fix json output

This commit is contained in:
Yann Hamon 2020-06-01 19:15:12 +02:00
parent f718b2c919
commit c3a25b9689
2 changed files with 28 additions and 13 deletions

View file

@ -57,7 +57,7 @@ func (o *jsono) Write(filename, kind, version string, err error, skipped bool) {
o.nSkipped++
}
if o.verbose || s == VALID || s == SKIPPED {
if o.verbose || (s != VALID && s != SKIPPED) {
o.results = append(o.results, result{Filename: filename, Kind: kind, Version: version, Status: st, Msg: msg})
}
}

View file

@ -6,7 +6,6 @@ import (
)
func TestJSONWrite(t *testing.T) {
type result struct {
fileName, kind, version string
err error
@ -22,7 +21,7 @@ func TestJSONWrite(t *testing.T) {
expect string
} {
{
"a single deployment, no summary",
"a single deployment, no summary, no verbose",
false,
false,
[]result{
@ -35,20 +34,12 @@ func TestJSONWrite(t *testing.T) {
},
},
`{
"resources": [
{
"filename": "deployment.yml",
"kind": "Deployment",
"version": "apps/v1",
"status": "VALID",
"msg": ""
}
]
"resources": []
}
`,
},
{
"a single deployment, with summary",
"a single deployment, summary, no verbose",
true,
false,
[]result{
@ -61,6 +52,30 @@ func TestJSONWrite(t *testing.T) {
},
},
`{
"resources": [],
"summary": {
"valid": 1,
"invalid": 0,
"errors": 0,
"skipped": 0
}
}
`,
},
{
"a single deployment, verbose, with summary",
true,
true,
[]result{
{
"deployment.yml",
"Deployment",
"apps/v1",
nil,
false,
},
},
`{
"resources": [
{
"filename": "deployment.yml",