From 5920cccf075f4045ff804743b197cbc2ed8253ef Mon Sep 17 00:00:00 2001 From: Yann Hamon Date: Sun, 18 Oct 2020 12:57:17 +0200 Subject: [PATCH] fine-tune text logging --- acceptance.bats | 2 +- pkg/output/text.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/acceptance.bats b/acceptance.bats index dccc9ae..455c99b 100755 --- a/acceptance.bats +++ b/acceptance.bats @@ -43,7 +43,7 @@ @test "Return relevant error for non-existent file" { run bin/kubeconform fixtures/not-here [ "$status" -eq 1 ] - [ "$output" = "fixtures/not-here - failed validation: open fixtures/not-here: no such file or directory" ] + [ "$output" = "fixtures/not-here - failed validation: open fixtures/not-here: no such file or directory" ] } @test "Fail when parsing a config with additional properties and strict set" { diff --git a/pkg/output/text.go b/pkg/output/text.go index 1fcd9c2..25171e8 100644 --- a/pkg/output/text.go +++ b/pkg/output/text.go @@ -46,7 +46,11 @@ func (o *text) Write(filename, kind, name, version string, reserr error, skipped _, err = fmt.Fprintf(o.w, "%s - %s %s is invalid: %s\n", filename, kind, name, reserr) o.nInvalid++ case ERROR: - _, err = fmt.Fprintf(o.w, "%s - %s %s failed validation: %s\n", filename, kind, name, reserr) + if kind != "" && name != "" { + _, err = fmt.Fprintf(o.w, "%s - %s %s failed validation: %s\n", filename, kind, name, reserr) + } else { + _, err = fmt.Fprintf(o.w, "%s - failed validation: %s\n", filename, reserr) + } o.nErrors++ case SKIPPED: if o.verbose {