@@ -156,52 +156,74 @@ var nc6 = &naclConfig{
156
156
157
157
// tests below
158
158
159
- var expectedConnStrTest1 = `vsi-0-subnet-1[10.240.10.4] => vsi-0-subnet-2[10.240.20.4] : All Connections
160
- vsi-0-subnet-2[10.240.20.4] => vsi-0-subnet-1[10.240.10.4] : All Connections
161
- `
162
-
163
- func TestAnalyzeConnectivity1 (t * testing.T ) {
164
- runConnectivityTest (t , tc1 , []* naclConfig {nc1 }, expectedConnStrTest1 )
165
- }
166
-
167
- var expectedConnStrTest2 = `vsi-0-subnet-1[10.240.10.4] => vsi-0-subnet-2[10.240.20.4] : TCP * ; ICMP,UDP
168
- `
169
-
170
- func TestAnalyzeConnectivity2 (t * testing.T ) {
171
- runConnectivityTest (t , tc1 , []* naclConfig {nc2 , nc3 }, expectedConnStrTest2 )
159
+ type ConnectivityAnalysisTest struct {
160
+ name string
161
+ tc * testNodesConfig
162
+ ncList []* naclConfig
163
+ expectedStrResult string
172
164
}
173
165
174
- var expectedConnStrTest2a = `vsi-0-subnet-1[10.240.10.4] => vsi-0-subnet-2[10.240.20.4] : ICMP
175
- ` // ICMP is actually enabled only unidirectional in this case, but responsive analysis does not apply to ICMP
176
-
177
- func TestAnalyzeConnectivity2a (t * testing.T ) {
178
- runConnectivityTest (t , tc1 , []* naclConfig {nc2a , nc3a }, expectedConnStrTest2a )
179
- }
180
-
181
- var expectedConnStrTest3 = `vsi-0-subnet-1[10.240.10.4] => vsi-0-subnet-2[10.240.20.4] : All Connections
166
+ var connectivityAnalysisTests = []* ConnectivityAnalysisTest {
167
+ {
168
+ name : "testAnalyzeConnectivity1" ,
169
+ tc : tc1 ,
170
+ ncList : []* naclConfig {nc1 },
171
+ expectedStrResult : `vsi-0-subnet-1[10.240.10.4] => vsi-0-subnet-2[10.240.20.4] : All Connections
172
+ vsi-0-subnet-2[10.240.20.4] => vsi-0-subnet-1[10.240.10.4] : All Connections
173
+ ` ,
174
+ },
175
+ {
176
+ name : "testAnalyzeConnectivity2" ,
177
+ tc : tc1 ,
178
+ ncList : []* naclConfig {nc2 , nc3 },
179
+ expectedStrResult : `vsi-0-subnet-1[10.240.10.4] => vsi-0-subnet-2[10.240.20.4] : TCP * ; ICMP,UDP
180
+ ` ,
181
+ },
182
+ {
183
+ name : "testAnalyzeConnectivity2a" ,
184
+ tc : tc1 ,
185
+ ncList : []* naclConfig {nc2a , nc3a },
186
+ expectedStrResult : `vsi-0-subnet-1[10.240.10.4] => vsi-0-subnet-2[10.240.20.4] : ICMP
187
+ ` , // ICMP is actually enabled only unidirectional in this case, but responsive analysis does not apply to ICMP
188
+ },
189
+ {
190
+ name : "testAnalyzeConnectivity3" ,
191
+ tc : tc1 ,
192
+ ncList : []* naclConfig {nc2 , nc4 },
193
+ expectedStrResult : `vsi-0-subnet-1[10.240.10.4] => vsi-0-subnet-2[10.240.20.4] : All Connections
182
194
vsi-0-subnet-2[10.240.20.4] => vsi-0-subnet-1[10.240.10.4] : TCP
183
- `
184
-
185
- func TestAnalyzeConnectivity3 ( t * testing. T ) {
186
- runConnectivityTest ( t , tc1 , [] * naclConfig { nc2 , nc4 }, expectedConnStrTest3 )
187
- }
188
-
189
- var expectedConnStrTest4 = `vsi-0-subnet-1[10.240.10.4] => vsi-0-subnet-2[10.240.20.4] : TCP src-ports: 10-100 dst-ports: 443
195
+ ` ,
196
+ },
197
+ {
198
+ name : "testAnalyzeConnectivity4" ,
199
+ tc : tc1 ,
200
+ ncList : [] * naclConfig { nc5 , nc6 },
201
+ expectedStrResult : `vsi-0-subnet-1[10.240.10.4] => vsi-0-subnet-2[10.240.20.4] : TCP src-ports: 10-100 dst-ports: 443
190
202
vsi-0-subnet-2[10.240.20.4] => vsi-0-subnet-1[10.240.10.4] : TCP src-ports: 443 dst-ports: 10-100
191
- `
203
+ ` ,
204
+ },
205
+ }
192
206
193
- func TestAnalyzeConnectivity4 (t * testing.T ) {
194
- runConnectivityTest (t , tc1 , []* naclConfig {nc5 , nc6 }, expectedConnStrTest4 )
207
+ func TestConnectivityAnalysis (t * testing.T ) {
208
+ // connectivityAnalysisTests is the list of tests to run
209
+ for testIdx := range connectivityAnalysisTests {
210
+ tt := connectivityAnalysisTests [testIdx ]
211
+ t .Run (tt .name , func (t * testing.T ) {
212
+ t .Parallel ()
213
+ tt .runConnectivityTest (t )
214
+ })
215
+ }
216
+ fmt .Println ("done" )
195
217
}
196
218
197
- func runConnectivityTest (t * testing.T , tc * testNodesConfig , ncList [] * naclConfig , expectedStrResult string ) {
198
- c := createConfigFromTestConfig (tc , ncList )
219
+ func ( tt * ConnectivityAnalysisTest ) runConnectivityTest (t * testing.T ) {
220
+ c := createConfigFromTestConfig (tt . tc , tt . ncList )
199
221
connectivity , err := c .GetVPCNetworkConnectivity (false , vpcmodel .NoGroupingNoConsistencyEdges )
200
222
require .Nil (t , err )
201
223
connectivityStr := connectivity .String ()
202
224
fmt .Println (connectivityStr )
203
225
fmt .Println ("done" )
204
- require .Equal (t , expectedStrResult , connectivityStr )
226
+ require .Equal (t , tt . expectedStrResult , connectivityStr )
205
227
}
206
228
207
229
////////////////////////////////////////////////////////////////////////////////////////////////
0 commit comments