github.com/teknogeek/dnscontrol/v2@v2.10.1-0.20200227202244-ae299b55ba42/models/dns_test.go (about) 1 package models 2 3 import ( 4 "testing" 5 ) 6 7 func TestRR(t *testing.T) { 8 experiment := RecordConfig{ 9 Type: "A", 10 Name: "foo", 11 NameFQDN: "foo.example.com", 12 Target: "1.2.3.4", 13 TTL: 0, 14 MxPreference: 0, 15 } 16 expected := "foo.example.com.\t300\tIN\tA\t1.2.3.4" 17 found := experiment.ToRR().String() 18 if found != expected { 19 t.Errorf("RR expected (%#v) got (%#v)\n", expected, found) 20 } 21 22 experiment = RecordConfig{ 23 Type: "CAA", 24 Name: "@", 25 NameFQDN: "example.com", 26 Target: "mailto:test@example.com", 27 TTL: 300, 28 CaaTag: "iodef", 29 CaaFlag: 1, 30 } 31 expected = "example.com.\t300\tIN\tCAA\t1 iodef \"mailto:test@example.com\"" 32 found = experiment.ToRR().String() 33 if found != expected { 34 t.Errorf("RR expected (%#v) got (%#v)\n", expected, found) 35 } 36 37 experiment = RecordConfig{ 38 Type: "TLSA", 39 Name: "@", 40 NameFQDN: "_443._tcp.example.com", 41 Target: "abcdef0123456789", 42 TTL: 300, 43 TlsaUsage: 0, 44 TlsaSelector: 0, 45 TlsaMatchingType: 1, 46 } 47 expected = "_443._tcp.example.com.\t300\tIN\tTLSA\t0 0 1 abcdef0123456789" 48 found = experiment.ToRR().String() 49 if found != expected { 50 t.Errorf("RR expected (%#v) got (%#v)\n", expected, found) 51 } 52 } 53 54 func TestDowncase(t *testing.T) { 55 dc := DomainConfig{Records: Records{ 56 &RecordConfig{Type: "MX", Name: "lower", Target: "targetmx"}, 57 &RecordConfig{Type: "MX", Name: "UPPER", Target: "TARGETMX"}, 58 }} 59 downcase(dc.Records) 60 if !dc.Records.HasRecordTypeName("MX", "lower") { 61 t.Errorf("%v: expected (%v) got (%v)\n", dc.Records, false, true) 62 } 63 if !dc.Records.HasRecordTypeName("MX", "upper") { 64 t.Errorf("%v: expected (%v) got (%v)\n", dc.Records, false, true) 65 } 66 if dc.Records[0].GetTargetField() != "targetmx" { 67 t.Errorf("%v: target0 expected (%v) got (%v)\n", dc.Records, "targetmx", dc.Records[0].GetTargetField()) 68 } 69 if dc.Records[1].GetTargetField() != "targetmx" { 70 t.Errorf("%v: target1 expected (%v) got (%v)\n", dc.Records, "targetmx", dc.Records[1].GetTargetField()) 71 } 72 }