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

Commit

Permalink
fix test logic
Browse files Browse the repository at this point in the history
  • Loading branch information
CecileRobertMichon committed Jun 15, 2018
1 parent f969733 commit 2c4a5d6
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions pkg/api/common/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ func TestValidateDNSPrefix(t *testing.T) {
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",
"a",
fmt.Errorf("DNSPrefix 'a' 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 1)"),
},
{
"1234",
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)"),
},
{
Expand All @@ -28,7 +32,7 @@ func TestValidateDNSPrefix(t *testing.T) {
},
{
"dnswith_special?char",
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)"),
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 20)"),
},
{
"myDNS-1234",
Expand All @@ -38,12 +42,16 @@ func TestValidateDNSPrefix(t *testing.T) {

for _, c := range cases {
err := ValidateDNSPrefix(c.dnsPrefix)
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())
if err != nil && c.expectedErr != nil {
if 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())
}
}
}
}

0 comments on commit 2c4a5d6

Please sign in to comment.