Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
add more unit test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
CecileRobertMichon committed Jun 15, 2018
1 parent b152c50 commit f969733
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pkg/api/common/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func ValidateDNSPrefix(dnsName string) error {
return err
}
if !re.MatchString(dnsName) {
return fmt.Errorf("DNSPrefix '%s' 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 %d)", dnsName, len(dnsName))
return fmt.Errorf("DNSPrefix '%s' is invalid. The DNSPrefix must contain between 3 and 45 characters and can contain only letters, numbers, and hyphens. It must start with a letter and must end with a letter or a number. (length was %d)", dnsName, len(dnsName))
}
return nil
}
20 changes: 10 additions & 10 deletions pkg/api/common/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ func TestValidateDNSPrefix(t *testing.T) {
},
{
"",
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)"),
fmt.Errorf("DNSPrefix '' is invalid. The DNSPrefix must contain between 3 and 45 characters and can contain only letters, numbers, and hyphens. It 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)"),
fmt.Errorf("DNSPrefix '1234' is invalid. The DNSPrefix must contain between 3 and 45 characters and can contain only letters, numbers, and hyphens. It 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)"),
fmt.Errorf("DNSPrefix 'verylongdnsprefixthatismorethan45characterslong' is invalid. The DNSPrefix must contain between 3 and 45 characters and can contain only letters, numbers, and hyphens. It 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)"),
fmt.Errorf("DNSPrefix 'dnswith_special?char' is invalid. The DNSPrefix must contain between 3 and 45 characters and can contain only letters, numbers, and hyphens. It must start with a letter and must end with a letter or a number. (length was 15)"),
},
{
"myDNS-1234",
Expand All @@ -38,12 +38,12 @@ func TestValidateDNSPrefix(t *testing.T) {

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())
}
if err != nil && c.expectedErr != nil && err.Error() != c.expectedErr.Error() {
t.Fatalf("expected validateDNSPrefix to return error %s, but instead got %s", c.expectedErr.Error(), err.Error())
} else if c.expectedErr != nil {
t.Fatalf("expected validateDNSPrefix to return error %s, but instead got no error", c.expectedErr.Error())
} else if err != nil {
t.Fatalf("expected validateDNSPrefix to return no error, but instead got %s", err.Error())
}
}
}
2 changes: 1 addition & 1 deletion pkg/api/vlabs/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ func TestMasterProfileValidate(t *testing.T) {
masterProfile: MasterProfile{
DNSPrefix: "bad!",
},
expectedErr: "DNSPrefix 'bad!' 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)",
expectedErr: "DNSPrefix 'bad!' is invalid. The DNSPrefix must contain between 3 and 45 characters and can contain only letters, numbers, and hyphens. It must start with a letter and must end with a letter or a number. (length was 4)",
},
{
masterProfile: MasterProfile{
Expand Down

0 comments on commit f969733

Please sign in to comment.