Skip to content

Commit

Permalink
feat(gator): print object name on test output (#3018)
Browse files Browse the repository at this point in the history
Signed-off-by: Duologic <jeroen@simplistic.be>
  • Loading branch information
Duologic authored Sep 26, 2023
1 parent 3e66ee2 commit cbfcdde
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/gator/test/gatortest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func Test_formatOutput(t *testing.T) {
ViolatingObject: barObject,
Trace: nil,
}},
expectedOutput: `[""] Message: ""
expectedOutput: `/ : [""] Message: ""
`,
},
{
Expand Down
19 changes: 18 additions & 1 deletion cmd/gator/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,24 @@ func formatOutput(flagOutput string, results []*test.GatorResult, stats []*instr
var buf bytes.Buffer
if len(results) > 0 {
for _, result := range results {
buf.WriteString(fmt.Sprintf("[%q] Message: %q\n", result.Constraint.GetName(), result.Msg))
obj := fmt.Sprintf("%s/%s %s",
result.ViolatingObject.GetAPIVersion(),
result.ViolatingObject.GetKind(),
result.ViolatingObject.GetName(),
)
if result.ViolatingObject.GetNamespace() != "" {
obj = fmt.Sprintf("%s/%s %s/%s",
result.ViolatingObject.GetAPIVersion(),
result.ViolatingObject.GetKind(),
result.ViolatingObject.GetNamespace(),
result.ViolatingObject.GetName(),
)
}
buf.WriteString(fmt.Sprintf("%s: [%q] Message: %q\n",
obj,
result.Constraint.GetName(),
result.Msg,
))

if result.Trace != nil {
buf.WriteString(fmt.Sprintf("Trace: %v", *result.Trace))
Expand Down

0 comments on commit cbfcdde

Please sign in to comment.