2
2
package main
3
3
4
4
import (
5
- "flag"
6
5
"path/filepath"
7
6
"testing"
8
7
@@ -16,6 +15,7 @@ func TestCreatePolicyReport(t *testing.T) {
16
15
name string
17
16
policyreport * appsv1aplha1.PolicyReport
18
17
ns string
18
+ category string
19
19
}{
20
20
{"demo-test-1" , & appsv1aplha1.PolicyReport {
21
21
ObjectMeta : metav1.ObjectMeta {
@@ -26,7 +26,7 @@ func TestCreatePolicyReport(t *testing.T) {
26
26
Fail : 4 ,
27
27
Warn : 0 ,
28
28
},
29
- }, "default" },
29
+ }, "default" , "" },
30
30
{"demo-test-2" , & appsv1aplha1.PolicyReport {
31
31
ObjectMeta : metav1.ObjectMeta {
32
32
Name : "demo-2" ,
@@ -40,7 +40,7 @@ func TestCreatePolicyReport(t *testing.T) {
40
40
{
41
41
Policy : "test-policy" ,
42
42
Rule : "test-rule" ,
43
- Category : "test-category " ,
43
+ Category : "CIS " ,
44
44
Result : "pass" ,
45
45
Scored : true ,
46
46
Description : "test-description" ,
@@ -59,21 +59,41 @@ func TestCreatePolicyReport(t *testing.T) {
59
59
},
60
60
},
61
61
},
62
- }, "default" },
62
+ }, "default" , "CIS" },
63
63
}
64
-
65
64
var kubeconfig * string
66
- if home := homedir .HomeDir (); home != "" {
67
- kubeconfig = flag .String ("kubeconfig" , filepath .Join (home , ".kube" , "config" ), "(optional) absolute path to the kubeconfig file" )
68
- } else {
69
- kubeconfig = flag .String ("kubeconfig" , "" , "absolute path to the kubeconfig file" )
65
+ if kubeconfig == nil {
66
+ var path string
67
+ if home := homedir .HomeDir (); home != "" {
68
+ path = filepath .Join (home , ".kube" , "config" )
69
+ } else {
70
+ path = ""
71
+ }
72
+ kubeconfig = & path
70
73
}
71
- flag .Parse ()
72
74
73
75
for _ , pr := range policyTests {
74
- err := createPolicyReport (pr .ns , pr .policyreport , kubeconfig )
76
+ err := createPolicyReport (pr .policyreport . Name , pr . ns , pr .category , kubeconfig , pr . policyreport )
75
77
if err != nil {
76
78
t .Fatalf ("error creating policy report: %v" , err )
77
79
}
78
80
}
79
81
}
82
+
83
+ func TestRunKubeBench (t * testing.T ) {
84
+ _ , err := runKubeBench ()
85
+ if err != nil {
86
+ t .Fatalf ("error getting kube-bench json output due to: %v" , err )
87
+ }
88
+ }
89
+
90
+ func TestGetBody (t * testing.T ) {
91
+ _ , err := getBody ()
92
+ if err != nil {
93
+ t .Fatalf ("error getting body of kube-bench json output due to: %v" , err )
94
+ }
95
+ }
96
+
97
+ func TestGetArguments (t * testing.T ) {
98
+ t .Log (getArguments ())
99
+ }
0 commit comments