mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-22 03:07:01 +00:00
add tests for text output, small fix
This commit is contained in:
parent
c3a25b9689
commit
dba9f97c1a
2 changed files with 84 additions and 1 deletions
|
|
@ -32,7 +32,7 @@ func (o *text) Write(filename, kind, version string, err error, skipped bool) {
|
||||||
|
|
||||||
switch status(err, skipped) {
|
switch status(err, skipped) {
|
||||||
case VALID:
|
case VALID:
|
||||||
if !o.verbose {
|
if o.verbose {
|
||||||
fmt.Fprintf(o.w, "%s - %s is valid\n", filename, kind)
|
fmt.Fprintf(o.w, "%s - %s is valid\n", filename, kind)
|
||||||
}
|
}
|
||||||
o.nValid++
|
o.nValid++
|
||||||
|
|
|
||||||
83
pkg/output/text_test.go
Normal file
83
pkg/output/text_test.go
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
package output
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTextWrite(t *testing.T) {
|
||||||
|
type result struct {
|
||||||
|
fileName, kind, version string
|
||||||
|
err error
|
||||||
|
skipped bool
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range []struct {
|
||||||
|
name string
|
||||||
|
withSummary bool
|
||||||
|
verbose bool
|
||||||
|
|
||||||
|
res []result
|
||||||
|
expect string
|
||||||
|
} {
|
||||||
|
{
|
||||||
|
"a single deployment, no summary, no verbose",
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
[]result{
|
||||||
|
{
|
||||||
|
"deployment.yml",
|
||||||
|
"Deployment",
|
||||||
|
"apps/v1",
|
||||||
|
nil,
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a single deployment, summary, no verbose",
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
[]result{
|
||||||
|
{
|
||||||
|
"deployment.yml",
|
||||||
|
"Deployment",
|
||||||
|
"apps/v1",
|
||||||
|
nil,
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Run summary - Valid: 1, Invalid: 0, Errors: 0 Skipped: 0\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a single deployment, verbose, with summary",
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
[]result{
|
||||||
|
{
|
||||||
|
"deployment.yml",
|
||||||
|
"Deployment",
|
||||||
|
"apps/v1",
|
||||||
|
nil,
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
`deployment.yml - Deployment is valid
|
||||||
|
Run summary - Valid: 1, Invalid: 0, Errors: 0 Skipped: 0
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
w := new(bytes.Buffer)
|
||||||
|
o := Text(w, testCase.withSummary, testCase.verbose)
|
||||||
|
|
||||||
|
for _, res := range testCase.res {
|
||||||
|
o.Write(res.fileName, res.kind, res.version, res.err, res.skipped)
|
||||||
|
}
|
||||||
|
o.Flush()
|
||||||
|
|
||||||
|
if w.String() != testCase.expect {
|
||||||
|
t.Errorf("%s - expected: %s, got: %s", testCase.name, testCase.expect, w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue