Skip to content

Commit 0c1c5aa

Browse files
committed
Only print summary messages from --status
Added a Summary.Results method to make it possible to get a specific State result.
1 parent e2cf08a commit 0c1c5aa

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

check/controls.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ type Summary struct {
7676
Info int `json:"total_info"`
7777
}
7878

79+
func (s Summary) Results(c State) int {
80+
var r int
81+
switch c {
82+
case "PASS":
83+
r = s.Pass
84+
case "FAIL":
85+
r = s.Fail
86+
case "WARN":
87+
r = s.Warn
88+
case "INFO":
89+
r = s.Info
90+
}
91+
return r
92+
}
93+
7994
// Predicate a predicate on the given Group and Check arguments.
8095
type Predicate func(group *Group, check *Check) bool
8196

cmd/common.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,19 @@ func printSummary(summary check.Summary, sectionName string) {
243243
}
244244

245245
colors[res].Printf("== Summary %s ==\n", sectionName)
246-
fmt.Printf("%d checks PASS\n%d checks FAIL\n%d checks WARN\n%d checks INFO\n\n",
247-
summary.Pass, summary.Fail, summary.Warn, summary.Info,
248-
)
246+
if statusList == "" {
247+
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)
248+
return
249+
}
250+
statusMap := parseStatus(statusList)
251+
var summaryBuilder strings.Builder
252+
for s, b := range statusMap {
253+
if b {
254+
summaryBuilder.WriteString(fmt.Sprintf("%d checks %v\n", summary.Results(s), s))
255+
}
256+
}
257+
summaryBuilder.WriteString("\n")
258+
fmt.Printf(summaryBuilder.String())
249259
}
250260

251261
// loadConfig finds the correct config dir based on the kubernetes version,

cmd/common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ func TestWriteStdoutOutputStatusList(t *testing.T) {
799799
os.Stdout = rescueStdout
800800

801801
for _, n := range tt.notContains {
802-
assert.NotContains(t, string(out), fmt.Sprintf("[%s]", n))
802+
assert.NotContains(t, string(out), n)
803803
}
804804
}
805805
}

0 commit comments

Comments
 (0)