github.com/pmoroney/dnscontrol@v0.2.4-0.20171024134423-fad98f73f44a/models/dns_test.go (about)

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