Skip to content

Commit cb92b2c

Browse files
authored
Merge pull request kubernetes#110203 from wppzxc/add-testcases
Fix: Add test cases for method IsZeroCIDR() in pkg/proxy/util/utils_test.go
2 parents 32c3fb3 + 872be44 commit cb92b2c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

pkg/proxy/util/utils_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,3 +1469,44 @@ func TestContainsIPv4Loopback(t *testing.T) {
14691469
})
14701470
}
14711471
}
1472+
1473+
func TestIsZeroCIDR(t *testing.T) {
1474+
testCases := []struct {
1475+
name string
1476+
input string
1477+
expected bool
1478+
}{
1479+
{
1480+
name: "invalide cidr",
1481+
input: "",
1482+
expected: false,
1483+
},
1484+
{
1485+
name: "ipv4 cidr",
1486+
input: "172.10.0.0/16",
1487+
expected: false,
1488+
},
1489+
{
1490+
name: "ipv4 zero cidr",
1491+
input: IPv4ZeroCIDR,
1492+
expected: true,
1493+
},
1494+
{
1495+
name: "ipv6 cidr",
1496+
input: "::/128",
1497+
expected: false,
1498+
},
1499+
{
1500+
name: "ipv6 zero cidr",
1501+
input: IPv6ZeroCIDR,
1502+
expected: true,
1503+
},
1504+
}
1505+
for _, tc := range testCases {
1506+
t.Run(tc.name, func(t *testing.T) {
1507+
if got := IsZeroCIDR(tc.input); tc.expected != got {
1508+
t.Errorf("IsZeroCIDR() = %t, want %t", got, tc.expected)
1509+
}
1510+
})
1511+
}
1512+
}

0 commit comments

Comments
 (0)