@@ -74,18 +74,41 @@ func Test_sanitizeClusterName(t *testing.T) {
74
74
name string
75
75
args args
76
76
want string
77
+ wantErr bool
77
78
}{
78
79
{
79
80
name : "should return sanitized string" ,
80
81
args : args {
81
- name : "^-.test !@-:cluster&*`;')test.cluster(-12_3=+::±§." ,
82
+ name : "^-.Test !@-:cluster&*`;')test.cluster(-12_3=+::±§." ,
82
83
},
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 ,
84
102
},
85
103
}
86
104
for _ , tt := range tests {
87
105
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 {
89
112
t .Errorf ("sanitizeClusterName() = %v, want %v" , got , tt .want )
90
113
}
91
114
})
@@ -104,35 +127,35 @@ func Test_validateClusterName(t *testing.T) {
104
127
{
105
128
name : "name should be valid" ,
106
129
args : args {
107
- name : "1test -cluster.test.cluster123z " ,
130
+ name : "test -cluster-123 " ,
108
131
},
109
132
wantErr : false ,
110
133
},
111
134
{
112
- name : "name should not be valid" ,
135
+ name : "name should not be valid (contains uppercase) " ,
113
136
args : args {
114
- name : ".test -cluster" ,
137
+ name : "Test -cluster" ,
115
138
},
116
139
wantErr : true ,
117
140
},
118
141
{
119
- name : "name should not be valid" ,
142
+ name : "name should not be valid (contains invalid chars) " ,
120
143
args : args {
121
- name : "test-cluster. " ,
144
+ name : "test-cluster:test/cluster.123# " ,
122
145
},
123
146
wantErr : true ,
124
147
},
125
148
{
126
- name : "name should not be valid" ,
149
+ name : "name should not be valid (begins with numeric char) " ,
127
150
args : args {
128
- name : "Test -cluster" ,
151
+ name : "2test -cluster" ,
129
152
},
130
153
wantErr : true ,
131
154
},
132
155
{
133
- name : "name should not be valid" ,
156
+ name : "name should not be valid (too long) " ,
134
157
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 " ,
136
159
},
137
160
wantErr : true ,
138
161
},
0 commit comments