coredns/test/server_test.go
Yong Tang 9dd288943a Move *proxy* to external (#2651)
* Move *proxy* to external

move the proxy plugin into coredns/proxy and remove it as a default
plugin. Link the proxy to deprecated in plugin.cfg

coredns/proxy doesn't compile because of the vendoring :(

Signed-off-by: Miek Gieben <miek@miek.nl>

* Add github.com/coredns/proxy

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2019-03-04 07:32:38 +00:00

55 lines
1.4 KiB
Go

package test
import (
"testing"
"github.com/miekg/dns"
)
// Start 2 tests server, server A will proxy to B, server B is an CH server.
func TestProxyToChaosServer(t *testing.T) {
t.Parallel()
corefile := `.:0 {
chaos CoreDNS-001 miek@miek.nl
}
`
chaos, udpChaos, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
defer chaos.Stop()
corefileProxy := `.:0 {
forward . ` + udpChaos + `
}
`
proxy, udp, _, err := CoreDNSServerAndPorts(corefileProxy)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance")
}
defer proxy.Stop()
chaosTest(t, udpChaos)
chaosTest(t, udp)
// chaosTest(t, tcp, "tcp"), commented out because we use the original transport to reach the
// proxy and we only forward to the udp port.
}
func chaosTest(t *testing.T, server string) {
m := new(dns.Msg)
m.Question = make([]dns.Question, 1)
m.Question[0] = dns.Question{Qclass: dns.ClassCHAOS, Name: "version.bind.", Qtype: dns.TypeTXT}
r, err := dns.Exchange(m, server)
if err != nil {
t.Fatalf("Could not send message: %s", err)
}
if r.Rcode != dns.RcodeSuccess || len(r.Answer) == 0 {
t.Fatalf("Expected successful reply, got %s", dns.RcodeToString[r.Rcode])
}
if r.Answer[0].String() != `version.bind. 0 CH TXT "CoreDNS-001"` {
t.Fatalf("Expected version.bind. reply, got %s", r.Answer[0].String())
}
}