Add support for multiple output files in different formats (#732)

This commit is contained in:
Keith Zantow
2022-01-06 17:52:20 -05:00
committed by GitHub
parent 38c4b17847
commit 5e5312c72d
51 changed files with 642 additions and 243 deletions
+10
View File
@@ -8,6 +8,7 @@ import (
func TestPackagesCmdFlags(t *testing.T) {
coverageImage := "docker-archive:" + getFixtureImage(t, "image-pkg-coverage")
//badBinariesImage := "docker-archive:" + getFixtureImage(t, "image-bad-binaries")
tmp := t.TempDir() + "/"
tests := []struct {
name string
@@ -32,6 +33,15 @@ func TestPackagesCmdFlags(t *testing.T) {
assertSuccessfulReturnCode,
},
},
{
name: "multiple-output-flags",
args: []string{"packages", "-o", "table", "-o", "json=" + tmp + ".tmp/multiple-output-flag-test.json", coverageImage},
assertions: []traitAssertion{
assertTableReport,
assertFileExists(tmp + ".tmp/multiple-output-flag-test.json"),
assertSuccessfulReturnCode,
},
},
// I haven't been able to reproduce locally yet, but in CI this has proven to be unstable:
// For the same commit:
// pass: https://github.com/anchore/syft/runs/4611344142?check_suite_focus=true
+10
View File
@@ -2,6 +2,7 @@ package cli
import (
"encoding/json"
"os"
"regexp"
"strings"
"testing"
@@ -114,3 +115,12 @@ func assertSuccessfulReturnCode(tb testing.TB, _, _ string, rc int) {
tb.Errorf("expected no failure but got rc=%d", rc)
}
}
func assertFileExists(file string) traitAssertion {
return func(tb testing.TB, _, _ string, _ int) {
tb.Helper()
if _, err := os.Stat(file); err != nil {
tb.Errorf("expected file to exist %s", file)
}
}
}