diff --git a/check/controls.go b/check/controls.go index f84acf7..6151b85 100644 --- a/check/controls.go +++ b/check/controls.go @@ -76,6 +76,21 @@ type Summary struct { Info int `json:"total_info"` } +func (s Summary) Results(c State) int { + var r int + switch c { + case "PASS": + r = s.Pass + case "FAIL": + r = s.Fail + case "WARN": + r = s.Warn + case "INFO": + r = s.Info + } + return r +} + // Predicate a predicate on the given Group and Check arguments. type Predicate func(group *Group, check *Check) bool diff --git a/cmd/common.go b/cmd/common.go index e6fab38..fff30c7 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -243,9 +243,19 @@ func printSummary(summary check.Summary, sectionName string) { } colors[res].Printf("== Summary %s ==\n", sectionName) - fmt.Printf("%d checks PASS\n%d checks FAIL\n%d checks WARN\n%d checks INFO\n\n", - summary.Pass, summary.Fail, summary.Warn, summary.Info, - ) + if statusList == "" { + fmt.Printf("%d checks PASS\n%d checks FAIL\n%d checks WARN\n%d checks INFO\n\n", summary.Pass, summary.Fail, summary.Warn, summary.Info) + return + } + statusMap := parseStatus(statusList) + var summaryBuilder strings.Builder + for s, b := range statusMap { + if b { + summaryBuilder.WriteString(fmt.Sprintf("%d checks %v\n", summary.Results(s), s)) + } + } + summaryBuilder.WriteString("\n") + fmt.Printf(summaryBuilder.String()) } // loadConfig finds the correct config dir based on the kubernetes version, diff --git a/cmd/common_test.go b/cmd/common_test.go index 7152ac2..c9b4a4f 100644 --- a/cmd/common_test.go +++ b/cmd/common_test.go @@ -799,7 +799,7 @@ func TestWriteStdoutOutputStatusList(t *testing.T) { os.Stdout = rescueStdout for _, n := range tt.notContains { - assert.NotContains(t, string(out), fmt.Sprintf("[%s]", n)) + assert.NotContains(t, string(out), n) } } }