github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/k8s/commands/namespace_test.go (about) 1 package commands 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/devseccon/trivy/pkg/flag" 9 ) 10 11 func Test_getNamespace(t *testing.T) { 12 13 tests := []struct { 14 name string 15 currentNamespace string 16 opts flag.Options 17 want string 18 }{ 19 { 20 name: "--namespace=custom", 21 currentNamespace: "default", 22 opts: flag.Options{ 23 K8sOptions: flag.K8sOptions{ 24 Namespace: "custom", 25 }, 26 }, 27 want: "custom", 28 }, 29 { 30 name: "no namespaces passed", 31 currentNamespace: "default", 32 opts: flag.Options{ 33 K8sOptions: flag.K8sOptions{ 34 Namespace: "", 35 }, 36 }, 37 want: "default", 38 }, 39 } 40 41 for _, test := range tests { 42 t.Run(test.name, func(t *testing.T) { 43 got := getNamespace(test.opts, test.currentNamespace) 44 assert.Equal(t, test.want, got) 45 }) 46 } 47 }