@@ -57,25 +57,36 @@ func TestDirScan(t *testing.T) {
57
57
os .Remove (outFile )
58
58
}
59
59
60
+ type TestDetails struct {
61
+ dirPath string
62
+ outFile string
63
+ expectedOutput string
64
+ }
65
+
60
66
func TestNetpolsJsonOutput (t * testing.T ) {
61
67
currentDir , _ := os .Getwd ()
62
- dirPath := filepath .Join (currentDir , "../../" , "tests" , "onlineboutique" , "kubernetes-manifests.yaml" )
63
- outFile := filepath .Join (currentDir , "../../" , "tests" , "onlineboutique" , "output.json" )
64
- expectedOutput := filepath .Join (currentDir , "../../" , "tests" , "onlineboutique" , "expected_netpol_output.json" )
65
- args := getTestArgs (dirPath , outFile , true )
66
-
67
- Start (args )
68
-
69
- res , err := compareFiles (expectedOutput , outFile )
68
+ tests := map [string ]TestDetails {} //map from test name to test details
69
+ tests ["onlineboutique" ] = TestDetails {dirPath : filepath .Join (currentDir , "../../" , "tests" , "onlineboutique" , "kubernetes-manifests.yaml" ),
70
+ outFile : filepath .Join (currentDir , "../../" , "tests" , "onlineboutique" , "output.json" ),
71
+ expectedOutput : filepath .Join (currentDir , "../../" , "tests" , "onlineboutique" , "expected_netpol_output.json" )}
72
+ tests ["sockshop" ] = TestDetails {dirPath : filepath .Join (currentDir , "../../" , "tests" , "sockshop" , "manifests" ),
73
+ outFile : filepath .Join (currentDir , "../../" , "tests" , "sockshop" , "output.json" ),
74
+ expectedOutput : filepath .Join (currentDir , "../../" , "tests" , "sockshop" , "expected_netpol_output.json" )}
75
+
76
+ for testName , testDetails := range tests {
77
+ args := getTestArgs (testDetails .dirPath , testDetails .outFile , true )
78
+ Start (args )
79
+ res , err := compareFiles (testDetails .expectedOutput , testDetails .outFile )
80
+ if err != nil {
81
+ t .Fatalf ("Test %v: expected err to be nil, but got %v" , testName , err )
82
+ }
83
+ if ! res {
84
+ t .Fatalf ("Test %v: expected res to be true, but got false" , testName )
85
+ }
86
+ os .Remove (testDetails .outFile )
70
87
71
- if err != nil {
72
- t .Fatalf ("expected err to be nil, but got %v" , err )
73
- }
74
- if ! res {
75
- t .Fatalf ("expected res to be true, but got false" )
76
88
}
77
89
78
- os .Remove (outFile )
79
90
}
80
91
81
92
func TestNetpolsInterface (t * testing.T ) {
0 commit comments