forked from anchore/syft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow convert to take stdin (anchore#1570)
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
- Loading branch information
Showing
5 changed files
with
114 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestConvertCmd(t *testing.T) { | ||
assertions := []traitAssertion{ | ||
assertInOutput("PackageName: musl-utils"), | ||
assertSuccessfulReturnCode, | ||
} | ||
|
||
tests := []struct { | ||
from string | ||
to string | ||
}{ | ||
{from: "syft-json", to: "spdx-tag-value"}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(fmt.Sprintf("from %s to %s", test.from, test.to), func(t *testing.T) { | ||
sbomArgs := []string{"dir:./test-fixtures/image-pkg-coverage", "-o", test.from} | ||
cmd, stdout, stderr := runSyft(t, nil, sbomArgs...) | ||
if cmd.ProcessState.ExitCode() != 0 { | ||
t.Log("STDOUT:\n", stdout) | ||
t.Log("STDERR:\n", stderr) | ||
t.Log("COMMAND:", strings.Join(cmd.Args, " ")) | ||
t.Fatalf("failure executing syft creating an sbom") | ||
return | ||
} | ||
|
||
convertArgs := []string{"convert", "-", "-o", test.to} | ||
cmd = getSyftCommand(t, convertArgs...) | ||
|
||
cmd.Stdin = strings.NewReader(stdout) | ||
stdout, stderr = runCommandObj(t, cmd, nil, false) | ||
|
||
for _, traitFn := range assertions { | ||
traitFn(t, stdout, stderr, cmd.ProcessState.ExitCode()) | ||
} | ||
if t.Failed() { | ||
t.Log("STDOUT:\n", stdout) | ||
t.Log("STDERR:\n", stderr) | ||
t.Log("COMMAND:", strings.Join(cmd.Args, " ")) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters