simplify command alias logic + remove deprecation warning for root command

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman
2021-03-22 15:25:04 -04:00
parent 36e4af1953
commit 46636ccb3c
4 changed files with 50 additions and 46 deletions
+39 -14
View File
@@ -9,25 +9,50 @@ import (
func TestRootCmdAliasesToPackagesSubcommand(t *testing.T) {
request := "docker-archive:" + getFixtureImage(t, "image-pkg-coverage")
deprecationWarning := "The root command is deprecated"
_, aliasStdout, aliasStderr := runSyftCommand(t, nil, request)
if !strings.Contains(aliasStderr, deprecationWarning) {
t.Errorf("missing root-packages alias deprecation warning")
tests := []struct {
name string
env map[string]string
assertions []traitAssertion
}{
{
name: "go-case",
assertions: []traitAssertion{
assertTableReport,
assertSuccessfulReturnCode,
},
},
{
name: "respond-to-output-binding",
env: map[string]string{
"SYFT_OUTPUT": "text",
},
assertions: []traitAssertion{
assertInOutput("[Image]"),
assertSuccessfulReturnCode,
},
},
}
_, pkgsStdout, pkgsStderr := runSyftCommand(t, nil, "packages", request)
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
aliasCmd, aliasStdout, aliasStderr := runSyftCommand(t, test.env, request)
for _, traitFn := range test.assertions {
traitFn(t, aliasStdout, aliasStderr, aliasCmd.ProcessState.ExitCode())
}
if strings.Contains(pkgsStderr, deprecationWarning) {
t.Errorf("packages command should not have deprecation warning")
}
pkgCmd, pkgsStdout, pkgsStderr := runSyftCommand(t, test.env, "packages", request)
for _, traitFn := range test.assertions {
traitFn(t, pkgsStdout, pkgsStderr, pkgCmd.ProcessState.ExitCode())
}
if aliasStdout != pkgsStdout {
t.Errorf("packages and root command should have same report output but do not!")
dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(aliasStdout, pkgsStdout, true)
t.Error(dmp.DiffPrettyText(diffs))
if aliasStdout != pkgsStdout {
t.Errorf("packages and root command should have same report output but do not!")
dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(aliasStdout, pkgsStdout, true)
t.Error(dmp.DiffPrettyText(diffs))
}
})
}
}