From 2c4a5d6543f16346405d50d10530cefaad096bb7 Mon Sep 17 00:00:00 2001 From: CecileRobertMichon Date: Fri, 15 Jun 2018 10:18:30 -0700 Subject: [PATCH] fix test logic --- pkg/api/common/helper_test.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/pkg/api/common/helper_test.go b/pkg/api/common/helper_test.go index 3b2c704da5..081b84af69 100644 --- a/pkg/api/common/helper_test.go +++ b/pkg/api/common/helper_test.go @@ -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)"), }, { @@ -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", @@ -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()) + } } } }