Skip to content

Commit a0000e1

Browse files
weisddrbren
andauthored
Suppress empty results when --only-show-failed-tests is passed (#811)
* Suppress empty results when --only-show-failed-tests is passed Signed-off-by: Igor Beliakov <[email protected]> * Fix remaining typo Signed-off-by: Igor Beliakov <[email protected]> Co-authored-by: Robert Brennan <[email protected]>
1 parent f9e2603 commit a0000e1

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

pkg/validator/output.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,21 @@ type AuditData struct {
5353
Score uint
5454
}
5555

56-
// RemoveSuccessfulResults remove all test that have passed.
56+
// RemoveSuccessfulResults removes all tests that have passed
5757
func (res AuditData) RemoveSuccessfulResults() AuditData {
5858
resCopy := res
59-
resCopy.Results = funk.Map(res.Results, func(auditDataResult Result) Result {
59+
resCopy.Results = []Result{}
60+
61+
filteredResults := funk.Map(res.Results, func(auditDataResult Result) Result {
6062
return auditDataResult.removeSuccessfulResults()
6163
}).([]Result)
64+
65+
for _, result := range filteredResults {
66+
if result.isNotEmpty() {
67+
resCopy.Results = append(resCopy.Results, result)
68+
}
69+
}
70+
6271
return resCopy
6372
}
6473

@@ -86,6 +95,10 @@ type ResultMessage struct {
8695
// ResultSet contiains the results for a set of checks
8796
type ResultSet map[string]ResultMessage
8897

98+
func (res ResultSet) isNotEmpty() bool {
99+
return len(res) > 0
100+
}
101+
89102
func (res ResultSet) removeSuccessfulResults() ResultSet {
90103
newResults := ResultSet{}
91104
for k, resultMessage := range res {
@@ -116,6 +129,13 @@ func (res Result) removeSuccessfulResults() Result {
116129
return resCopy
117130
}
118131

132+
func (res Result) isNotEmpty() bool {
133+
if res.PodResult != nil {
134+
return res.PodResult.isNotEmpty()
135+
}
136+
return res.Results.isNotEmpty()
137+
}
138+
119139
// PodResult provides a list of validation messages for each pod.
120140
type PodResult struct {
121141
Name string
@@ -132,6 +152,15 @@ func (res PodResult) removeSuccessfulResults() PodResult {
132152
return resCopy
133153
}
134154

155+
func (res PodResult) isNotEmpty() bool {
156+
for _, cr := range res.ContainerResults {
157+
if cr.isNotEmpty() {
158+
return true
159+
}
160+
}
161+
return res.Results.isNotEmpty()
162+
}
163+
135164
// ContainerResult provides a list of validation messages for each container.
136165
type ContainerResult struct {
137166
Name string
@@ -144,6 +173,10 @@ func (res ContainerResult) removeSuccessfulResults() ContainerResult {
144173
return resCopy
145174
}
146175

176+
func (res ContainerResult) isNotEmpty() bool {
177+
return res.Results.isNotEmpty()
178+
}
179+
147180
func fillString(id string, l int) string {
148181
for len(id) < l {
149182
id += " "

0 commit comments

Comments
 (0)