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>
This commit is contained in:
Miek Gieben
2018-07-19 16:23:06 +01:00
committed by GitHub
parent c69bed726b
commit f3134da45e
59 changed files with 188 additions and 82 deletions

View File

@@ -2,7 +2,6 @@ package test
import (
"io/ioutil"
"log"
"os"
"path"
"testing"
@@ -35,8 +34,6 @@ func TestAuto(t *testing.T) {
}
defer i.Stop()
log.SetOutput(ioutil.Discard)
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
@@ -82,7 +79,6 @@ func TestAutoNonExistentZone(t *testing.T) {
if err != nil {
t.Fatal(err)
}
log.SetOutput(ioutil.Discard)
corefile := `.:0 {
auto {
@@ -117,7 +113,6 @@ func TestAutoNonExistentZone(t *testing.T) {
func TestAutoAXFR(t *testing.T) {
t.Parallel()
log.SetOutput(ioutil.Discard)
tmpdir, err := ioutil.TempDir(os.TempDir(), "coredns")
if err != nil {

View File

@@ -1,8 +1,6 @@
package test
import (
"io/ioutil"
"log"
"testing"
// Plug in CoreDNS, needed for AppVersion and AppName in this test.
@@ -24,8 +22,6 @@ func TestChaos(t *testing.T) {
}
defer i.Stop()
log.SetOutput(ioutil.Discard)
m := new(dns.Msg)
m.SetQuestion("version.bind.", dns.TypeTXT)
m.Question[0].Qclass = dns.ClassCHAOS

View File

@@ -1,8 +1,6 @@
package test
import (
"io/ioutil"
"log"
"testing"
"github.com/coredns/coredns/plugin/proxy"
@@ -49,8 +47,6 @@ func TestLookupDS(t *testing.T) {
}
defer i.Stop()
log.SetOutput(ioutil.Discard)
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &mtest.ResponseWriter{}, Req: new(dns.Msg)}

View File

@@ -4,8 +4,6 @@ package test
import (
"context"
"io/ioutil"
"log"
"testing"
"github.com/coredns/coredns/plugin/etcd/msg"
@@ -33,7 +31,6 @@ func TestEtcdCache(t *testing.T) {
defer ex.Stop()
etc := etcdPlugin()
log.SetOutput(ioutil.Discard)
var ctx = context.TODO()
for _, serv := range servicesCacheTest {

View File

@@ -5,8 +5,6 @@ package test
import (
"context"
"encoding/json"
"io/ioutil"
"log"
"testing"
"time"
@@ -53,7 +51,6 @@ func TestEtcdStubAndProxyLookup(t *testing.T) {
defer ex.Stop()
etc := etcdPlugin()
log.SetOutput(ioutil.Discard)
var ctx = context.TODO()
for _, serv := range servicesStub { // adds example.{net,org} as stubs

View File

@@ -1,8 +1,6 @@
package test
import (
"io/ioutil"
"log"
"testing"
"github.com/coredns/coredns/plugin/proxy"
@@ -14,7 +12,6 @@ import (
func TestZoneExternalCNAMELookupWithoutProxy(t *testing.T) {
t.Parallel()
log.SetOutput(ioutil.Discard)
name, rm, err := TempFile(".", exampleOrg)
if err != nil {
@@ -48,7 +45,6 @@ func TestZoneExternalCNAMELookupWithoutProxy(t *testing.T) {
func TestZoneExternalCNAMELookupWithProxy(t *testing.T) {
t.Parallel()
log.SetOutput(ioutil.Discard)
name, rm, err := TempFile(".", exampleOrg)
if err != nil {

View File

@@ -1,8 +1,6 @@
package test
import (
"io/ioutil"
"log"
"testing"
"github.com/miekg/dns"
@@ -10,7 +8,6 @@ import (
func TestZoneEDNS0Lookup(t *testing.T) {
t.Parallel()
log.SetOutput(ioutil.Discard)
name, rm, err := TempFile(".", `$ORIGIN example.org.
@ 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. (
@@ -58,7 +55,6 @@ www IN AAAA ::1
func TestZoneNoNS(t *testing.T) {
t.Parallel()
log.SetOutput(ioutil.Discard)
name, rm, err := TempFile(".", `$ORIGIN example.org.
@ 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. (

View File

@@ -1,8 +1,6 @@
package test
import (
"io/ioutil"
"log"
"testing"
"github.com/coredns/coredns/plugin/proxy"
@@ -14,7 +12,6 @@ import (
func TestZoneSRVAdditional(t *testing.T) {
t.Parallel()
log.SetOutput(ioutil.Discard)
name, rm, err := TempFile(".", exampleOrg)
if err != nil {

View File

@@ -2,8 +2,6 @@ package test
import (
"context"
"io/ioutil"
"log"
"testing"
"time"
@@ -14,8 +12,6 @@ import (
)
func TestGrpc(t *testing.T) {
log.SetOutput(ioutil.Discard)
corefile := `grpc://.:0 {
whoami
}

View File

@@ -1,8 +1,6 @@
package test
import (
"io/ioutil"
"log"
"testing"
"github.com/coredns/coredns/plugin/proxy"
@@ -26,8 +24,6 @@ func TestHostsInlineLookup(t *testing.T) {
}
defer i.Stop()
log.SetOutput(ioutil.Discard)
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}

5
test/log_test.go Normal file
View File

@@ -0,0 +1,5 @@
package test
import clog "github.com/coredns/coredns/plugin/pkg/log"
func init() { clog.Discard() }

View File

@@ -2,7 +2,6 @@ package test
import (
"io/ioutil"
"log"
"os"
"path"
"testing"
@@ -145,8 +144,6 @@ func TestMetricsAuto(t *testing.T) {
}
defer i.Stop()
log.SetOutput(ioutil.Discard)
// Write db.example.org to get example.org.
if err = ioutil.WriteFile(path.Join(tmpdir, "db.example.org"), []byte(zoneContent), 0644); err != nil {
t.Fatal(err)

View File

@@ -2,7 +2,6 @@ package test
import (
"io/ioutil"
"log"
"os"
"testing"
@@ -36,7 +35,6 @@ func TestLookupBalanceRewriteCacheDnssec(t *testing.T) {
}
defer ex.Stop()
log.SetOutput(ioutil.Discard)
c := new(dns.Client)
m := new(dns.Msg)
m.SetQuestion("example.org.", dns.TypeA)

View File

@@ -1,8 +1,6 @@
package test
import (
"io/ioutil"
"log"
"testing"
"github.com/coredns/coredns/plugin/test"
@@ -34,7 +32,6 @@ func benchmarkLookupBalanceRewriteCache(b *testing.B) {
}
defer ex.Stop()
log.SetOutput(ioutil.Discard)
c := new(dns.Client)
m := new(dns.Msg)
m.SetQuestion("example.org.", dns.TypeA)

View File

@@ -1,8 +1,6 @@
package test
import (
"io/ioutil"
"log"
"testing"
"github.com/coredns/coredns/plugin/proxy"
@@ -13,8 +11,6 @@ import (
)
func TestProxyErratic(t *testing.T) {
log.SetOutput(ioutil.Discard)
corefile := `example.org:0 {
erratic {
drop 2
@@ -39,8 +35,7 @@ func TestProxyErratic(t *testing.T) {
func TestProxyThreeWay(t *testing.T) {
// Run 3 CoreDNS server, 2 upstream ones and a proxy. 1 Upstream is unhealthy after 1 query, but after
// that we should still be able to send to the other one
log.SetOutput(ioutil.Discard)
// that we should still be able to send to the other one.
// Backend CoreDNS's.
corefileUp1 := `example.org:0 {

View File

@@ -2,8 +2,6 @@ package test
import (
"io"
"io/ioutil"
"log"
"net"
"net/http"
"net/http/httptest"
@@ -17,8 +15,6 @@ import (
)
func TestProxyWithHTTPCheckOK(t *testing.T) {
log.SetOutput(ioutil.Discard)
healthCheckServer := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)

View File

@@ -1,8 +1,6 @@
package test
import (
"io/ioutil"
"log"
"testing"
"github.com/coredns/coredns/plugin/proxy"
@@ -31,8 +29,6 @@ func TestLookupProxy(t *testing.T) {
}
defer i.Stop()
log.SetOutput(ioutil.Discard)
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
resp, err := p.Lookup(state, "example.org.", dns.TypeA)
@@ -70,8 +66,6 @@ func TestLookupDnsWithForcedTcp(t *testing.T) {
}
defer i.Stop()
log.SetOutput(ioutil.Discard)
p := proxy.NewLookupWithOption([]string{tcp}, proxy.Options{ForceTCP: true})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
resp, err := p.Lookup(state, "example.org.", dns.TypeA)
@@ -114,8 +108,6 @@ func BenchmarkProxyLookup(b *testing.B) {
}
defer i.Stop()
log.SetOutput(ioutil.Discard)
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}

View File

@@ -3,7 +3,6 @@ package test
import (
"bufio"
"io/ioutil"
"log"
"os"
"path/filepath"
"strconv"
@@ -48,8 +47,6 @@ func TestReadme(t *testing.T) {
create(contents)
defer remove(contents)
log.SetOutput(ioutil.Discard)
middle := filepath.Join("..", "plugin")
dirs, err := ioutil.ReadDir(middle)
if err != nil {

View File

@@ -1,8 +1,6 @@
package test
import (
"io/ioutil"
"log"
"testing"
"github.com/coredns/coredns/plugin/proxy"
@@ -28,8 +26,6 @@ func TestReverseCorefile(t *testing.T) {
t.Fatalf("Could not get UDP listening port")
}
log.SetOutput(ioutil.Discard)
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
resp, err := p.Lookup(state, "17.0.0.10.in-addr.arpa.", dns.TypePTR)

View File

@@ -2,8 +2,6 @@ package test
import (
"bytes"
"io/ioutil"
"log"
"testing"
"github.com/miekg/dns"
@@ -26,8 +24,6 @@ func TestRewrite(t *testing.T) {
defer i.Stop()
log.SetOutput(ioutil.Discard)
testMX(t, udp)
testEdns0(t, udp)
}

View File

@@ -1,8 +1,6 @@
package test
import (
"io/ioutil"
"log"
"sync"
"github.com/coredns/coredns/core/dnsserver"
@@ -21,7 +19,6 @@ func CoreDNSServer(corefile string) (*caddy.Instance, error) {
defer mu.Unlock()
caddy.Quiet = true
dnsserver.Quiet = true
log.SetOutput(ioutil.Discard)
return caddy.Start(NewInput(corefile))
}

View File

@@ -1,8 +1,6 @@
package test
import (
"io/ioutil"
"log"
"testing"
"github.com/coredns/coredns/plugin/proxy"
@@ -31,8 +29,6 @@ func TestLookupWildcard(t *testing.T) {
}
defer i.Stop()
log.SetOutput(ioutil.Discard)
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}