@@ -27,85 +27,67 @@ func TestDualStackIPs(t *testing.T) {
2727 desc string
2828 ips []string
2929 expectedResult bool
30- expectError bool
3130 }{
3231 {
3332 desc : "should fail because length is not at least 2" ,
3433 ips : []string {"1.1.1.1" },
3534 expectedResult : false ,
36- expectError : false ,
3735 },
3836 {
3937 desc : "should fail because length is not at least 2" ,
4038 ips : []string {},
4139 expectedResult : false ,
42- expectError : false ,
4340 },
4441 {
4542 desc : "should fail because all are v4" ,
4643 ips : []string {"1.1.1.1" , "2.2.2.2" , "3.3.3.3" },
4744 expectedResult : false ,
48- expectError : false ,
4945 },
5046 {
5147 desc : "should fail because all are v6" ,
5248 ips : []string {"fd92:20ba:ca:34f7:ffff:ffff:ffff:ffff" , "fd92:20ba:ca:34f7:ffff:ffff:ffff:fff0" , "fd92:20ba:ca:34f7:ffff:ffff:ffff:fff1" },
5349 expectedResult : false ,
54- expectError : false ,
5550 },
5651 {
5752 desc : "should fail because 2nd ip is invalid" ,
5853 ips : []string {"1.1.1.1" , "not-a-valid-ip" },
5954 expectedResult : false ,
60- expectError : true ,
6155 },
6256 {
6357 desc : "should fail because 1st ip is invalid" ,
6458 ips : []string {"not-a-valid-ip" , "fd92:20ba:ca:34f7:ffff:ffff:ffff:ffff" },
6559 expectedResult : false ,
66- expectError : true ,
6760 },
6861 {
6962 desc : "should fail despite dual-stack because 3rd ip is invalid" ,
7063 ips : []string {"1.1.1.1" , "fd92:20ba:ca:34f7:ffff:ffff:ffff:ffff" , "not-a-valid-ip" },
7164 expectedResult : false ,
72- expectError : true ,
7365 },
7466 {
7567 desc : "dual-stack ipv4-primary" ,
7668 ips : []string {"1.1.1.1" , "fd92:20ba:ca:34f7:ffff:ffff:ffff:ffff" },
7769 expectedResult : true ,
78- expectError : false ,
7970 },
8071 {
8172 desc : "dual-stack, multiple ipv6" ,
8273 ips : []string {"fd92:20ba:ca:34f7:ffff:ffff:ffff:ffff" , "1.1.1.1" , "fd92:20ba:ca:34f7:ffff:ffff:ffff:fff0" },
8374 expectedResult : true ,
84- expectError : false ,
8575 },
8676 {
8777 desc : "dual-stack, multiple ipv4" ,
8878 ips : []string {"1.1.1.1" , "fd92:20ba:ca:34f7:ffff:ffff:ffff:ffff" , "10.0.0.0" },
8979 expectedResult : true ,
90- expectError : false ,
9180 },
9281 {
9382 desc : "dual-stack, ipv6-primary" ,
9483 ips : []string {"fd92:20ba:ca:34f7:ffff:ffff:ffff:ffff" , "1.1.1.1" },
9584 expectedResult : true ,
96- expectError : false ,
9785 },
9886 }
9987 // for each test case, test the regular func and the string func
10088 for _ , tc := range testCases {
10189 t .Run (tc .desc , func (t * testing.T ) {
102- dualStack , err := IsDualStackIPStrings (tc .ips )
103- if err == nil && tc .expectError {
104- t .Fatalf ("expected an error from IsDualStackIPStrings" )
105- }
106- if err != nil && ! tc .expectError {
107- t .Fatalf ("unexpected error from IsDualStackIPStrings: %v" , err )
108- }
90+ dualStack := IsDualStackIPStrings (tc .ips )
10991 if dualStack != tc .expectedResult {
11092 t .Errorf ("expected IsDualStackIPStrings=%v, got %v" , tc .expectedResult , dualStack )
11193 }
@@ -115,13 +97,7 @@ func TestDualStackIPs(t *testing.T) {
11597 parsedIP := ParseIPSloppy (ip )
11698 ips = append (ips , parsedIP )
11799 }
118- dualStack , err = IsDualStackIPs (ips )
119- if err == nil && tc .expectError {
120- t .Fatalf ("expected an error from IsDualStackIPs" )
121- }
122- if err != nil && ! tc .expectError {
123- t .Fatalf ("unexpected error from IsDualStackIPs: %v" , err )
124- }
100+ dualStack = IsDualStackIPs (ips )
125101 if dualStack != tc .expectedResult {
126102 t .Errorf ("expected IsDualStackIPs=%v, got %v" , tc .expectedResult , dualStack )
127103 }
@@ -134,74 +110,58 @@ func TestDualStackCIDRs(t *testing.T) {
134110 desc string
135111 cidrs []string
136112 expectedResult bool
137- expectError bool
138113 }{
139114 {
140115 desc : "should fail because length is not at least 2" ,
141116 cidrs : []string {"10.10.10.10/8" },
142117 expectedResult : false ,
143- expectError : false ,
144118 },
145119 {
146120 desc : "should fail because length is not at least 2" ,
147121 cidrs : []string {},
148122 expectedResult : false ,
149- expectError : false ,
150123 },
151124 {
152125 desc : "should fail because all cidrs are v4" ,
153126 cidrs : []string {"10.10.10.10/8" , "20.20.20.20/8" , "30.30.30.30/8" },
154127 expectedResult : false ,
155- expectError : false ,
156128 },
157129 {
158130 desc : "should fail because all cidrs are v6" ,
159131 cidrs : []string {"2000::/10" , "3000::/10" },
160132 expectedResult : false ,
161- expectError : false ,
162133 },
163134 {
164135 desc : "should fail because 2nd cidr is invalid" ,
165136 cidrs : []string {"10.10.10.10/8" , "not-a-valid-cidr" },
166137 expectedResult : false ,
167- expectError : true ,
168138 },
169139 {
170140 desc : "should fail because 1st cidr is invalid" ,
171141 cidrs : []string {"not-a-valid-ip" , "2000::/10" },
172142 expectedResult : false ,
173- expectError : true ,
174143 },
175144 {
176145 desc : "dual-stack, ipv4-primary" ,
177146 cidrs : []string {"10.10.10.10/8" , "2000::/10" },
178147 expectedResult : true ,
179- expectError : false ,
180148 },
181149 {
182150 desc : "dual-stack, ipv6-primary" ,
183151 cidrs : []string {"2000::/10" , "10.10.10.10/8" },
184152 expectedResult : true ,
185- expectError : false ,
186153 },
187154 {
188155 desc : "dual-stack, multiple IPv6" ,
189156 cidrs : []string {"2000::/10" , "10.10.10.10/8" , "3000::/10" },
190157 expectedResult : true ,
191- expectError : false ,
192158 },
193159 }
194160
195161 // for each test case, test the regular func and the string func
196162 for _ , tc := range testCases {
197163 t .Run (tc .desc , func (t * testing.T ) {
198- dualStack , err := IsDualStackCIDRStrings (tc .cidrs )
199- if err == nil && tc .expectError {
200- t .Fatalf ("expected an error from IsDualStackCIDRStrings" )
201- }
202- if err != nil && ! tc .expectError {
203- t .Fatalf ("unexpected error from IsDualStackCIDRStrings: %v" , err )
204- }
164+ dualStack := IsDualStackCIDRStrings (tc .cidrs )
205165 if dualStack != tc .expectedResult {
206166 t .Errorf ("expected IsDualStackCIDRStrings=%v, got %v" , tc .expectedResult , dualStack )
207167 }
@@ -212,13 +172,7 @@ func TestDualStackCIDRs(t *testing.T) {
212172 cidrs = append (cidrs , parsedCIDR )
213173 }
214174
215- dualStack , err = IsDualStackCIDRs (cidrs )
216- if err == nil && tc .expectError {
217- t .Fatalf ("expected an error from IsDualStackCIDRs" )
218- }
219- if err != nil && ! tc .expectError {
220- t .Fatalf ("unexpected error from IsDualStackCIDRs: %v" , err )
221- }
175+ dualStack = IsDualStackCIDRs (cidrs )
222176 if dualStack != tc .expectedResult {
223177 t .Errorf ("expected IsDualStackCIDRs=%v, got %v" , tc .expectedResult , dualStack )
224178 }
0 commit comments