diff options
author | 2017-04-13 16:25:16 +0100 | |
---|---|---|
committer | 2017-04-13 16:25:16 +0100 | |
commit | ef4fa66e670fabe5c4dcfecc319c0f99d02bfd07 (patch) | |
tree | dfb7cfcaddebfa48ef9ebec5c14b9d374ec50669 /test/file_srv_additional_test.go | |
parent | 7a79b819262ddcccb1ce6d13d96211fea1861c4a (diff) | |
download | coredns-ef4fa66e670fabe5c4dcfecc319c0f99d02bfd07.tar.gz coredns-ef4fa66e670fabe5c4dcfecc319c0f99d02bfd07.tar.zst coredns-ef4fa66e670fabe5c4dcfecc319c0f99d02bfd07.zip |
middleware/file: add test for SRV additional (#616)
Add test for checking the additional section after a SRV query. Though
this wasn't fixed, but it is.
Fixes #609
Diffstat (limited to 'test/file_srv_additional_test.go')
-rw-r--r-- | test/file_srv_additional_test.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/file_srv_additional_test.go b/test/file_srv_additional_test.go new file mode 100644 index 000000000..0fad80758 --- /dev/null +++ b/test/file_srv_additional_test.go @@ -0,0 +1,53 @@ +package test + +import ( + "io/ioutil" + "log" + "testing" + + "github.com/coredns/coredns/middleware/proxy" + "github.com/coredns/coredns/middleware/test" + "github.com/coredns/coredns/request" + + "github.com/miekg/dns" +) + +func TestZoneSRVAdditional(t *testing.T) { + t.Parallel() + log.SetOutput(ioutil.Discard) + + name, rm, err := TempFile(".", exampleOrg) + if err != nil { + t.Fatalf("Failed to create zone: %s", err) + } + defer rm() + + // Corefile with for example without proxy section. + corefile := `example.org:0 { + file ` + name + ` +} +` + i, err := CoreDNSServer(corefile) + if err != nil { + t.Fatalf("Could not get CoreDNS serving instance: %s", err) + } + + udp, _ := CoreDNSServerPorts(i, 0) + if udp == "" { + t.Fatalf("Could not get UDP listening port") + } + defer i.Stop() + + p := proxy.NewLookup([]string{udp}) + state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)} + + resp, err := p.Lookup(state, "service.example.org.", dns.TypeSRV) + if err != nil { + t.Fatalf("Expected to receive reply, but didn't: %s", err) + } + + // There should be 2 A records in the additional section. + if len(resp.Extra) != 2 { + t.Fatalf("Expected 2 RR in additional section got %d", len(resp.Extra)) + } +} |