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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
59 changed files with 188 additions and 82 deletions

View file

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

5
plugin/auto/log_test.go Normal file
View file

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

5
plugin/bind/log_test.go Normal file
View file

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

5
plugin/cache/log_test.go vendored Normal file
View file

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

5
plugin/chaos/log_test.go Normal file
View file

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

5
plugin/debug/log_test.go Normal file
View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

5
plugin/etcd/log_test.go Normal file
View file

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

View file

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

5
plugin/file/log_test.go Normal file
View file

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

View file

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

View file

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

5
plugin/hosts/log_test.go Normal file
View file

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

View file

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

View file

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

View file

@ -8,12 +8,15 @@ import (
"testing"
"github.com/coredns/coredns/plugin/pkg/dnstest"
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/response"
"github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns"
)
func init() { clog.Discard() }
func TestLoggedStatus(t *testing.T) {
var f bytes.Buffer
rule := Rule{

5
plugin/log_test.go Normal file
View file

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

View file

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

View file

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

5
plugin/nsid/log_test.go Normal file
View file

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

View file

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

View file

@ -10,6 +10,7 @@ package log
import (
"fmt"
"io/ioutil"
golog "log"
)
@ -61,6 +62,9 @@ func Error(v ...interface{}) { log(err, v...) }
// Errorf is equivalent to log.Printf, but prefixed with "[ERROR] ".
func Errorf(format string, v ...interface{}) { logf(err, format, v...) }
// Discard sets the log output to /dev/null.
func Discard() { golog.SetOutput(ioutil.Discard) }
const (
debug = "[DEBUG] "
err = "[ERROR] "

5
plugin/pprof/log_test.go Normal file
View file

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

5
plugin/proxy/log_test.go Normal file
View file

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

View file

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

View file

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

5
plugin/root/log_test.go Normal file
View file

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

View file

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

View file

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

View file

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

5
plugin/tls/log_test.go Normal file
View file

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

5
plugin/trace/log_test.go Normal file
View file

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

View file

@ -0,0 +1,5 @@
package whoami
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"
@ -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)}