Skip to content

Commit

Permalink
Merge pull request #178 from cookpad/fix_kubebench_fail
Browse files Browse the repository at this point in the history
Update tests for new kube-bench format
  • Loading branch information
aidy authored Feb 9, 2021
2 parents cf551e0 + 1eb5005 commit f15b348
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions test/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,20 +468,28 @@ func validateKubeBench(t *testing.T, kubeconfig string) {
WaitUntilPodsSucceeded(t, kubectlOptions, metav1.ListOptions{LabelSelector: "app=kube-bench"}, 1, 30, 5*time.Second)
output, err := k8s.RunKubectlAndGetOutputE(t, kubectlOptions, "logs", "-l", "app=kube-bench")
require.NoError(t, err)
results := make([]KubeBenchResult, 1)
err = json.Unmarshal([]byte(output), &results)
resultWrapper := KubeBenchResult{}
err = json.Unmarshal([]byte(output), &resultWrapper)
require.NoError(t, err)
result := results[0]
assert.Equal(t, result.TotalFail, 0)
result := resultWrapper.Totals
if !assert.Equal(t, 0, result.TotalFail) {
fmt.Printf(`non-zero total_fail: %s`, output)
}
// https://github.com/awslabs/amazon-eks-ami/pull/391
assert.LessOrEqual(t, result.TotalWarn, 1)
if !assert.LessOrEqual(t, result.TotalWarn, 1) {
fmt.Printf(`>=1 total_warn: %s`, output)
}
}

type KubeBenchResult struct {
TotalPass int `json:total_pass`
TotalFail int `json:total_fail`
TotalWarn int `json:total_warn`
TotalInfo int `json:total_info`
Totals KubeBenchResultTotals `json:"Totals"`
}

type KubeBenchResultTotals struct {
TotalPass int `json:"total_pass"`
TotalFail int `json:"total_fail"`
TotalWarn int `json:"total_warn"`
TotalInfo int `json:"total_info"`
}

const KUBEBENCH_MANIFEST = `---
Expand Down

0 comments on commit f15b348

Please sign in to comment.