mirror of
https://github.com/anchore/syft.git
synced 2026-10-30 14:02:26 +01:00
Add support for multiple output files in different formats (#732)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user