Skip to content

Commit

Permalink
add test for existing internal IP on node
Browse files Browse the repository at this point in the history
  • Loading branch information
AshleyDumaine committed Oct 2, 2024
1 parent a777899 commit 7a52a5a
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions cloud/linode/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,29 @@ func TestMetadataRetrieval(t *testing.T) {
})

ipTests := []struct {
name string
inputIPv4s []string
inputIPv6 string
externalNetwork string
outputAddresses []v1.NodeAddress
expectedErr error
name string
inputIPv4s []string
inputIPv6 string
externalNetwork string
existingAddresses []v1.NodeAddress
outputAddresses []v1.NodeAddress
expectedErr error
}{
{"no IPs", nil, "", "", nil, instanceNoIPAddressesError{192910}},
{
"no IPs",
nil,
"",
"",
nil,
nil,
instanceNoIPAddressesError{192910},
},
{
"one public, one private",
[]string{"32.74.121.25", "192.168.121.42"},
"",
"",
nil,
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}, {Type: v1.NodeInternalIP, Address: "192.168.121.42"}},
nil,
},
Expand All @@ -164,6 +174,7 @@ func TestMetadataRetrieval(t *testing.T) {
[]string{"32.74.121.25"},
"2600:3c06::f03c:94ff:fe1e:e072",
"",
nil,
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}, {Type: v1.NodeExternalIP, Address: "2600:3c06::f03c:94ff:fe1e:e072"}},
nil,
},
Expand All @@ -172,6 +183,7 @@ func TestMetadataRetrieval(t *testing.T) {
[]string{"32.74.121.25"},
"",
"",
nil,
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}},
nil,
},
Expand All @@ -180,6 +192,7 @@ func TestMetadataRetrieval(t *testing.T) {
[]string{"192.168.121.42"},
"",
"",
nil,
[]v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "192.168.121.42"}},
nil,
},
Expand All @@ -188,6 +201,7 @@ func TestMetadataRetrieval(t *testing.T) {
[]string{"32.74.121.25", "32.74.121.22"},
"",
"",
nil,
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}, {Type: v1.NodeExternalIP, Address: "32.74.121.22"}},
nil,
},
Expand All @@ -196,6 +210,7 @@ func TestMetadataRetrieval(t *testing.T) {
[]string{"192.168.121.42", "10.0.2.15"},
"",
"",
nil,
[]v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "192.168.121.42"}, {Type: v1.NodeInternalIP, Address: "10.0.2.15"}},
nil,
},
Expand All @@ -204,9 +219,19 @@ func TestMetadataRetrieval(t *testing.T) {
[]string{"192.168.121.42", "10.0.2.15"},
"",
"10.0.2.0/16",
nil,
[]v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "192.168.121.42"}, {Type: v1.NodeExternalIP, Address: "10.0.2.15"}},
nil,
},
{
"one private addresses, one existing internal IP set on the node",
[]string{"192.168.121.42"},
"",
"",
[]v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "10.0.0.1"}},
[]v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "192.168.121.42"}, {Type: v1.NodeInternalIP, Address: "10.0.0.1"}},
nil,
},
}

for _, test := range ipTests {
Expand All @@ -221,6 +246,9 @@ func TestMetadataRetrieval(t *testing.T) {
} else {
_, Options.LinodeExternalNetwork, _ = net.ParseCIDR(test.externalNetwork)
}
if test.existingAddresses != nil {
node.Status.Addresses = append(node.Status.Addresses, test.existingAddresses...)
}
ips := make([]*net.IP, 0, len(test.inputIPv4s))
for _, ip := range test.inputIPv4s {
parsed := net.ParseIP(ip)
Expand Down

0 comments on commit 7a52a5a

Please sign in to comment.