diff --git a/main.go b/main.go index f36a2ee..d58eafb 100644 --- a/main.go +++ b/main.go @@ -274,9 +274,7 @@ func realMain() int { wg.Wait() close(validationResults) success := <-res - if err = o.Flush(); err != nil { - fmt.Fprint(os.Stderr, "failed flushing output") - } + o.Flush() if !success { return 1 diff --git a/pkg/output/text.go b/pkg/output/text.go index fc19b68..a7cd2b5 100644 --- a/pkg/output/text.go +++ b/pkg/output/text.go @@ -11,6 +11,7 @@ type text struct { w io.Writer withSummary bool verbose bool + files map[string]bool nValid, nInvalid, nErrors, nSkipped int } @@ -20,6 +21,7 @@ func Text(w io.Writer, withSummary, verbose bool) Output { w: w, withSummary: withSummary, verbose: verbose, + files: map[string]bool{}, nValid: 0, nInvalid: 0, nErrors: 0, @@ -33,6 +35,7 @@ func (o *text) Write(filename, kind, version string, reserr error, skipped bool) var err error + o.files[filename] = true switch status(reserr, skipped) { case VALID: if o.verbose { @@ -58,7 +61,17 @@ func (o *text) Write(filename, kind, version string, reserr error, skipped bool) func (o *text) Flush() error { var err error if o.withSummary { - _, err = fmt.Fprintf(o.w, "Run summary - Valid: %d, Invalid: %d, Errors: %d Skipped: %d\n", o.nValid, o.nInvalid, o.nErrors, o.nSkipped) + nFiles := len(o.files) + nResources := o.nValid + o.nInvalid + o.nErrors + o.nSkipped + resourcesPlural := "" + if nResources > 1 { + resourcesPlural = "s" + } + filesPlural := "" + if nFiles > 1 { + filesPlural = "s" + } + _, err = fmt.Fprintf(o.w, "Summary: %d resource%s found in %d file%s - Valid: %d, Invalid: %d, Errors: %d Skipped: %d\n", nResources, resourcesPlural, nFiles, filesPlural, o.nValid, o.nInvalid, o.nErrors, o.nSkipped) } return err diff --git a/pkg/output/text_test.go b/pkg/output/text_test.go index 3adaeab..21fc1e7 100644 --- a/pkg/output/text_test.go +++ b/pkg/output/text_test.go @@ -48,7 +48,7 @@ func TestTextWrite(t *testing.T) { false, }, }, - "Run summary - Valid: 1, Invalid: 0, Errors: 0 Skipped: 0\n", + "Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0 Skipped: 0\n", }, { "a single deployment, verbose, with summary", @@ -64,7 +64,7 @@ func TestTextWrite(t *testing.T) { }, }, `deployment.yml - Deployment is valid -Run summary - Valid: 1, Invalid: 0, Errors: 0 Skipped: 0 +Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0 Skipped: 0 `, }, } {