github.com/telepresenceio/telepresence/v2@v2.20.0-pro.6.0.20240517030216-236ea954e789/pkg/client/cli/daemon/identifier_test.go (about) 1 package daemon_test 2 3 import ( 4 "testing" 5 6 "github.com/telepresenceio/telepresence/v2/pkg/client/cli/daemon" 7 "github.com/telepresenceio/telepresence/v2/pkg/ioutil" 8 ) 9 10 func TestDaemonInfoFileName(t *testing.T) { 11 tests := []struct { 12 name string 13 namespace string 14 result string 15 }{ 16 {name: "the-cure", namespace: "ns1", result: "the-cure-ns1.json"}, 17 {name: "arn:aws:eks:us-east-2:914373874199:cluster/test-auth", namespace: "ns1", result: "arn_aws_eks_us-east-2_914373874199_cluster_test-auth-ns1.json"}, 18 {name: "gke_datawireio_us-central1-b_kube-staging-apps-1", namespace: "ns1", result: "gke_datawireio_us-central1-b_kube-staging-apps-1-ns1.json"}, 19 } 20 for _, test := range tests { 21 di, err := daemon.NewIdentifier("", test.name, test.namespace, false) 22 if err != nil { 23 t.Fatal(err) 24 } 25 result := di.InfoFileName() 26 if result != test.result { 27 t.Fatalf("DaemonInfoFile gave bad output; expected %s got %s", test.result, result) 28 } 29 } 30 } 31 32 func TestSafeContainerName(t *testing.T) { 33 tests := []struct { 34 name string 35 want string 36 }{ 37 { 38 "@", 39 "a", 40 }, 41 { 42 "@x", 43 "ax", 44 }, 45 { 46 "x@", 47 "x_", 48 }, 49 { 50 "x@y", 51 "x_y", 52 }, 53 { 54 "x™y", // multibyte char 55 "x_y", 56 }, 57 { 58 "x™", // multibyte char 59 "x_", 60 }, 61 { 62 "_y", 63 "ay", 64 }, 65 { 66 "_y_", 67 "ay_", 68 }, 69 // TODO: Add test cases. 70 } 71 for _, tt := range tests { 72 t.Run(tt.name, func(t *testing.T) { 73 if got := ioutil.SafeName(tt.name); got != tt.want { 74 t.Errorf("SafeName() = %v, want %v", got, tt.want) 75 } 76 }) 77 } 78 }