diff options
Diffstat (limited to 'test/proxy_test.go')
-rw-r--r-- | test/proxy_test.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/proxy_test.go b/test/proxy_test.go index cb9f1b298..7e85a0c87 100644 --- a/test/proxy_test.go +++ b/test/proxy_test.go @@ -56,6 +56,50 @@ func TestLookupProxy(t *testing.T) { } } +func TestLookupDnsWithForcedTcp(t *testing.T) { + t.Parallel() + name, rm, err := test.TempFile(".", exampleOrg) + if err != nil { + t.Fatalf("failed to create zone: %s", err) + } + defer rm() + + corefile := `example.org:0 { + file ` + name + ` +} +` + + i, err := CoreDNSServer(corefile) + if err != nil { + t.Fatalf("Could not get CoreDNS serving instance: %s", err) + } + + _, tcp := CoreDNSServerPorts(i, 0) + if tcp == "" { + t.Fatalf("Could not get TCP listening port") + } + defer i.Stop() + + log.SetOutput(ioutil.Discard) + + p := proxy.NewLookupWithOption([]string{tcp}, proxy.Options{ForceTCP: true}) + state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)} + resp, err := p.Lookup(state, "example.org.", dns.TypeA) + if err != nil { + t.Fatal("Expected to receive reply, but didn't") + } + // expect answer section with A record in it + if len(resp.Answer) == 0 { + t.Fatalf("Expected to at least one RR in the answer section, got none: %s", resp) + } + if resp.Answer[0].Header().Rrtype != dns.TypeA { + t.Errorf("Expected RR to A, got: %d", resp.Answer[0].Header().Rrtype) + } + if resp.Answer[0].(*dns.A).A.String() != "127.0.0.1" { + t.Errorf("Expected 127.0.0.1, got: %s", resp.Answer[0].(*dns.A).A.String()) + } +} + func BenchmarkLookupProxy(b *testing.B) { t := new(testing.T) name, rm, err := test.TempFile(".", exampleOrg) |