1
16
17 package strings
18
19 import (
20 "testing"
21 )
22
23 func TestSplitQualifiedName(t *testing.T) {
24 testCases := []struct {
25 input string
26 output []string
27 }{
28 {"kubernetes.io/blah", []string{"kubernetes.io", "blah"}},
29 {"blah", []string{"", "blah"}},
30 {"kubernetes.io/blah/blah", []string{"kubernetes.io", "blah"}},
31 }
32 for i, tc := range testCases {
33 namespace, name := SplitQualifiedName(tc.input)
34 if namespace != tc.output[0] || name != tc.output[1] {
35 t.Errorf("case[%d]: expected (%q, %q), got (%q, %q)", i, tc.output[0], tc.output[1], namespace, name)
36 }
37 }
38 }
39
40 func TestJoinQualifiedName(t *testing.T) {
41 testCases := []struct {
42 input []string
43 output string
44 }{
45 {[]string{"kubernetes.io", "blah"}, "kubernetes.io/blah"},
46 {[]string{"blah", ""}, "blah"},
47 {[]string{"kubernetes.io", "blah"}, "kubernetes.io/blah"},
48 }
49 for i, tc := range testCases {
50 res := JoinQualifiedName(tc.input[0], tc.input[1])
51 if res != tc.output {
52 t.Errorf("case[%d]: expected %q, got %q", i, tc.output, res)
53 }
54 }
55 }
56
57 func TestShortenString(t *testing.T) {
58 testCases := []struct {
59 input string
60 outLen int
61 output string
62 }{
63 {"kubernetes.io", 5, "kuber"},
64 {"blah", 34, "blah"},
65 {"kubernetes.io", 13, "kubernetes.io"},
66 }
67 for i, tc := range testCases {
68 res := ShortenString(tc.input, tc.outLen)
69 if res != tc.output {
70 t.Errorf("case[%d]: expected %q, got %q", i, tc.output, res)
71 }
72 }
73 }
74
View as plain text