mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-11 14:09:21 +00:00
add back json output tests
This commit is contained in:
parent
1b4bc79841
commit
81c097f1bb
2 changed files with 111 additions and 6 deletions
111
pkg/output/json_test.go
Normal file
111
pkg/output/json_test.go
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
package output
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/yannh/kubeconform/pkg/resource"
|
||||
"github.com/yannh/kubeconform/pkg/validator"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestJSONWrite(t *testing.T) {
|
||||
for _, testCase := range []struct {
|
||||
name string
|
||||
withSummary bool
|
||||
isStdin bool
|
||||
verbose bool
|
||||
results []validator.Result
|
||||
expect string
|
||||
}{
|
||||
{
|
||||
"a single deployment, no summary, no verbose",
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
[]validator.Result{},
|
||||
"{\n \"resources\": []\n}\n",
|
||||
},
|
||||
|
||||
{
|
||||
"a single deployment, summary, no verbose",
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
[]validator.Result{
|
||||
{
|
||||
Resource: resource.Resource{
|
||||
Path: "deployment.yml",
|
||||
Bytes: []byte(`apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: "my-app"
|
||||
`),
|
||||
},
|
||||
Status: validator.Valid,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
`{
|
||||
"resources": [],
|
||||
"summary": {
|
||||
"valid": 1,
|
||||
"invalid": 0,
|
||||
"errors": 0,
|
||||
"skipped": 0
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
"a single 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.Valid,
|
||||
Err: nil,
|
||||
},
|
||||
|
||||
},
|
||||
`{
|
||||
"resources": [
|
||||
{
|
||||
"filename": "deployment.yml",
|
||||
"kind": "Deployment",
|
||||
"name": "my-app",
|
||||
"version": "apps/v1",
|
||||
"status": "statusValid",
|
||||
"msg": ""
|
||||
}
|
||||
],
|
||||
"summary": {
|
||||
"valid": 1,
|
||||
"invalid": 0,
|
||||
"errors": 0,
|
||||
"skipped": 0
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
} {
|
||||
w := new(bytes.Buffer)
|
||||
o := jsonOutput(w, testCase.withSummary, testCase.isStdin, testCase.verbose)
|
||||
|
||||
for _, res := range testCase.results {
|
||||
o.Write(res)
|
||||
}
|
||||
o.Flush()
|
||||
|
||||
if w.String() != testCase.expect {
|
||||
t.Errorf("%s - expected: %s, got: %s", testCase.name, testCase.expect, w)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,12 +8,6 @@ import (
|
|||
)
|
||||
|
||||
func TestTextWrite(t *testing.T) {
|
||||
type result struct {
|
||||
fileName, kind, name, version string
|
||||
err error
|
||||
skipped bool
|
||||
}
|
||||
|
||||
for _, testCase := range []struct {
|
||||
name string
|
||||
withSummary bool
|
||||
|
|
|
|||
Loading…
Reference in a new issue