Add test to JSON output with validationError

This commit is contained in:
Yann Hamon 2023-02-26 12:29:35 +01:00
parent 2b4dc8f9f2
commit d329fa6483
2 changed files with 60 additions and 2 deletions

View file

@ -50,11 +50,15 @@ func (o *jsono) Write(result validator.Result) error {
o.nValid++
case validator.Invalid:
st = "statusInvalid"
msg = result.Err.Error()
if result.Err != nil {
msg = result.Err.Error()
}
o.nInvalid++
case validator.Error:
st = "statusError"
msg = result.Err.Error()
if result.Err != nil {
msg = result.Err.Error()
}
o.nErrors++
case validator.Skipped:
st = "statusSkipped"

View file

@ -93,6 +93,60 @@ metadata:
"skipped": 0
}
}
`,
},
{
"a single invalid deployment, verbose, with summary",
true,
false,
true,
[]validator.Result{
{
Resource: resource.Resource{
Path: "deployment.yml",
Bytes: []byte(`apiVersion: apps/v1
kind: Deployment
metadata:
name: "my-app"
`),
},
Status: validator.Invalid,
Err: &validator.ValidationError{
Path: "foo",
Msg: "bar",
},
ValidationErrors: []validator.ValidationError{
{
Path: "foo",
Msg: "bar",
},
},
},
},
`{
"resources": [
{
"filename": "deployment.yml",
"kind": "Deployment",
"name": "my-app",
"version": "apps/v1",
"status": "statusInvalid",
"msg": "bar",
"validationErrors": [
{
"path": "foo",
"msg": "bar"
}
]
}
],
"summary": {
"valid": 0,
"invalid": 1,
"errors": 0,
"skipped": 0
}
}
`,
},
} {