refactor: move from urfave/cli to spf13/cobra (#2458)

Co-authored-by: afdesk <work@afdesk.com>
Co-authored-by: DmitriyLewen <91113035+DmitriyLewen@users.noreply.github.com>
This commit is contained in:
Teppei Fukuda
2022-07-09 19:40:31 +03:00
committed by GitHub
parent 7699153c66
commit 5b7e0a858d
73 changed files with 3663 additions and 3533 deletions

View File

@@ -3,9 +3,9 @@ package commands
import (
"testing"
cmd "github.com/aquasecurity/trivy/pkg/commands/artifact"
"github.com/aquasecurity/trivy/pkg/commands/option"
"gotest.tools/assert"
"github.com/stretchr/testify/assert"
"github.com/aquasecurity/trivy/pkg/flag"
)
func Test_getNamespace(t *testing.T) {
@@ -13,27 +13,35 @@ func Test_getNamespace(t *testing.T) {
tests := []struct {
name string
currentNamespace string
opt cmd.Option
expected string
opts flag.Options
want string
}{
{
name: "--namespace=custom",
currentNamespace: "default",
opt: cmd.Option{KubernetesOption: option.KubernetesOption{Namespace: "custom"}},
expected: "custom",
opts: flag.Options{
K8sOptions: flag.K8sOptions{
Namespace: "custom",
},
},
want: "custom",
},
{
name: "no namespaces passed",
currentNamespace: "default",
opt: cmd.Option{KubernetesOption: option.KubernetesOption{Namespace: ""}},
expected: "default",
opts: flag.Options{
K8sOptions: flag.K8sOptions{
Namespace: "",
},
},
want: "default",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := getNamespace(test.opt, test.currentNamespace)
assert.Equal(t, test.expected, got)
got := getNamespace(test.opts, test.currentNamespace)
assert.Equal(t, test.want, got)
})
}
}