mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-23 07:29:00 -08:00
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:
@@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user