coredns/test/chaos_test.go
Miek Gieben f3134da45e
Clean up tests logging (#1979)
* Clean up tests logging

This cleans up the travis logs so you can see the failures better.

Older tests in tests/ would call log.SetOutput(ioutil.Discard) in
a haphazard way. This add log.Discard and put an `init` function in each
package's dir (no way to do this globally). The cleanup in tests/ is
clear.

All plugins also got this init function to have some uniformity and kill
any (future) logging there in the tests as well.

There is a one-off in pkg/healthcheck because that does log.

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

* bring back original log_test.go

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

* suppress logging here as well

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-07-19 16:23:06 +01:00

38 lines
819 B
Go

package test
import (
"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()
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)
}
}