Skip to content

Commit

Permalink
wip: move test to cluster_config_validate
Browse files Browse the repository at this point in the history
  • Loading branch information
eaudetcobello committed Sep 27, 2024
1 parent 147a3a4 commit 6e0899d
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/k8s/pkg/k8sd/types/cluster_config_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ func TestValidateCIDR(t *testing.T) {
cidr string
expectErr bool
}{
{cidr: "10.1.0.0/16"},
{cidr: "192.168.0.0/16"},
{cidr: "2001:0db8::/32"},
{cidr: "10.1.0.0/16,2001:0db8::/32"},
{cidr: "", expectErr: true},
{cidr: "bananas", expectErr: true},
{cidr: "fd01::/64,fd02::/64,fd03::/64", expectErr: true},
{cidr: "10.1.0.0/32", expectErr: true},
} {
t.Run(tc.cidr, func(t *testing.T) {
t.Run("Pod", func(t *testing.T) {
Expand Down Expand Up @@ -128,3 +129,46 @@ func TestValidateExternalServers(t *testing.T) {
})
}
}

func TestValidateCIDROverlap(t *testing.T) {
for _, tc := range []struct {
name string
podCIDR string
serviceCIDR string
expectErr bool
}{
{"RandomName", "nogood", "nogood", true},
{"BothValid", "10.1.0.0/16", "2001:0db8::/108", false},
//IPv4
{"SameIPv4CIDRs", "192.168.100.0/24", "192.168.100.0/24", true},
{"OverlappingIPv4CIDRs", "10.2.0.13/24", "10.2.0.0/24", true},
{"IPv4CIDRMinimumSize", "192.168.0.0/32", "10.0.0.0/24", true},
{"InvalidIPv4CIDRFormat", "192.168.1.1/33", "10.0.0.0/24", true},
{"MaxSizeIPv4CIDRs", "0.0.0.0/0", "0.0.0.0/0", true},
//IPv6
{"SameIPv6CIDRs", "fe80::1/32", "fe80::1/32", true},
{"OverlappingIPv6CIDRs", "fe80::/48", "fe80::dead/48", true},
{"IPv6CIDRMinimumSize", "2001:db8::1/128", "fc00::/32", true},
{"InvalidIPv6CIDRFormat", "2001:db8::1/129", "fc00::/64", true},
{"MaxSizeIPv6CIDRs", "::/0", "::/0", true},
//Mixed
{"IPv4AndIPv6MixedCIDRs", "192.168.0.0/16", "2001:db8::/32", true},
{"OnlyInvalidIPv6CIDR", "", "2001:db8::/65", true},
} {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
config := types.ClusterConfig{
Network: types.Network{
PodCIDR: utils.Pointer(tc.podCIDR),
ServiceCIDR: utils.Pointer(tc.serviceCIDR),
},
}
err := config.Validate()
if tc.expectErr {
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(err).To(BeNil())
}
})
}
}

0 comments on commit 6e0899d

Please sign in to comment.