improve config parsing + fix command deprecation warning

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman
2021-03-22 10:58:09 -04:00
parent b1b57f6ba6
commit f180d1c537
20 changed files with 179 additions and 131 deletions
+1 -1
View File
@@ -71,7 +71,7 @@ func TestPackagesCmdFlags(t *testing.T) {
{
name: "packages-scope-env-binding",
env: map[string]string{
"SYFT_PACKAGES_SCOPE": "all-layers",
"SYFT_PACKAGE_CATALOGER_SCOPE": "all-layers",
},
args: []string{"packages", "-o", "json", request},
assertions: []traitAssertion{
+1
View File
@@ -25,6 +25,7 @@ func TestPowerUserCmdFlags(t *testing.T) {
name: "default-results",
args: []string{"power-user", request},
assertions: []traitAssertion{
assertNotInOutput(" command is deprecated"), // only the root command should be deprecated
assertInOutput(`"type": "regularFile"`), // proof of file-metadata data
assertInOutput(`"algorithm": "sha256"`), // proof of file-metadata default digest algorithm of sha256
assertInOutput(`"metadataType": "ApkMetadata"`), // proof of package artifacts data
+10 -7
View File
@@ -45,16 +45,19 @@ func getSyftCommand(t testing.TB, args ...string) *exec.Cmd {
var binaryLocation string
if os.Getenv("SYFT_BINARY_LOCATION") != "" {
// SYFT_BINARY_LOCATION is relative to the repository root. (e.g., "snapshot/syft-linux_amd64/syft")
// This value is transformed due to the CLI tests' need for a path relative to the test directory.
binaryLocation = path.Join(repoRoot(t), os.Getenv("SYFT_BINARY_LOCATION"))
// SYFT_BINARY_LOCATION is the absolute path to the snapshot binary
binaryLocation = os.Getenv("SYFT_BINARY_LOCATION")
} else {
os := runtime.GOOS
if os == "darwin" {
os = "macos_darwin"
// note: there is a subtle - vs _ difference between these versions
switch runtime.GOOS {
case "darwin":
binaryLocation = path.Join(repoRoot(t), fmt.Sprintf("snapshot/syft-macos_darwin_%s/syft", runtime.GOARCH))
case "linux":
binaryLocation = path.Join(repoRoot(t), fmt.Sprintf("snapshot/syft_linux_%s/syft", runtime.GOARCH))
default:
t.Fatalf("unsupported OS: %s", runtime.GOOS)
}
binaryLocation = path.Join(repoRoot(t), fmt.Sprintf("snapshot/syft-%s_%s/syft", os, runtime.GOARCH))
}
return exec.Command(binaryLocation, args...)
}