Skip to content

Commit b35e083

Browse files
author
Rahul Sharma
committed
add unittests
1 parent 541d8b0 commit b35e083

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

internal/controller/linodemachine_controller_helpers_test.go

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,11 @@ func validateInterfaceExpectations(
410410
require.NotNil(t, iface)
411411
require.Equal(t, linodego.InterfacePurposeVPC, iface.Purpose)
412412
if iface.IPv6 != nil {
413-
require.Equal(t, defaultNodeIPv6CIDRRange, *iface.IPv6.Ranges[0].Range)
413+
if iface.IPv6.SLAAC != nil {
414+
require.Equal(t, defaultNodeIPv6CIDRRange, iface.IPv6.SLAAC[0].Range)
415+
} else {
416+
require.Equal(t, defaultNodeIPv6CIDRRange, *iface.IPv6.Ranges[0].Range)
417+
}
414418
}
415419
require.True(t, iface.Primary)
416420
require.NotNil(t, iface.SubnetID)
@@ -485,6 +489,35 @@ func TestGetVPCInterfaceConfigFromDirectID(t *testing.T) {
485489
expectInterface: true,
486490
expectSubnetID: 789, // Matching subnet ID
487491
},
492+
{
493+
name: "Success - Valid VPC with subnets and ipv6 ranges, specific subnet name",
494+
vpcID: 123,
495+
interfaces: []linodego.InstanceConfigInterfaceCreateOptions{},
496+
subnetName: "subnet-2",
497+
mockSetup: func(mockLinodeClient *mock.MockLinodeClient) {
498+
mockLinodeClient.EXPECT().GetVPC(gomock.Any(), 123).Return(&linodego.VPC{
499+
ID: 123,
500+
Subnets: []linodego.VPCSubnet{
501+
{
502+
ID: 456,
503+
Label: "subnet-1",
504+
},
505+
{
506+
ID: 789,
507+
Label: "subnet-2",
508+
IPv6: []linodego.VPCIPv6Range{
509+
{
510+
Range: "2001:0db8::/56",
511+
},
512+
},
513+
},
514+
},
515+
}, nil)
516+
},
517+
expectErr: false,
518+
expectInterface: true,
519+
expectSubnetID: 789, // Matching subnet ID
520+
},
488521
{
489522
name: "Success - VPC interface already exists",
490523
vpcID: 123,
@@ -1176,7 +1209,10 @@ func TestGetVPCInterfaceConfig(t *testing.T) {
11761209
ObjectMeta: metav1.ObjectMeta{
11771210
Namespace: "default",
11781211
},
1179-
Spec: infrav1alpha2.LinodeMachineSpec{},
1212+
Spec: infrav1alpha2.LinodeMachineSpec{
1213+
EnableSLAAC: ptr.To(true),
1214+
IsPublicIPv6: ptr.To(true),
1215+
},
11801216
},
11811217
LinodeCluster: &infrav1alpha2.LinodeCluster{
11821218
Spec: infrav1alpha2.LinodeClusterSpec{

0 commit comments

Comments
 (0)