22package main
33
44import (
5- "flag"
65 "path/filepath"
76 "testing"
87
@@ -16,6 +15,7 @@ func TestCreatePolicyReport(t *testing.T) {
1615 name string
1716 policyreport * appsv1aplha1.PolicyReport
1817 ns string
18+ category string
1919 }{
2020 {"demo-test-1" , & appsv1aplha1.PolicyReport {
2121 ObjectMeta : metav1.ObjectMeta {
@@ -26,7 +26,7 @@ func TestCreatePolicyReport(t *testing.T) {
2626 Fail : 4 ,
2727 Warn : 0 ,
2828 },
29- }, "default" },
29+ }, "default" , "" },
3030 {"demo-test-2" , & appsv1aplha1.PolicyReport {
3131 ObjectMeta : metav1.ObjectMeta {
3232 Name : "demo-2" ,
@@ -40,7 +40,7 @@ func TestCreatePolicyReport(t *testing.T) {
4040 {
4141 Policy : "test-policy" ,
4242 Rule : "test-rule" ,
43- Category : "test-category " ,
43+ Category : "CIS " ,
4444 Result : "pass" ,
4545 Scored : true ,
4646 Description : "test-description" ,
@@ -59,21 +59,41 @@ func TestCreatePolicyReport(t *testing.T) {
5959 },
6060 },
6161 },
62- }, "default" },
62+ }, "default" , "CIS" },
6363 }
64-
6564 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
7073 }
71- flag .Parse ()
7274
7375 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 )
7577 if err != nil {
7678 t .Fatalf ("error creating policy report: %v" , err )
7779 }
7880 }
7981}
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