Fix file creation for output options (#875)

This commit is contained in:
Alex Goodman
2022-03-08 15:37:28 +00:00
committed by GitHub
parent 5123f073c7
commit 07d3c9af52
12 changed files with 190 additions and 20 deletions
+16
View File
@@ -10,10 +10,26 @@ import (
"testing"
"github.com/acarl005/stripansi"
"github.com/stretchr/testify/require"
)
type traitAssertion func(tb testing.TB, stdout, stderr string, rc int)
func assertFileOutput(tb testing.TB, path string, assertions ...traitAssertion) traitAssertion {
tb.Helper()
return func(tb testing.TB, _, stderr string, rc int) {
content, err := os.ReadFile(path)
require.NoError(tb, err)
contentStr := string(content)
for _, assertion := range assertions {
// treat the file content as stdout
assertion(tb, contentStr, stderr, rc)
}
}
}
func assertJsonReport(tb testing.TB, stdout, _ string, _ int) {
tb.Helper()
var data interface{}