@@ -74,18 +74,41 @@ func Test_sanitizeClusterName(t *testing.T) {
7474 name string
7575 args args
7676 want string
77+ wantErr bool
7778 }{
7879 {
7980 name : "should return sanitized string" ,
8081 args : args {
81- name : "^-.test !@-:cluster&*`;')test.cluster(-12_3=+::±§." ,
82+ name : "^-.Test !@-:cluster&*`;')test.cluster(-12_3=+::±§." ,
8283 },
83- want : "test----cluster------test.cluster--12-3" ,
84+ want : "test----cluster------test-cluster--12-3" ,
85+ wantErr : false ,
86+ },
87+ {
88+ name : "should return sanitized string" ,
89+ args : args {
90+ name : "^-.123test!@-:cluster&*`;')test.cluster(-12_3=+::±§." ,
91+ },
92+ want : "test----cluster------test-cluster--12-3" ,
93+ wantErr : false ,
94+ },
95+ {
96+ name : "should return error of sanitization failed" ,
97+ args : args {
98+ name : "12345" ,
99+ },
100+ want : "" ,
101+ wantErr : true ,
84102 },
85103 }
86104 for _ , tt := range tests {
87105 t .Run (tt .name , func (t * testing.T ) {
88- if got := sanitizeClusterName (tt .args .name ); got != tt .want {
106+ got , err := sanitizeClusterName (tt .args .name )
107+
108+ if (err != nil ) != tt .wantErr {
109+ t .Errorf ("sanitizeClusterName() error = %v, wantErr %v" , err , tt .wantErr )
110+ }
111+ if got != tt .want {
89112 t .Errorf ("sanitizeClusterName() = %v, want %v" , got , tt .want )
90113 }
91114 })
@@ -104,35 +127,35 @@ func Test_validateClusterName(t *testing.T) {
104127 {
105128 name : "name should be valid" ,
106129 args : args {
107- name : "1test -cluster.test.cluster123z " ,
130+ name : "test -cluster-123 " ,
108131 },
109132 wantErr : false ,
110133 },
111134 {
112- name : "name should not be valid" ,
135+ name : "name should not be valid (contains uppercase) " ,
113136 args : args {
114- name : ".test -cluster" ,
137+ name : "Test -cluster" ,
115138 },
116139 wantErr : true ,
117140 },
118141 {
119- name : "name should not be valid" ,
142+ name : "name should not be valid (contains invalid chars) " ,
120143 args : args {
121- name : "test-cluster. " ,
144+ name : "test-cluster:test/cluster.123# " ,
122145 },
123146 wantErr : true ,
124147 },
125148 {
126- name : "name should not be valid" ,
149+ name : "name should not be valid (begins with numeric char) " ,
127150 args : args {
128- name : "Test -cluster" ,
151+ name : "2test -cluster" ,
129152 },
130153 wantErr : true ,
131154 },
132155 {
133- name : "name should not be valid" ,
156+ name : "name should not be valid (too long) " ,
134157 args : args {
135- name : "test -cluster:test/ cluster" ,
158+ name : "this -cluster-name-is-too-long-1-this- cluster-name-is-too-long-1-this-cluster-name-is-too-long-1-123 " ,
136159 },
137160 wantErr : true ,
138161 },
0 commit comments