Skip to content

Commit

Permalink
Suppress empty results when --only-show-failed-tests is passed (#811)
Browse files Browse the repository at this point in the history
* Suppress empty results when --only-show-failed-tests is passed

Signed-off-by: Igor Beliakov <demtis.register@gmail.com>

* Fix remaining typo

Signed-off-by: Igor Beliakov <demtis.register@gmail.com>

Co-authored-by: Robert Brennan <accounts@rbren.io>
  • Loading branch information
weisdd and rbren authored Jul 26, 2022
1 parent f9e2603 commit a0000e1
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions pkg/validator/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,21 @@ type AuditData struct {
Score uint
}

// RemoveSuccessfulResults remove all test that have passed.
// RemoveSuccessfulResults removes all tests that have passed
func (res AuditData) RemoveSuccessfulResults() AuditData {
resCopy := res
resCopy.Results = funk.Map(res.Results, func(auditDataResult Result) Result {
resCopy.Results = []Result{}

filteredResults := funk.Map(res.Results, func(auditDataResult Result) Result {
return auditDataResult.removeSuccessfulResults()
}).([]Result)

for _, result := range filteredResults {
if result.isNotEmpty() {
resCopy.Results = append(resCopy.Results, result)
}
}

return resCopy
}

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

func (res ResultSet) isNotEmpty() bool {
return len(res) > 0
}

func (res ResultSet) removeSuccessfulResults() ResultSet {
newResults := ResultSet{}
for k, resultMessage := range res {
Expand Down Expand Up @@ -116,6 +129,13 @@ func (res Result) removeSuccessfulResults() Result {
return resCopy
}

func (res Result) isNotEmpty() bool {
if res.PodResult != nil {
return res.PodResult.isNotEmpty()
}
return res.Results.isNotEmpty()
}

// PodResult provides a list of validation messages for each pod.
type PodResult struct {
Name string
Expand All @@ -132,6 +152,15 @@ func (res PodResult) removeSuccessfulResults() PodResult {
return resCopy
}

func (res PodResult) isNotEmpty() bool {
for _, cr := range res.ContainerResults {
if cr.isNotEmpty() {
return true
}
}
return res.Results.isNotEmpty()
}

// ContainerResult provides a list of validation messages for each container.
type ContainerResult struct {
Name string
Expand All @@ -144,6 +173,10 @@ func (res ContainerResult) removeSuccessfulResults() ContainerResult {
return resCopy
}

func (res ContainerResult) isNotEmpty() bool {
return res.Results.isNotEmpty()
}

func fillString(id string, l int) string {
for len(id) < l {
id += " "
Expand Down

0 comments on commit a0000e1

Please sign in to comment.