@@ -18,9 +18,9 @@ package network
1818
1919import (
2020 "context"
21- "encoding/json"
2221 "fmt"
2322 "reflect"
23+ "slices"
2424 "testing"
2525
2626 "github.com/aws/aws-sdk-go/aws"
@@ -63,10 +63,7 @@ func TestReconcileSubnets(t *testing.T) {
6363 {ID : "subnet-private-us-east-1-wl1-nyc-wlz-1" , AvailabilityZone : "us-east-1-wl1-nyc-wlz-1" , CidrBlock : "10.0.7.0/24" , IsPublic : false },
6464 {ID : "subnet-public-us-east-1-wl1-nyc-wlz-1" , AvailabilityZone : "us-east-1-wl1-nyc-wlz-1" , CidrBlock : "10.0.8.0/24" , IsPublic : true },
6565 }
66- // TODO(mtulio): replace by slices.Concat(...) on go 1.22+
67- stubSubnetsAllZones := stubSubnetsAvailabilityZone
68- stubSubnetsAllZones = append (stubSubnetsAllZones , stubSubnetsLocalZone ... )
69- stubSubnetsAllZones = append (stubSubnetsAllZones , stubSubnetsWavelengthZone ... )
66+ stubSubnetsAllZones := slices .Concat (stubSubnetsAvailabilityZone , stubSubnetsLocalZone , stubSubnetsWavelengthZone )
7067
7168 // NetworkSpec with subnets in zone type availability-zone
7269 stubNetworkSpecWithSubnets := & infrav1.NetworkSpec {
@@ -678,7 +675,6 @@ func TestReconcileSubnets(t *testing.T) {
678675 AvailabilityZone : "us-east-1a" ,
679676 CidrBlock : "10.0.10.0/24" ,
680677 IsPublic : true ,
681- Tags : infrav1.Tags {},
682678 },
683679 },
684680 expect : func (m * mocks.MockEC2APIMockRecorder ) {
@@ -702,6 +698,12 @@ func TestReconcileSubnets(t *testing.T) {
702698 AvailabilityZone : aws .String ("us-east-1a" ),
703699 CidrBlock : aws .String ("10.0.10.0/24" ),
704700 MapPublicIpOnLaunch : aws .Bool (false ),
701+ Tags : []* ec2.Tag {
702+ {
703+ Key : aws .String ("company-policy" ),
704+ Value : aws .String ("enabled" ),
705+ },
706+ },
705707 },
706708 },
707709 }, nil )
@@ -784,15 +786,13 @@ func TestReconcileSubnets(t *testing.T) {
784786 AvailabilityZone : "us-east-1a" ,
785787 CidrBlock : "10.0.10.0/24" ,
786788 IsPublic : true ,
787- Tags : infrav1.Tags {},
788789 },
789790 {
790791 ID : "subnet-2" ,
791792 ResourceID : "subnet-2" ,
792793 AvailabilityZone : "us-east-1b" ,
793794 CidrBlock : "10.0.11.0/24" ,
794795 IsPublic : true ,
795- Tags : infrav1.Tags {},
796796 },
797797 },
798798 expect : func (m * mocks.MockEC2APIMockRecorder ) {
@@ -1057,55 +1057,7 @@ func TestReconcileSubnets(t *testing.T) {
10571057 },
10581058 Subnets : []infrav1.SubnetSpec {},
10591059 }).WithTagUnmanagedNetworkResources (true ),
1060- expect : func (m * mocks.MockEC2APIMockRecorder ) {
1061- m .DescribeSubnetsWithContext (context .TODO (), gomock .Eq (& ec2.DescribeSubnetsInput {
1062- Filters : []* ec2.Filter {
1063- {
1064- Name : aws .String ("state" ),
1065- Values : []* string {aws .String ("pending" ), aws .String ("available" )},
1066- },
1067- {
1068- Name : aws .String ("vpc-id" ),
1069- Values : []* string {aws .String (subnetsVPCID )},
1070- },
1071- },
1072- })).
1073- Return (& ec2.DescribeSubnetsOutput {
1074- Subnets : []* ec2.Subnet {
1075- {
1076- VpcId : aws .String (subnetsVPCID ),
1077- SubnetId : aws .String ("subnet-1" ),
1078- AvailabilityZone : aws .String ("us-east-1a" ),
1079- CidrBlock : aws .String ("10.0.10.0/24" ),
1080- MapPublicIpOnLaunch : aws .Bool (false ),
1081- },
1082- {
1083- VpcId : aws .String (subnetsVPCID ),
1084- SubnetId : aws .String ("subnet-2" ),
1085- AvailabilityZone : aws .String ("us-east-1a" ),
1086- CidrBlock : aws .String ("10.0.20.0/24" ),
1087- MapPublicIpOnLaunch : aws .Bool (false ),
1088- },
1089- },
1090- }, nil )
1091- m .DescribeRouteTablesWithContext (context .TODO (), gomock .AssignableToTypeOf (& ec2.DescribeRouteTablesInput {})).
1092- Return (& ec2.DescribeRouteTablesOutput {}, nil )
1093-
1094- m .DescribeNatGatewaysPagesWithContext (context .TODO (),
1095- gomock .Eq (& ec2.DescribeNatGatewaysInput {
1096- Filter : []* ec2.Filter {
1097- {
1098- Name : aws .String ("vpc-id" ),
1099- Values : []* string {aws .String (subnetsVPCID )},
1100- },
1101- {
1102- Name : aws .String ("state" ),
1103- Values : []* string {aws .String ("pending" ), aws .String ("available" )},
1104- },
1105- },
1106- }),
1107- gomock .Any ()).Return (nil )
1108- },
1060+ expect : func (m * mocks.MockEC2APIMockRecorder ) {},
11091061 errorExpected : true ,
11101062 tagUnmanagedNetworkResources : true ,
11111063 },
@@ -4017,10 +3969,7 @@ func TestDiscoverSubnets(t *testing.T) {
40173969 CidrBlock : "10.0.10.0/24" ,
40183970 IsPublic : true ,
40193971 RouteTableID : aws .String ("rtb-1" ),
4020- Tags : infrav1.Tags {
4021- "Name" : "provided-subnet-public" ,
4022- },
4023- ZoneType : ptr.To [infrav1.ZoneType ]("availability-zone" ),
3972+ ZoneType : ptr.To [infrav1.ZoneType ]("availability-zone" ),
40243973 },
40253974 {
40263975 ID : "subnet-2" ,
@@ -4029,10 +3978,7 @@ func TestDiscoverSubnets(t *testing.T) {
40293978 CidrBlock : "10.0.11.0/24" ,
40303979 IsPublic : false ,
40313980 RouteTableID : aws .String ("rtb-2" ),
4032- Tags : infrav1.Tags {
4033- "Name" : "provided-subnet-private" ,
4034- },
4035- ZoneType : ptr.To [infrav1.ZoneType ]("availability-zone" ),
3981+ ZoneType : ptr.To [infrav1.ZoneType ]("availability-zone" ),
40363982 },
40373983 },
40383984 },
@@ -4084,15 +4030,7 @@ func TestDiscoverSubnets(t *testing.T) {
40844030 }
40854031
40864032 if ! cmp .Equal (sn , exp ) {
4087- expected , err := json .MarshalIndent (exp , "" , "\t " )
4088- if err != nil {
4089- t .Fatalf ("got an unexpected error: %v" , err )
4090- }
4091- actual , err := json .MarshalIndent (sn , "" , "\t " )
4092- if err != nil {
4093- t .Fatalf ("got an unexpected error: %v" , err )
4094- }
4095- t .Errorf ("Expected %s, got %s" , string (expected ), string (actual ))
4033+ t .Errorf ("Expected subnets to be equal. Diff %s" , cmp .Diff (sn , exp ))
40964034 }
40974035 delete (out , exp .ID )
40984036 }
0 commit comments