aboutsummaryrefslogtreecommitdiff
path: root/test/server_test.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2016-04-10 18:50:11 +0100
committerGravatar Miek Gieben <miek@miek.nl> 2016-04-10 18:50:11 +0100
commit0ea2a6088dc95aea57bd6f502c5fb4b567623e66 (patch)
tree2c442aeae211d0cd832e9a13805cd314a790280c /test/server_test.go
parentdb98cd4e4bced5a383ae2914f438617bcea28f73 (diff)
downloadcoredns-0ea2a6088dc95aea57bd6f502c5fb4b567623e66.tar.gz
coredns-0ea2a6088dc95aea57bd6f502c5fb4b567623e66.tar.zst
coredns-0ea2a6088dc95aea57bd6f502c5fb4b567623e66.zip
Add TestServer (#102)
Add a fullblown testing server. This allows us to do integration tests. Also add a basic proxy test. Further tests will test etcd proxy and stub zone communication and other "wildish" configurations. Redo the server startup, so we can access the ports it listens on when it has started up (with dns.ActivateAndServer). Extend the .travis file to download etcd and test for that as well. Put integration tests in test dir
Diffstat (limited to 'test/server_test.go')
-rw-r--r--test/server_test.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/server_test.go b/test/server_test.go
new file mode 100644
index 000000000..6020e76d3
--- /dev/null
+++ b/test/server_test.go
@@ -0,0 +1,53 @@
+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) {
+ corefile := `.:0 {
+ chaos CoreDNS-001 miek@miek.nl
+}
+`
+ chaos, tcpCH, udpCH, err := testServer(t, corefile)
+ if err != nil {
+ t.Fatalf("Could get server: %s", err)
+ }
+ defer chaos.Stop()
+
+ corefileProxy := `.:0 {
+ proxy . ` + udpCH + `
+}
+`
+ proxy, _, udp, err := testServer(t, corefileProxy)
+ if err != nil {
+ t.Fatalf("Could get server: %s", err)
+ }
+ defer proxy.Stop()
+
+ chaosTest(t, udpCH, "udp")
+ chaosTest(t, tcpCH, "tcp")
+
+ chaosTest(t, udp, "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, net string) {
+ m := testMsg("version.bind.", dns.TypeTXT, nil)
+ m.Question[0].Qclass = dns.ClassCHAOS
+
+ r, err := testExchange(m, server, net)
+ 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 on %s, got %s", net, 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())
+ }
+}