github.com/wtfutil/wtf@v0.43.0/modules/kubernetes/widget_test.go (about) 1 package kubernetes 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func Test_generateTitle(t *testing.T) { 10 type fields struct { 11 title string 12 namespaces []string 13 context string 14 } 15 16 testCases := []struct { 17 name string 18 fields fields 19 want string 20 }{ 21 { 22 name: "No Namespaces", 23 fields: fields{ 24 namespaces: []string{}, 25 }, 26 want: "Kube", 27 }, 28 { 29 name: "One Namespace", 30 fields: fields{ 31 namespaces: []string{"some-namespace"}, 32 }, 33 want: "Kube - Namespace: some-namespace", 34 }, 35 { 36 name: "Multiple Namespaces", 37 fields: fields{ 38 namespaces: []string{"ns1", "ns2"}, 39 }, 40 want: `Kube - Namespaces: ["ns1" "ns2"]`, 41 }, 42 { 43 name: "Explicit Title Set", 44 fields: fields{ 45 namespaces: []string{}, 46 title: "Test Explicit Title", 47 }, 48 want: "Test Explicit Title", 49 }, 50 { 51 name: "Context set", 52 fields: fields{ 53 namespaces: []string{}, 54 context: "test-context", 55 }, 56 want: "Kube (test-context)", 57 }, 58 } 59 60 for _, tt := range testCases { 61 t.Run(tt.name, func(t *testing.T) { 62 widget := &Widget{ 63 title: tt.fields.title, 64 namespaces: tt.fields.namespaces, 65 context: tt.fields.context, 66 } 67 assert.Equal(t, tt.want, widget.generateTitle()) 68 }) 69 } 70 }