mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-13 00:00:19 -08:00
Co-authored-by: afdesk <work@afdesk.com> Co-authored-by: DmitriyLewen <91113035+DmitriyLewen@users.noreply.github.com>
48 lines
867 B
Go
48 lines
867 B
Go
package commands
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/aquasecurity/trivy/pkg/flag"
|
|
)
|
|
|
|
func Test_getNamespace(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
name string
|
|
currentNamespace string
|
|
opts flag.Options
|
|
want string
|
|
}{
|
|
{
|
|
name: "--namespace=custom",
|
|
currentNamespace: "default",
|
|
opts: flag.Options{
|
|
K8sOptions: flag.K8sOptions{
|
|
Namespace: "custom",
|
|
},
|
|
},
|
|
want: "custom",
|
|
},
|
|
{
|
|
name: "no namespaces passed",
|
|
currentNamespace: "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.opts, test.currentNamespace)
|
|
assert.Equal(t, test.want, got)
|
|
})
|
|
}
|
|
}
|