mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-22 07:10:41 -08:00
40 lines
950 B
Go
40 lines
950 B
Go
package commands
|
|
|
|
import (
|
|
"testing"
|
|
|
|
cmd "github.com/aquasecurity/trivy/pkg/commands/artifact"
|
|
"github.com/aquasecurity/trivy/pkg/commands/option"
|
|
"gotest.tools/assert"
|
|
)
|
|
|
|
func Test_getNamespace(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
name string
|
|
currentNamespace string
|
|
opt cmd.Option
|
|
expected string
|
|
}{
|
|
{
|
|
name: "--namespace=custom",
|
|
currentNamespace: "default",
|
|
opt: cmd.Option{KubernetesOption: option.KubernetesOption{Namespace: "custom"}},
|
|
expected: "custom",
|
|
},
|
|
{
|
|
name: "no namespaces passed",
|
|
currentNamespace: "default",
|
|
opt: cmd.Option{KubernetesOption: option.KubernetesOption{Namespace: ""}},
|
|
expected: "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)
|
|
})
|
|
}
|
|
}
|