github.com/teknogeek/dnscontrol/v2@v2.10.1-0.20200227202244-ae299b55ba42/models/record_test.go (about)

     1  package models
     2  
     3  import "testing"
     4  
     5  func TestHasRecordTypeName(t *testing.T) {
     6  	x := &RecordConfig{
     7  		Type: "A",
     8  		Name: "@",
     9  	}
    10  	recs := Records{}
    11  	if recs.HasRecordTypeName("A", "@") {
    12  		t.Errorf("%v: expected (%v) got (%v)\n", recs, false, true)
    13  	}
    14  	recs = append(recs, x)
    15  	if !recs.HasRecordTypeName("A", "@") {
    16  		t.Errorf("%v: expected (%v) got (%v)\n", recs, true, false)
    17  	}
    18  	if recs.HasRecordTypeName("AAAA", "@") {
    19  		t.Errorf("%v: expected (%v) got (%v)\n", recs, false, true)
    20  	}
    21  }
    22  
    23  func TestKey(t *testing.T) {
    24  	var tests = []struct {
    25  		rc       RecordConfig
    26  		expected RecordKey
    27  	}{
    28  		{
    29  			RecordConfig{Type: "A", NameFQDN: "example.com"},
    30  			RecordKey{Type: "A", NameFQDN: "example.com"},
    31  		},
    32  		{
    33  			RecordConfig{Type: "R53_ALIAS", NameFQDN: "example.com"},
    34  			RecordKey{Type: "R53_ALIAS", NameFQDN: "example.com"},
    35  		},
    36  		{
    37  			RecordConfig{Type: "R53_ALIAS", NameFQDN: "example.com", R53Alias: map[string]string{"foo": "bar"}},
    38  			RecordKey{Type: "R53_ALIAS", NameFQDN: "example.com"},
    39  		},
    40  		{
    41  			RecordConfig{Type: "R53_ALIAS", NameFQDN: "example.com", R53Alias: map[string]string{"type": "AAAA"}},
    42  			RecordKey{Type: "R53_ALIAS_AAAA", NameFQDN: "example.com"},
    43  		},
    44  	}
    45  	for i, test := range tests {
    46  		actual := test.rc.Key()
    47  		if test.expected != actual {
    48  			t.Errorf("%d: Expected %s, got %s", i, test.expected, actual)
    49  		}
    50  	}
    51  }