diff options
author | 2017-05-22 13:09:35 +0100 | |
---|---|---|
committer | 2017-05-22 08:09:35 -0400 | |
commit | 024f56682dcaaaae2dd990d6fae3b54c8d17c467 (patch) | |
tree | 57ba35a5a8486ce0d23be2935880c6a0d3086d0a /test | |
parent | 7e6f5c77aa617bb95df10cbfacf22b1e96751169 (diff) | |
download | coredns-024f56682dcaaaae2dd990d6fae3b54c8d17c467.tar.gz coredns-024f56682dcaaaae2dd990d6fae3b54c8d17c467.tar.zst coredns-024f56682dcaaaae2dd990d6fae3b54c8d17c467.zip |
middleware/chaos: fix version (#669)
* middleware/chaos: fix version
Move the version setting into a init function so it is done early. Then
tweak the setup code for chaos a bit to correctly pick this version up.
Add an integration test to pick this up in the toplevel test/ directory.
Fixes #667
* Update tests
Diffstat (limited to 'test')
-rw-r--r-- | test/chaos_test.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/chaos_test.go b/test/chaos_test.go new file mode 100644 index 000000000..4f902c841 --- /dev/null +++ b/test/chaos_test.go @@ -0,0 +1,48 @@ +package test + +import ( + "io/ioutil" + "log" + "testing" + + // Plug in CoreDNS, needed for AppVersion and AppName in this test. + _ "github.com/coredns/coredns/coremain" + + "github.com/mholt/caddy" + "github.com/miekg/dns" +) + +func TestChaos(t *testing.T) { + corefile := `.:0 { + chaos +} +` + + i, err := CoreDNSServer(corefile) + if err != nil { + t.Fatalf("Could not get CoreDNS serving instance: %s", err) + } + // Stop the server. + defer i.Stop() + + udp, _ := CoreDNSServerPorts(i, 0) + if udp == "" { + t.Fatalf("Could not get UDP listening port") + } + + log.SetOutput(ioutil.Discard) + + m := new(dns.Msg) + m.SetQuestion("version.bind.", dns.TypeTXT) + m.Question[0].Qclass = dns.ClassCHAOS + + resp, err := dns.Exchange(m, udp) + if err != nil { + t.Fatalf("Expected to receive reply, but didn't: %v", err) + } + chTxt := resp.Answer[0].(*dns.TXT).Txt[0] + version := caddy.AppName + "-" + caddy.AppVersion + if chTxt != version { + t.Fatalf("Expected version to bo %s, got %s", version, chTxt) + } +} |