26 lines
546 B
Go
26 lines
546 B
Go
|
|
package agent
|
||
|
|
|
||
|
|
import "testing"
|
||
|
|
|
||
|
|
func TestPeerSubnet(t *testing.T) {
|
||
|
|
cases := []struct {
|
||
|
|
peer string
|
||
|
|
want string
|
||
|
|
}{
|
||
|
|
{"2602:817:3000:a25::1", "2602:817:3000:a25::/64"},
|
||
|
|
{"2602:817:3000:a25::104", "2602:817:3000:a25::/64"},
|
||
|
|
{"172.25.25.1", "172.25.25.0/24"},
|
||
|
|
{"172.25.25.104", "172.25.25.0/24"},
|
||
|
|
{"", ""},
|
||
|
|
{"not-an-ip", ""},
|
||
|
|
}
|
||
|
|
for _, tc := range cases {
|
||
|
|
t.Run(tc.peer, func(t *testing.T) {
|
||
|
|
got := peerSubnet(tc.peer)
|
||
|
|
if got != tc.want {
|
||
|
|
t.Fatalf("peerSubnet(%q) = %q, want %q", tc.peer, got, tc.want)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|