@@ -212,8 +212,6 @@ func TestValidateLabelValue(t *testing.T) {
212212
213213// TestValidateDomain tests that only correct DNS subdomain names are accepted
214214func TestValidateDomain (t * testing.T ) {
215- // TestValidateNamespace tests that only correct Kubernetes namespace names are accepted
216- func TestValidateNamespace (t * testing.T ) {
217215 cases := []struct {
218216 In string
219217 Valid bool
@@ -233,6 +231,7 @@ func TestValidateNamespace(t *testing.T) {
233231 {"example-app.com" , true }, // hyphen in domain
234232 {"a.co" , true }, // short domain
235233 {"123app.example.com" , true }, // label starting with number
234+
236235 // Invalid domains
237236 {"Example.Com" , false }, // uppercase not allowed
238237 {"MY-APP.COM" , false }, // uppercase not allowed
@@ -264,6 +263,45 @@ func TestValidateNamespace(t *testing.T) {
264263 }
265264 if err == nil && ! c .Valid {
266265 t .Fatalf ("Expected error for invalid domain: '%v'" , c .In )
266+ }
267+ }
268+ }
269+
270+ func TestValidateDomainErrMsg (t * testing.T ) {
271+ invalidDomain := "my@app.com"
272+ errMsgPrefix := fmt .Sprintf ("Domain '%v'" , invalidDomain )
273+
274+ err := ValidateDomain (invalidDomain )
275+ if err != nil {
276+ if ! strings .HasPrefix (err .Error (), errMsgPrefix ) {
277+ t .Fatalf ("Unexpected error message: %v, the message should start with '%v' string" , err .Error (), errMsgPrefix )
278+ }
279+ } else {
280+ t .Fatalf ("Expected error for invalid domain: %v" , invalidDomain )
281+ }
282+ }
283+
284+ // TestValidateDomainEmptyString ensures empty string is handled specially
285+ func TestValidateDomainEmptyString (t * testing.T ) {
286+ // Empty string should be valid (means use cluster default)
287+ err := ValidateDomain ("" )
288+ if err != nil {
289+ t .Fatalf ("Empty string should be valid (means use default): %v" , err )
290+ }
291+
292+ // String with only whitespace should error
293+ err = ValidateDomain (" " )
294+ if err == nil {
295+ t .Fatal ("String with only whitespace should be invalid" )
296+ }
297+ }
298+
299+ // TestValidateNamespace tests that only correct Kubernetes namespace names are accepted
300+ func TestValidateNamespace (t * testing.T ) {
301+ cases := []struct {
302+ In string
303+ Valid bool
304+ }{
267305 // Valid namespaces
268306 {"default" , true },
269307 {"kube-system" , true },
@@ -309,11 +347,6 @@ func TestValidateNamespace(t *testing.T) {
309347 }
310348}
311349
312- func TestValidateDomainErrMsg (t * testing.T ) {
313- invalidDomain := "my@app.com"
314- errMsgPrefix := fmt .Sprintf ("Domain '%v'" , invalidDomain )
315-
316- err := ValidateDomain (invalidDomain )
317350func TestValidateNamespaceErrMsg (t * testing.T ) {
318351 invalidNamespace := "my@app"
319352 errMsgPrefix := fmt .Sprintf ("Namespace '%v'" , invalidNamespace )
@@ -324,24 +357,6 @@ func TestValidateNamespaceErrMsg(t *testing.T) {
324357 t .Fatalf ("Unexpected error message: %v, the message should start with '%v' string" , err .Error (), errMsgPrefix )
325358 }
326359 } else {
327- t .Fatalf ("Expected error for invalid domain: %v" , invalidDomain )
328- }
329- }
330-
331- // TestValidateDomainEmptyString ensures empty string is handled specially
332- func TestValidateDomainEmptyString (t * testing.T ) {
333- // Empty string should be valid (means use cluster default)
334- err := ValidateDomain ("" )
335- if err != nil {
336- t .Fatalf ("Empty string should be valid (means use default): %v" , err )
337- }
338-
339- // String with only whitespace should error
340- err = ValidateDomain (" " )
341- if err == nil {
342- t .Fatal ("String with only whitespace should be invalid" )
343- }
344- }
345360 t .Fatalf ("Expected error for invalid namespace: %v" , invalidNamespace )
346361 }
347362}
0 commit comments