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

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
CecileRobertMichon committed Jun 15, 2018
1 parent 437b9f5 commit b152c50
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
49 changes: 49 additions & 0 deletions pkg/api/common/helper_test.go
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())
}
}
}
}
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: "DNS prefix 'bad!' is invalid. The DNS prefix 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. 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)",
},
{
masterProfile: MasterProfile{
Expand Down

0 comments on commit b152c50

Please sign in to comment.