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