2016-08-22 18:31:50 -06:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHasRecordTypeName(t *testing.T) {
|
|
|
|
x := &RecordConfig{
|
|
|
|
Type: "A",
|
|
|
|
Name: "@",
|
|
|
|
}
|
|
|
|
dc := DomainConfig{}
|
|
|
|
if dc.HasRecordTypeName("A", "@") {
|
|
|
|
t.Errorf("%v: expected (%v) got (%v)\n", dc.Records, false, true)
|
|
|
|
}
|
|
|
|
dc.Records = append(dc.Records, x)
|
|
|
|
if !dc.HasRecordTypeName("A", "@") {
|
|
|
|
t.Errorf("%v: expected (%v) got (%v)\n", dc.Records, true, false)
|
|
|
|
}
|
|
|
|
if dc.HasRecordTypeName("AAAA", "@") {
|
|
|
|
t.Errorf("%v: expected (%v) got (%v)\n", dc.Records, false, true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRR(t *testing.T) {
|
|
|
|
experiment := RecordConfig{
|
2017-07-19 15:53:40 -04:00
|
|
|
Type: "A",
|
|
|
|
Name: "foo",
|
|
|
|
Target: "1.2.3.4",
|
|
|
|
TTL: 0,
|
|
|
|
NameFQDN: "foo.example.com",
|
|
|
|
MxPreference: 0,
|
2016-08-22 18:31:50 -06:00
|
|
|
}
|
|
|
|
expected := "foo.example.com.\t300\tIN\tA\t1.2.3.4"
|
2017-06-17 11:00:12 -04:00
|
|
|
found := experiment.ToRR().String()
|
2016-08-22 18:31:50 -06:00
|
|
|
if found != expected {
|
|
|
|
t.Errorf("RR expected (%#v) got (%#v)\n", expected, found)
|
|
|
|
}
|
2017-07-25 14:59:40 -04:00
|
|
|
|
|
|
|
experiment = RecordConfig{
|
|
|
|
Type: "CAA",
|
|
|
|
Name: "@",
|
|
|
|
Target: "mailto:test@example.com",
|
|
|
|
TTL: 300,
|
|
|
|
NameFQDN: "example.com",
|
|
|
|
CaaTag: "iodef",
|
2017-08-01 09:18:47 -04:00
|
|
|
CaaFlag: 1,
|
2017-07-25 14:59:40 -04:00
|
|
|
}
|
|
|
|
expected = "example.com.\t300\tIN\tCAA\t1 iodef \"mailto:test@example.com\""
|
|
|
|
found = experiment.ToRR().String()
|
|
|
|
if found != expected {
|
|
|
|
t.Errorf("RR expected (%#v) got (%#v)\n", expected, found)
|
|
|
|
}
|
2017-09-15 09:03:29 -04:00
|
|
|
|
|
|
|
experiment = RecordConfig{
|
|
|
|
Type: "TLSA",
|
|
|
|
Name: "@",
|
|
|
|
Target: "abcdef0123456789",
|
|
|
|
TTL: 300,
|
|
|
|
NameFQDN: "_443._tcp.example.com",
|
|
|
|
TlsaUsage: 0,
|
|
|
|
TlsaSelector: 0,
|
|
|
|
TlsaMatchingType: 1,
|
|
|
|
}
|
|
|
|
expected = "_443._tcp.example.com.\t300\tIN\tTLSA\t0 0 1 abcdef0123456789"
|
|
|
|
found = experiment.ToRR().String()
|
|
|
|
if found != expected {
|
|
|
|
t.Errorf("RR expected (%#v) got (%#v)\n", expected, found)
|
|
|
|
}
|
2016-08-22 18:31:50 -06:00
|
|
|
}
|