Display number of files / resources in text output

This commit is contained in:
Yann Hamon 2020-06-04 23:59:50 +02:00
parent 00880f68df
commit 7bfb0b51f1
3 changed files with 17 additions and 6 deletions

View file

@ -274,9 +274,7 @@ func realMain() int {
wg.Wait() wg.Wait()
close(validationResults) close(validationResults)
success := <-res success := <-res
if err = o.Flush(); err != nil { o.Flush()
fmt.Fprint(os.Stderr, "failed flushing output")
}
if !success { if !success {
return 1 return 1

View file

@ -11,6 +11,7 @@ type text struct {
w io.Writer w io.Writer
withSummary bool withSummary bool
verbose bool verbose bool
files map[string]bool
nValid, nInvalid, nErrors, nSkipped int nValid, nInvalid, nErrors, nSkipped int
} }
@ -20,6 +21,7 @@ func Text(w io.Writer, withSummary, verbose bool) Output {
w: w, w: w,
withSummary: withSummary, withSummary: withSummary,
verbose: verbose, verbose: verbose,
files: map[string]bool{},
nValid: 0, nValid: 0,
nInvalid: 0, nInvalid: 0,
nErrors: 0, nErrors: 0,
@ -33,6 +35,7 @@ func (o *text) Write(filename, kind, version string, reserr error, skipped bool)
var err error var err error
o.files[filename] = true
switch status(reserr, skipped) { switch status(reserr, skipped) {
case VALID: case VALID:
if o.verbose { if o.verbose {
@ -58,7 +61,17 @@ func (o *text) Write(filename, kind, version string, reserr error, skipped bool)
func (o *text) Flush() error { func (o *text) Flush() error {
var err error var err error
if o.withSummary { 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 return err

View file

@ -48,7 +48,7 @@ func TestTextWrite(t *testing.T) {
false, 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", "a single deployment, verbose, with summary",
@ -64,7 +64,7 @@ func TestTextWrite(t *testing.T) {
}, },
}, },
`deployment.yml - Deployment is valid `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
`, `,
}, },
} { } {