coredns/test/chaos_test.go
Miek Gieben f901b0cefa tests: CoreDNSServerAndPorts (#972)
* tests: CoreDNSServerAndPorts

Copy from kubernetes.go and renamed to fit the style, adapted almost
all callers.

This is a mechanicl change, no testdata was changed.

* typos
2017-08-24 11:35:14 +01:00

42 lines
871 B
Go

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, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
defer i.Stop()
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)
}
}