diff --git a/pkg/output/text.go b/pkg/output/text.go index 6f1f7fc..c958e91 100644 --- a/pkg/output/text.go +++ b/pkg/output/text.go @@ -32,7 +32,7 @@ func (o *text) Write(filename, kind, version string, err error, skipped bool) { switch status(err, skipped) { case VALID: - if !o.verbose { + if o.verbose { fmt.Fprintf(o.w, "%s - %s is valid\n", filename, kind) } o.nValid++ diff --git a/pkg/output/text_test.go b/pkg/output/text_test.go new file mode 100644 index 0000000..3bc1236 --- /dev/null +++ b/pkg/output/text_test.go @@ -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) + } + } +} \ No newline at end of file