@@ -18,6 +18,7 @@ package securitygroup
1818
1919import (
2020 "context"
21+ "reflect"
2122 "strings"
2223 "testing"
2324
@@ -904,9 +905,9 @@ func TestAdditionalControlPlaneSecurityGroup(t *testing.T) {
904905 _ = infrav1 .AddToScheme (scheme )
905906
906907 testCases := []struct {
907- name string
908- networkSpec infrav1.NetworkSpec
909- expectedAdditionalIngresRule infrav1.IngressRule
908+ name string
909+ networkSpec infrav1.NetworkSpec
910+ expectedAdditionalIngressRule infrav1.IngressRule
910911 }{
911912 {
912913 name : "default control plane security group is used" ,
@@ -920,7 +921,7 @@ func TestAdditionalControlPlaneSecurityGroup(t *testing.T) {
920921 },
921922 },
922923 },
923- expectedAdditionalIngresRule : infrav1.IngressRule {
924+ expectedAdditionalIngressRule : infrav1.IngressRule {
924925 Description : "test" ,
925926 Protocol : infrav1 .SecurityGroupProtocolTCP ,
926927 FromPort : 9345 ,
@@ -941,7 +942,7 @@ func TestAdditionalControlPlaneSecurityGroup(t *testing.T) {
941942 },
942943 },
943944 },
944- expectedAdditionalIngresRule : infrav1.IngressRule {
945+ expectedAdditionalIngressRule : infrav1.IngressRule {
945946 Description : "test" ,
946947 Protocol : infrav1 .SecurityGroupProtocolTCP ,
947948 FromPort : 9345 ,
@@ -962,7 +963,7 @@ func TestAdditionalControlPlaneSecurityGroup(t *testing.T) {
962963 },
963964 },
964965 },
965- expectedAdditionalIngresRule : infrav1.IngressRule {
966+ expectedAdditionalIngressRule : infrav1.IngressRule {
966967 Description : "test" ,
967968 Protocol : infrav1 .SecurityGroupProtocolTCP ,
968969 FromPort : 9345 ,
@@ -984,7 +985,7 @@ func TestAdditionalControlPlaneSecurityGroup(t *testing.T) {
984985 },
985986 },
986987 },
987- expectedAdditionalIngresRule : infrav1.IngressRule {
988+ expectedAdditionalIngressRule : infrav1.IngressRule {
988989 Description : "test" ,
989990 Protocol : infrav1 .SecurityGroupProtocolTCP ,
990991 FromPort : 9345 ,
@@ -1005,7 +1006,7 @@ func TestAdditionalControlPlaneSecurityGroup(t *testing.T) {
10051006 },
10061007 },
10071008 },
1008- expectedAdditionalIngresRule : infrav1.IngressRule {
1009+ expectedAdditionalIngressRule : infrav1.IngressRule {
10091010 Description : "test" ,
10101011 Protocol : infrav1 .SecurityGroupProtocolTCP ,
10111012 FromPort : 9345 ,
@@ -1056,20 +1057,20 @@ func TestAdditionalControlPlaneSecurityGroup(t *testing.T) {
10561057 }
10571058 found = true
10581059
1059- if r .Protocol != tc .expectedAdditionalIngresRule .Protocol {
1060- t .Fatalf ("Expected protocol %s, got %s" , tc .expectedAdditionalIngresRule .Protocol , r .Protocol )
1060+ if r .Protocol != tc .expectedAdditionalIngressRule .Protocol {
1061+ t .Fatalf ("Expected protocol %s, got %s" , tc .expectedAdditionalIngressRule .Protocol , r .Protocol )
10611062 }
10621063
1063- if r .FromPort != tc .expectedAdditionalIngresRule .FromPort {
1064- t .Fatalf ("Expected from port %d, got %d" , tc .expectedAdditionalIngresRule .FromPort , r .FromPort )
1064+ if r .FromPort != tc .expectedAdditionalIngressRule .FromPort {
1065+ t .Fatalf ("Expected from port %d, got %d" , tc .expectedAdditionalIngressRule .FromPort , r .FromPort )
10651066 }
10661067
1067- if r .ToPort != tc .expectedAdditionalIngresRule .ToPort {
1068- t .Fatalf ("Expected to port %d, got %d" , tc .expectedAdditionalIngresRule .ToPort , r .ToPort )
1068+ if r .ToPort != tc .expectedAdditionalIngressRule .ToPort {
1069+ t .Fatalf ("Expected to port %d, got %d" , tc .expectedAdditionalIngressRule .ToPort , r .ToPort )
10691070 }
10701071
1071- if ! sets .New [string ](tc .expectedAdditionalIngresRule .SourceSecurityGroupIDs ... ).Equal (sets .New [string ](tc .expectedAdditionalIngresRule .SourceSecurityGroupIDs ... )) {
1072- t .Fatalf ("Expected source security group IDs %v, got %v" , tc .expectedAdditionalIngresRule .SourceSecurityGroupIDs , r .SourceSecurityGroupIDs )
1072+ if ! sets .New [string ](tc .expectedAdditionalIngressRule .SourceSecurityGroupIDs ... ).Equal (sets .New [string ](tc .expectedAdditionalIngressRule .SourceSecurityGroupIDs ... )) {
1073+ t .Fatalf ("Expected source security group IDs %v, got %v" , tc .expectedAdditionalIngressRule .SourceSecurityGroupIDs , r .SourceSecurityGroupIDs )
10731074 }
10741075 }
10751076
@@ -1085,9 +1086,9 @@ func TestAdditionalManagedControlPlaneSecurityGroup(t *testing.T) {
10851086 _ = ekscontrolplanev1 .AddToScheme (scheme )
10861087
10871088 testCases := []struct {
1088- name string
1089- networkSpec infrav1.NetworkSpec
1090- expectedAdditionalIngresRule infrav1.IngressRule
1089+ name string
1090+ networkSpec infrav1.NetworkSpec
1091+ expectedAdditionalIngressRule infrav1.IngressRule
10911092 }{
10921093 {
10931094 name : "default control plane security group is used" ,
@@ -1101,7 +1102,7 @@ func TestAdditionalManagedControlPlaneSecurityGroup(t *testing.T) {
11011102 },
11021103 },
11031104 },
1104- expectedAdditionalIngresRule : infrav1.IngressRule {
1105+ expectedAdditionalIngressRule : infrav1.IngressRule {
11051106 Description : "test" ,
11061107 Protocol : infrav1 .SecurityGroupProtocolTCP ,
11071108 FromPort : 9345 ,
@@ -1122,11 +1123,12 @@ func TestAdditionalManagedControlPlaneSecurityGroup(t *testing.T) {
11221123 },
11231124 },
11241125 },
1125- expectedAdditionalIngresRule : infrav1.IngressRule {
1126+ expectedAdditionalIngressRule : infrav1.IngressRule {
11261127 Description : "test" ,
11271128 Protocol : infrav1 .SecurityGroupProtocolTCP ,
11281129 FromPort : 9345 ,
11291130 ToPort : 9345 ,
1131+ CidrBlocks : []string {"test-cidr-block" },
11301132 },
11311133 },
11321134 }
@@ -1171,20 +1173,8 @@ func TestAdditionalManagedControlPlaneSecurityGroup(t *testing.T) {
11711173 if r .Description == "test" {
11721174 found = true
11731175
1174- if r .Protocol != tc .expectedAdditionalIngresRule .Protocol {
1175- t .Fatalf ("Expected protocol %s, got %s" , tc .expectedAdditionalIngresRule .Protocol , r .Protocol )
1176- }
1177-
1178- if r .FromPort != tc .expectedAdditionalIngresRule .FromPort {
1179- t .Fatalf ("Expected from port %d, got %d" , tc .expectedAdditionalIngresRule .FromPort , r .FromPort )
1180- }
1181-
1182- if r .ToPort != tc .expectedAdditionalIngresRule .ToPort {
1183- t .Fatalf ("Expected to port %d, got %d" , tc .expectedAdditionalIngresRule .ToPort , r .ToPort )
1184- }
1185-
1186- if ! sets .New [string ](tc .expectedAdditionalIngresRule .SourceSecurityGroupIDs ... ).Equal (sets .New [string ](tc .expectedAdditionalIngresRule .SourceSecurityGroupIDs ... )) {
1187- t .Fatalf ("Expected source security group IDs %v, got %v" , tc .expectedAdditionalIngresRule .SourceSecurityGroupIDs , r .SourceSecurityGroupIDs )
1176+ if ! reflect .DeepEqual (r , tc .expectedAdditionalIngressRule ) {
1177+ t .Fatalf ("Expected ingress rule %#v, got %#v" , tc .expectedAdditionalIngressRule , r )
11881178 }
11891179 }
11901180 }
0 commit comments