github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/cloudflare/validators_test.go (about)

     1  package cloudflare
     2  
     3  import "testing"
     4  
     5  func TestValidateRecordType(t *testing.T) {
     6  	validTypes := []string{
     7  		"A",
     8  		"AAAA",
     9  		"CNAME",
    10  		"TXT",
    11  		"SRV",
    12  		"LOC",
    13  		"MX",
    14  		"NS",
    15  		"SPF",
    16  	}
    17  	for _, v := range validTypes {
    18  		_, errors := validateRecordType(v, "type")
    19  		if len(errors) != 0 {
    20  			t.Fatalf("%q should be a valid record type: %q", v, errors)
    21  		}
    22  	}
    23  
    24  	invalidTypes := []string{
    25  		"a",
    26  		"cName",
    27  		"txt",
    28  		"SRv",
    29  		"foo",
    30  		"bar",
    31  	}
    32  	for _, v := range invalidTypes {
    33  		_, errors := validateRecordType(v, "type")
    34  		if len(errors) == 0 {
    35  			t.Fatalf("%q should be an invalid record type", v)
    36  		}
    37  	}
    38  }
    39  
    40  func TestValidateRecordName(t *testing.T) {
    41  	validNames := map[string]string{
    42  		"A":    "192.168.0.1",
    43  		"AAAA": "2001:0db8:0000:0042:0000:8a2e:0370:7334",
    44  	}
    45  
    46  	for k, v := range validNames {
    47  		if err := validateRecordName(k, v); err != nil {
    48  			t.Fatalf("%q should be a valid name for type %q: %v", v, k, err)
    49  		}
    50  	}
    51  
    52  	invalidNames := map[string]string{
    53  		"A":    "terraform.io",
    54  		"AAAA": "192.168.0.1",
    55  	}
    56  	for k, v := range invalidNames {
    57  		if err := validateRecordName(k, v); err == nil {
    58  			t.Fatalf("%q should be an invalid name for type %q", v, k)
    59  		}
    60  	}
    61  }