github.com/cilium/cilium@v1.16.2/pkg/hubble/k8s/utils_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Hubble 3 4 package k8s 5 6 import ( 7 "testing" 8 ) 9 10 func TestParseNamespaceName(t *testing.T) { 11 type args struct { 12 namespaceName string 13 } 14 tests := []struct { 15 name string 16 args args 17 wantNS string 18 wantName string 19 }{ 20 { 21 args: args{ 22 namespaceName: "default/pod-1", 23 }, 24 wantNS: "default", 25 wantName: "pod-1", 26 }, 27 { 28 args: args{ 29 namespaceName: "default/", 30 }, 31 wantNS: "default", 32 wantName: "", 33 }, 34 { 35 args: args{ 36 namespaceName: "pod-1", 37 }, 38 wantNS: "default", 39 wantName: "pod-1", 40 }, 41 { 42 args: args{ 43 namespaceName: "", 44 }, 45 wantNS: "", 46 wantName: "", 47 }, 48 } 49 for _, tt := range tests { 50 t.Run(tt.name, func(t *testing.T) { 51 gotNS, gotPod := ParseNamespaceName(tt.args.namespaceName) 52 if gotNS != tt.wantNS { 53 t.Errorf("ParseNamespaceName() gotNS = %v, wantNS %v", gotNS, tt.wantNS) 54 } 55 if gotPod != tt.wantName { 56 t.Errorf("ParseNamespaceName() gotPod = %v, wantName %v", gotPod, tt.wantName) 57 } 58 }) 59 } 60 }