This repository was archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
CecileRobertMichon
committed
Jun 15, 2018
1 parent
437b9f5
commit b152c50
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestValidateDNSPrefix(t *testing.T) { | ||
cases := []struct { | ||
dnsPrefix string | ||
expectedErr error | ||
}{ | ||
{ | ||
"validDnsPrefix", | ||
nil, | ||
}, | ||
{ | ||
"", | ||
fmt.Errorf("DNSPrefix '' is invalid. The DNSPrefix must contain between 3 and 45 characters. The name can contain only letters, numbers, and hyphens. The name must start with a letter and must end with a letter or a number. (length was 0)"), | ||
}, | ||
{ | ||
"1232", | ||
fmt.Errorf("DNSPrefix '1234' is invalid. The DNSPrefix must contain between 3 and 45 characters. The name can contain only letters, numbers, and hyphens. The name must start with a letter and must end with a letter or a number. (length was 4)"), | ||
}, | ||
{ | ||
"verylongdnsprefixthatismorethan45characterslong", | ||
fmt.Errorf("DNSPrefix 'verylongdnsprefixthatismorethan45characterslong' is invalid. The DNSPrefix must contain between 3 and 45 characters. The name can contain only letters, numbers, and hyphens. The name must start with a letter and must end with a letter or a number. (length was 47)"), | ||
}, | ||
{ | ||
"dnswith_special?char", | ||
fmt.Errorf("DNSPrefix 'dnswith_special?char' is invalid. The DNSPrefix must contain between 3 and 45 characters. The name can contain only letters, numbers, and hyphens. The name must start with a letter and must end with a letter or a number. (length was 15)"), | ||
}, | ||
{ | ||
"myDNS-1234", | ||
nil, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
err := ValidateDNSPrefix(c.dnsPrefix) | ||
if err != c.expectedErr { | ||
if c.expectedErr != nil { | ||
t.Fatalf("expected validateDNSPrefix to return error %s, but instead got %s", c.expectedErr.Error(), err.Error()) | ||
} else { | ||
t.Fatalf("expected validateDNSPrefix to return no error, but instead got %s", err.Error()) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters