mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-11 22:19:25 +00:00
Display number of files / resources in text output
This commit is contained in:
parent
00880f68df
commit
7bfb0b51f1
3 changed files with 17 additions and 6 deletions
4
main.go
4
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
`,
|
||||
},
|
||||
} {
|
||||
|
|
|
|||
Loading…
Reference in a new issue