Skip to content

Commit

Permalink
[management] Add tests for parsing port of a management message
Browse files Browse the repository at this point in the history
  • Loading branch information
leap-pea authored and jkito committed Dec 4, 2024
1 parent 2f95230 commit 8e9a765
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion pkg/vpn/management/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func TestStateEvent(t *testing.T) {
WantDesc string
WantLocalAddr string
WantRemoteAddr string
WantRemotePort string
}
testCases := []TestCase{
{
Expand All @@ -190,6 +191,7 @@ func TestStateEvent(t *testing.T) {
WantDesc: "",
WantLocalAddr: "",
WantRemoteAddr: "",
WantRemotePort: "",
},
{
Input: []byte("STATE:,"),
Expand All @@ -198,6 +200,7 @@ func TestStateEvent(t *testing.T) {
WantDesc: "",
WantLocalAddr: "",
WantRemoteAddr: "",
WantRemotePort: "",
},
{
Input: []byte("STATE:,,,,"),
Expand All @@ -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"),
Expand All @@ -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,,"),
Expand All @@ -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: "",
},
}

Expand Down Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit 8e9a765

Please sign in to comment.