github.com/gofunct/common@v0.0.0-20190131174352-fd058c7fbf22/pkg/strings/strings_test.go (about) 1 package strings 2 3 import ( 4 "testing" 5 ) 6 7 func TestSplitQualifiedName(t *testing.T) { 8 testCases := []struct { 9 input string 10 output []string 11 }{ 12 {"kubernetes.io/blah", []string{"kubernetes.io", "blah"}}, 13 {"blah", []string{"", "blah"}}, 14 {"kubernetes.io/blah/blah", []string{"kubernetes.io", "blah"}}, 15 } 16 for i, tc := range testCases { 17 namespace, name := SplitQualifiedName(tc.input) 18 if namespace != tc.output[0] || name != tc.output[1] { 19 t.Errorf("case[%d]: expected (%q, %q), got (%q, %q)", i, tc.output[0], tc.output[1], namespace, name) 20 } 21 } 22 } 23 24 func TestJoinQualifiedName(t *testing.T) { 25 testCases := []struct { 26 input []string 27 output string 28 }{ 29 {[]string{"kubernetes.io", "blah"}, "kubernetes.io/blah"}, 30 {[]string{"blah", ""}, "blah"}, 31 {[]string{"kubernetes.io", "blah"}, "kubernetes.io/blah"}, 32 } 33 for i, tc := range testCases { 34 res := JoinQualifiedName(tc.input[0], tc.input[1]) 35 if res != tc.output { 36 t.Errorf("case[%d]: expected %q, got %q", i, tc.output, res) 37 } 38 } 39 } 40 41 func TestShortenString(t *testing.T) { 42 testCases := []struct { 43 input string 44 outLen int 45 output string 46 }{ 47 {"kubernetes.io", 5, "kuber"}, 48 {"blah", 34, "blah"}, 49 {"kubernetes.io", 13, "kubernetes.io"}, 50 } 51 for i, tc := range testCases { 52 res := ShortenString(tc.input, tc.outLen) 53 if res != tc.output { 54 t.Errorf("case[%d]: expected %q, got %q", i, tc.output, res) 55 } 56 } 57 }