mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
add ut for PortPart()
This commit is contained in:
parent
76e9fdaa72
commit
2f30751db3
@ -50,6 +50,58 @@ func TestIPPart(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPortPart(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
endpoint string
|
||||
want int
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
"no error parsing from ipv4-ip:port",
|
||||
"1.2.3.4:1024",
|
||||
1024,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"no error parsing from ipv6-ip:port",
|
||||
"[2001:db8::2:2]:9999",
|
||||
9999,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"error: missing port",
|
||||
"1.2.3.4",
|
||||
-1,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"error: invalid port '1-2'",
|
||||
"1.2.3.4:1-2",
|
||||
-1,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"error: invalid port 'port'",
|
||||
"100.200.3.4:port",
|
||||
-1,
|
||||
true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := PortPart(tt.endpoint)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("PortPart() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Errorf("PortPart() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestToCIDR(t *testing.T) {
|
||||
testCases := []struct {
|
||||
ip string
|
||||
|
Loading…
Reference in New Issue
Block a user