From 8e9a765dd865bea11d37308cf6f704a4a74b18b8 Mon Sep 17 00:00:00 2001 From: Pea Nut <peanut2@systemli.org> Date: Fri, 20 Sep 2024 11:52:39 +0200 Subject: [PATCH] [management] Add tests for parsing port of a management message --- pkg/vpn/management/event_test.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/pkg/vpn/management/event_test.go b/pkg/vpn/management/event_test.go index 5afc95f6..ec0d5544 100644 --- a/pkg/vpn/management/event_test.go +++ b/pkg/vpn/management/event_test.go @@ -181,6 +181,7 @@ func TestStateEvent(t *testing.T) { WantDesc string WantLocalAddr string WantRemoteAddr string + WantRemotePort string } testCases := []TestCase{ { @@ -190,6 +191,7 @@ func TestStateEvent(t *testing.T) { WantDesc: "", WantLocalAddr: "", WantRemoteAddr: "", + WantRemotePort: "", }, { Input: []byte("STATE:,"), @@ -198,6 +200,7 @@ func TestStateEvent(t *testing.T) { WantDesc: "", WantLocalAddr: "", WantRemoteAddr: "", + WantRemotePort: "", }, { Input: []byte("STATE:,,,,"), @@ -206,6 +209,7 @@ func TestStateEvent(t *testing.T) { WantDesc: "", WantLocalAddr: "", WantRemoteAddr: "", + WantRemotePort: "", }, { Input: []byte("STATE:123,CONNECTED,good,172.16.0.1,192.168.4.1"), @@ -214,6 +218,7 @@ func TestStateEvent(t *testing.T) { WantDesc: "good", WantLocalAddr: "172.16.0.1", WantRemoteAddr: "192.168.4.1", + WantRemotePort: "", }, { Input: []byte("STATE:123,RECONNECTING,SIGHUP,,"), @@ -222,14 +227,34 @@ func TestStateEvent(t *testing.T) { WantDesc: "SIGHUP", WantLocalAddr: "", WantRemoteAddr: "", + WantRemotePort: "", }, { - Input: []byte("STATE:123,RECONNECTING,SIGHUP,,,extra"), + Input: []byte("STATE:123,RECONNECTING,SIGHUP,,,"), WantTimestamp: "123", WantState: "RECONNECTING", WantDesc: "SIGHUP", WantLocalAddr: "", WantRemoteAddr: "", + WantRemotePort: "", + }, + { + Input: []byte("STATE:1726824244,CONNECTED,SUCCESS,10.42.0.62,204.13.164.252,80,,,fd15:53b6:dead::2"), + WantTimestamp: "1726824244", + WantState: "CONNECTED", + WantDesc: "SUCCESS", + WantLocalAddr: "10.42.0.62", + WantRemoteAddr: "204.13.164.252", + WantRemotePort: "80", + }, + { + Input: []byte("STATE:1726824244,CONNECTED,SUCCESS,10.42.0.62,204.13.164.252"), + WantTimestamp: "1726824244", + WantState: "CONNECTED", + WantDesc: "SUCCESS", + WantLocalAddr: "10.42.0.62", + WantRemoteAddr: "204.13.164.252", + WantRemotePort: "", }, } @@ -258,6 +283,9 @@ func TestStateEvent(t *testing.T) { if got, want := st.RemoteAddr(), testCase.WantRemoteAddr; got != want { t.Errorf("test %d RemoteAddr returned %q; want %q", i, got, want) } + if got, want := st.RemotePort(), testCase.WantRemotePort; got != want { + t.Errorf("test %d RemotePort returned %q; want %q", i, got, want) + } } } -- GitLab