Ready for CoreDNS testing
This commit is contained in:
parent
772469d21b
commit
b79df4bf1d
9 changed files with 290 additions and 124 deletions
151
yamlzone_test.go
151
yamlzone_test.go
|
|
@ -14,15 +14,15 @@ func assertOk(t *testing.T, ok bool) {
|
|||
}
|
||||
}
|
||||
|
||||
func assertNotOk(t *testing.T, ok bool, records []Record) {
|
||||
func assertNotOk(t *testing.T, ok bool, res LookupResult) {
|
||||
if ok {
|
||||
t.Fatalf("Expected not ok, got ok (%v)", records)
|
||||
t.Fatalf("Expected not ok, got ok (%v)", res)
|
||||
}
|
||||
}
|
||||
|
||||
func assertRecordCount(t *testing.T, records []Record, expected int) {
|
||||
if len(records) != expected {
|
||||
t.Fatalf("Expected %d records, got %d (%v)", expected, len(records), records)
|
||||
func assertRecordCount(t *testing.T, res LookupResult, expected int) {
|
||||
if len(res.Answer) != expected {
|
||||
t.Fatalf("Expected %d records, got %d (%v)", expected, len(res.Answer), res.Answer)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -65,25 +65,25 @@ func TestEmptyZone(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("Lookup empty string", func(t *testing.T) {
|
||||
records, ok := zEmpty.Lookup("")
|
||||
res, ok := zEmpty.Lookup("")
|
||||
assertOk(t, ok)
|
||||
assertRecordCount(t, records, 0)
|
||||
assertRecordCount(t, res, 0)
|
||||
})
|
||||
|
||||
t.Run("Lookup single dot", func(t *testing.T) {
|
||||
records, ok := zEmpty.Lookup(".")
|
||||
res, ok := zEmpty.Lookup(".")
|
||||
assertOk(t, ok)
|
||||
assertRecordCount(t, records, 0)
|
||||
assertRecordCount(t, res, 0)
|
||||
})
|
||||
|
||||
t.Run("Lookup example.com", func(t *testing.T) {
|
||||
records, ok := zEmpty.Lookup("example.com")
|
||||
assertNotOk(t, ok, records)
|
||||
res, ok := zEmpty.Lookup("example.com")
|
||||
assertNotOk(t, ok, res)
|
||||
})
|
||||
|
||||
t.Run("LookupType example.com A", func(t *testing.T) {
|
||||
records, ok := zEmpty.LookupType("example.com", "A")
|
||||
assertNotOk(t, ok, records)
|
||||
res, ok := zEmpty.LookupType("example.com", "A")
|
||||
assertNotOk(t, ok, res)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -104,23 +104,23 @@ func TestSimpleZone(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("Lookup", func(t *testing.T) {
|
||||
records, ok := zSimple.Lookup("")
|
||||
res, ok := zSimple.Lookup("")
|
||||
assertOk(t, ok)
|
||||
assertRecordCount(t, records, 4)
|
||||
assertRecord(t, records[0], "SOA", 0, "ns1.example.com. admin.example.com. 1 1 1 1 1")
|
||||
assertRecord(t, records[1], "A", 0, "192.0.2.100")
|
||||
assertRecord(t, records[2], "AAAA", 0, "2001:db8::100")
|
||||
assertRecord(t, records[3], "NS", 0, "ns1.example.com")
|
||||
assertRecordCount(t, res, 4)
|
||||
assertRecord(t, res.Answer[0].Record, "SOA", 0, "ns1.example.com. admin.example.com. 1 1 1 1 1")
|
||||
assertRecord(t, res.Answer[1].Record, "A", 0, "192.0.2.100")
|
||||
assertRecord(t, res.Answer[2].Record, "AAAA", 0, "2001:db8::100")
|
||||
assertRecord(t, res.Answer[3].Record, "NS", 0, "ns1.example.com")
|
||||
})
|
||||
|
||||
t.Run("LookupType", func(t *testing.T) {
|
||||
records, ok := zSimple.LookupType("", "A")
|
||||
res, ok := zSimple.LookupType("", "A")
|
||||
if !ok {
|
||||
t.Fatalf("Expected ok, got false")
|
||||
}
|
||||
|
||||
assertRecordCount(t, records, 1)
|
||||
assertRecord(t, records[0], "A", 0, "192.0.2.100")
|
||||
assertRecordCount(t, res, 1)
|
||||
assertRecord(t, res.Answer[0].Record, "A", 0, "192.0.2.100")
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -141,93 +141,93 @@ func TestFullZone(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("Lookup example.com", func(t *testing.T) {
|
||||
records, ok := zFull.Lookup("example.com")
|
||||
res, ok := zFull.Lookup("example.com")
|
||||
if !ok {
|
||||
t.Fatalf("Expected ok, got false")
|
||||
}
|
||||
|
||||
assertRecordCount(t, records, 8)
|
||||
assertRecord(t, records[0], "SOA", 0, "ns1.example.com. admin.example.com. 1 1 1 1 1")
|
||||
assertRecord(t, records[1], "A", 0, "192.0.2.1")
|
||||
assertRecord(t, records[2], "AAAA", 0, "2001:db8::1")
|
||||
assertRecord(t, records[3], "MX", 3600, "10 mail.example.com") // Default TTL
|
||||
assertRecord(t, records[4], "TXT", 300, "v=spf1 a mx include:mail.example.com ~all")
|
||||
assertRecord(t, records[5], "CAA", 86400, "0 issue \"letsencrypt.org\"")
|
||||
assertRecord(t, records[6], "TXT", 3600, "foo=bar")
|
||||
assertRecord(t, records[7], "NS", 0, "ns1.example.com")
|
||||
assertRecordCount(t, res, 8)
|
||||
assertRecord(t, res.Answer[0].Record, "SOA", 0, "ns1.example.com. admin.example.com. 1 1 1 1 1")
|
||||
assertRecord(t, res.Answer[1].Record, "A", 0, "192.0.2.1")
|
||||
assertRecord(t, res.Answer[2].Record, "AAAA", 0, "2001:db8::1")
|
||||
assertRecord(t, res.Answer[3].Record, "MX", 3600, "10 mail.example.com") // Default TTL
|
||||
assertRecord(t, res.Answer[4].Record, "TXT", 300, "v=spf1 a mx include:mail.example.com ~all")
|
||||
assertRecord(t, res.Answer[5].Record, "CAA", 86400, "0 issue \"letsencrypt.org\"")
|
||||
assertRecord(t, res.Answer[6].Record, "TXT", 3600, "foo=bar")
|
||||
assertRecord(t, res.Answer[7].Record, "NS", 0, "ns1.example.com")
|
||||
|
||||
})
|
||||
|
||||
t.Run("LookupType example.com TXT", func(t *testing.T) {
|
||||
records, ok := zFull.LookupType("example.com", "TXT")
|
||||
res, ok := zFull.LookupType("example.com", "TXT")
|
||||
assertOk(t, ok)
|
||||
assertRecordCount(t, records, 2)
|
||||
assertRecord(t, records[0], "TXT", 300, "v=spf1 a mx include:mail.example.com ~all")
|
||||
assertRecord(t, records[1], "TXT", 3600, "foo=bar")
|
||||
assertRecordCount(t, res, 2)
|
||||
assertRecord(t, res.Answer[0].Record, "TXT", 300, "v=spf1 a mx include:mail.example.com ~all")
|
||||
assertRecord(t, res.Answer[1].Record, "TXT", 3600, "foo=bar")
|
||||
})
|
||||
|
||||
t.Run("Lookup www.example.com", func(t *testing.T) {
|
||||
records, ok := zFull.Lookup("www.example.com")
|
||||
res, ok := zFull.Lookup("www.example.com")
|
||||
assertOk(t, ok)
|
||||
assertRecordCount(t, records, 1)
|
||||
assertRecord(t, records[0], "CNAME", 3600, "example.com")
|
||||
assertRecordCount(t, res, 1)
|
||||
assertRecord(t, res.Answer[0].Record, "CNAME", 3600, "example.com")
|
||||
|
||||
})
|
||||
|
||||
t.Run("LookupType www.example.com CNAME", func(t *testing.T) {
|
||||
records, ok := zFull.LookupType("www.example.com", "CNAME")
|
||||
res, ok := zFull.LookupType("www.example.com", "CNAME")
|
||||
assertOk(t, ok)
|
||||
assertRecordCount(t, records, 1)
|
||||
assertRecord(t, records[0], "CNAME", 3600, "example.com")
|
||||
assertRecordCount(t, res, 1)
|
||||
assertRecord(t, res.Answer[0].Record, "CNAME", 3600, "example.com")
|
||||
})
|
||||
|
||||
t.Run("Lookup www.example.com TXT", func(t *testing.T) {
|
||||
records, ok := zFull.LookupType("www.example.com", "TXT")
|
||||
res, ok := zFull.LookupType("www.example.com", "TXT")
|
||||
assertOk(t, ok)
|
||||
assertRecordCount(t, records, 0)
|
||||
assertRecordCount(t, res, 0)
|
||||
})
|
||||
|
||||
t.Run("Lookup status.example.com", func(t *testing.T) {
|
||||
records, ok := zFull.Lookup("status.example.com")
|
||||
res, ok := zFull.Lookup("status.example.com")
|
||||
assertOk(t, ok)
|
||||
assertRecordCount(t, records, 2)
|
||||
assertRecord(t, records[0], "A", 3600, "198.51.100.24")
|
||||
assertRecord(t, records[1], "A", 3600, "203.0.113.24")
|
||||
assertRecordCount(t, res, 2)
|
||||
assertRecord(t, res.Answer[0].Record, "A", 3600, "198.51.100.24")
|
||||
assertRecord(t, res.Answer[1].Record, "A", 3600, "203.0.113.24")
|
||||
})
|
||||
|
||||
t.Run("Lookup partner.example.com", func(t *testing.T) {
|
||||
records, ok := zFull.Lookup("partner.example.com")
|
||||
res, ok := zFull.Lookup("partner.example.com")
|
||||
assertOk(t, ok)
|
||||
assertRecordCount(t, records, 2)
|
||||
assertRecord(t, records[0], "NS", 3600, "ns1.example.org")
|
||||
assertRecord(t, records[1], "NS", 3600, "ns2.example.org")
|
||||
assertRecordCount(t, res, 2)
|
||||
assertRecord(t, res.Answer[0].Record, "NS", 3600, "ns1.example.org")
|
||||
assertRecord(t, res.Answer[1].Record, "NS", 3600, "ns2.example.org")
|
||||
})
|
||||
|
||||
t.Run("Lookup unused.example.com", func(t *testing.T) {
|
||||
records, ok := zFull.Lookup("unused.example.com")
|
||||
res, ok := zFull.Lookup("unused.example.com")
|
||||
assertOk(t, ok)
|
||||
assertRecordCount(t, records, 0)
|
||||
assertRecordCount(t, res, 0)
|
||||
})
|
||||
|
||||
t.Run("Lookup ftp.internal.example.com", func(t *testing.T) {
|
||||
records, ok := zFull.Lookup("ftp.internal.example.com")
|
||||
res, ok := zFull.Lookup("ftp.internal.example.com")
|
||||
assertOk(t, ok)
|
||||
assertRecordCount(t, records, 1)
|
||||
assertRecord(t, records[0], "A", 3600, "10.0.0.2")
|
||||
assertRecordCount(t, res, 1)
|
||||
assertRecord(t, res.Answer[0].Record, "A", 3600, "10.0.0.2")
|
||||
})
|
||||
|
||||
t.Run("Lookup _xmpp-server._tcp.example.com", func(t *testing.T) {
|
||||
records, ok := zFull.Lookup("_xmpp-server._tcp.example.com")
|
||||
res, ok := zFull.Lookup("_xmpp-server._tcp.example.com")
|
||||
assertOk(t, ok)
|
||||
assertRecordCount(t, records, 1)
|
||||
assertRecord(t, records[0], "SRV", 3600, "10 0 5269 example.com")
|
||||
assertRecordCount(t, res, 1)
|
||||
assertRecord(t, res.Answer[0].Record, "SRV", 3600, "10 0 5269 example.com")
|
||||
})
|
||||
|
||||
t.Run("Lookup multilayer.nested.folders.example.com", func(t *testing.T) {
|
||||
records, ok := zFull.Lookup("multilayer.nested.folders.example.com")
|
||||
res, ok := zFull.Lookup("multilayer.nested.folders.example.com")
|
||||
assertOk(t, ok)
|
||||
assertRecordCount(t, records, 1)
|
||||
assertRecord(t, records[0], "A", 3600, "192.0.2.1")
|
||||
assertRecordCount(t, res, 1)
|
||||
assertRecord(t, res.Answer[0].Record, "A", 3600, "192.0.2.1")
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -238,6 +238,11 @@ func TestBadZones(t *testing.T) {
|
|||
errorSubstring string
|
||||
}
|
||||
var badZones = []badZone{
|
||||
{
|
||||
name: "CnameWithOther",
|
||||
filename: "testdata/bad_cname_with_other.yaml",
|
||||
errorSubstring: "extraneous records found next to CNAME",
|
||||
},
|
||||
{
|
||||
name: "NonexistentFile",
|
||||
filename: "testdata/bad_nonexistent.yaml",
|
||||
|
|
@ -303,6 +308,26 @@ func TestBadZones(t *testing.T) {
|
|||
filename: "testdata/bad_missing_ns.yaml",
|
||||
errorSubstring: "zone apex missing NS records",
|
||||
},
|
||||
{
|
||||
name: "NsWithOther",
|
||||
filename: "testdata/bad_ns_with_other.yaml",
|
||||
errorSubstring: "non-glue, non-NS records found at delegation point",
|
||||
},
|
||||
{
|
||||
name: "NsWithSubzone",
|
||||
filename: "testdata/bad_ns_with_subzone.yaml",
|
||||
errorSubstring: "non-glue records found under delegation point",
|
||||
},
|
||||
{
|
||||
name: "GlueWithOther",
|
||||
filename: "testdata/bad_glue_with_other.yaml",
|
||||
errorSubstring: "non-glue record found under delegation point",
|
||||
},
|
||||
{
|
||||
name: "CnameWithOther",
|
||||
filename: "testdata/bad_cname_with_other.yaml",
|
||||
errorSubstring: "extraneous records found next to CNAME",
|
||||
},
|
||||
}
|
||||
|
||||
for _, badZone := range badZones {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue