diff --git a/README.md b/README.md index 72c4d443b..5c59dc2b9 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ Github: ## Systemd Service File -Use this as a systemd service file. It defaults to a coredns with a homedir of /home/coredns +Use this as a systemd service file. It defaults to a coredns with a homedir of /home/coredns and the binary lives in /opt/bin and the config in `/etc/coredns/Corefile`: ~~~ txt @@ -154,12 +154,11 @@ After=network.target [Service] PermissionsStartOnly=true -PIDFile=/home/coredns/coredns.pid LimitNOFILE=8192 User=coredns WorkingDirectory=/home/coredns ExecStartPre=/sbin/setcap cap_net_bind_service=+ep /opt/bin/coredns -ExecStart=/opt/bin/coredns -pidfile /home/coredns/coredns.pid -conf=/etc/coredns/Corefile +ExecStart=/opt/bin/coredns -conf=/etc/coredns/Corefile ExecReload=/bin/kill -SIGUSR1 $MAINPID Restart=on-failure diff --git a/middleware/file/nsec3_test.go b/middleware/file/nsec3_test.go index 938ff120c..04b76b8a2 100644 --- a/middleware/file/nsec3_test.go +++ b/middleware/file/nsec3_test.go @@ -10,7 +10,6 @@ func TestParseNSEC3PARAM(t *testing.T) { if err == nil { t.Fatalf("expected error when reading zone, got nothing") } - t.Logf("%v\n", err) } func TestParseNSEC3(t *testing.T) { @@ -18,7 +17,6 @@ func TestParseNSEC3(t *testing.T) { if err == nil { t.Fatalf("expected error when reading zone, got nothing") } - t.Logf("%v\n", err) } const nsec3paramTest = `miek.nl. 1800 IN SOA linode.atoom.net. miek.miek.nl. 1460175181 14400 3600 604800 14400 diff --git a/middleware/file/reload_test.go b/middleware/file/reload_test.go index 06690805f..9dcafc8a2 100644 --- a/middleware/file/reload_test.go +++ b/middleware/file/reload_test.go @@ -2,6 +2,7 @@ package file import ( "io/ioutil" + "log" "os" "testing" "time" @@ -11,6 +12,8 @@ import ( ) func TestZoneReload(t *testing.T) { + log.SetOutput(ioutil.Discard) + fileName, rm, err := test.TempFile(".", reloadZoneTest) if err != nil { t.Fatalf("failed to create zone: %s", err) diff --git a/middleware/file/secondary_test.go b/middleware/file/secondary_test.go index 6f45a61bb..e978fcd2f 100644 --- a/middleware/file/secondary_test.go +++ b/middleware/file/secondary_test.go @@ -2,6 +2,8 @@ package file import ( "fmt" + "io/ioutil" + "log" "testing" "github.com/miekg/coredns/middleware/test" @@ -70,11 +72,12 @@ const testZone = "secondary.miek.nl." func TestShouldTransfer(t *testing.T) { soa := soa{250} + log.SetOutput(ioutil.Discard) dns.HandleFunc(testZone, soa.Handler) defer dns.HandleRemove(testZone) - s, addrstr, err := test.TCPServer(t, "127.0.0.1:0") + s, addrstr, err := test.TCPServer("127.0.0.1:0") if err != nil { t.Fatalf("unable to run test server: %v", err) } @@ -114,11 +117,12 @@ func TestShouldTransfer(t *testing.T) { func TestTransferIn(t *testing.T) { soa := soa{250} + log.SetOutput(ioutil.Discard) dns.HandleFunc(testZone, soa.Handler) defer dns.HandleRemove(testZone) - s, addrstr, err := test.TCPServer(t, "127.0.0.1:0") + s, addrstr, err := test.TCPServer("127.0.0.1:0") if err != nil { t.Fatalf("unable to run test server: %v", err) } diff --git a/middleware/metrics/setup_test.go b/middleware/metrics/setup_test.go index 2971634f9..fbda89a54 100644 --- a/middleware/metrics/setup_test.go +++ b/middleware/metrics/setup_test.go @@ -6,7 +6,7 @@ import ( "github.com/mholt/caddy" ) -func TestPrometheus(t *testing.T) { +func TestPrometheusParse(t *testing.T) { tests := []struct { input string shouldErr bool diff --git a/middleware/pkg/rcode/rcode_test.go b/middleware/pkg/rcode/rcode_test.go new file mode 100644 index 000000000..bfca32f1d --- /dev/null +++ b/middleware/pkg/rcode/rcode_test.go @@ -0,0 +1,29 @@ +package rcode + +import ( + "testing" + + "github.com/miekg/dns" +) + +func TestToString(t *testing.T) { + tests := []struct { + in int + expected string + }{ + { + dns.RcodeSuccess, + "NOERROR", + }, + { + 28, + "RCODE28", + }, + } + for i, test := range tests { + got := ToString(test.in) + if got != test.expected { + t.Errorf("Test %d, expected %s, got %s", i, test.expected, got) + } + } +} diff --git a/middleware/test/server.go b/middleware/test/server.go index 03237df5b..eb39c7a5b 100644 --- a/middleware/test/server.go +++ b/middleware/test/server.go @@ -3,14 +3,13 @@ package test import ( "net" "sync" - "testing" "time" "github.com/miekg/dns" ) // TCPServer starts a DNS server with a TCP listener on laddr. -func TCPServer(t *testing.T, laddr string) (*dns.Server, string, error) { +func TCPServer(laddr string) (*dns.Server, string, error) { l, err := net.Listen("tcp", laddr) if err != nil { return nil, "", err @@ -20,7 +19,7 @@ func TCPServer(t *testing.T, laddr string) (*dns.Server, string, error) { waitLock := sync.Mutex{} waitLock.Lock() - server.NotifyStartedFunc = func() { t.Logf("started TCP server on %s", l.Addr()); waitLock.Unlock() } + server.NotifyStartedFunc = func() { waitLock.Unlock() } go func() { server.ActivateAndServe() @@ -32,7 +31,7 @@ func TCPServer(t *testing.T, laddr string) (*dns.Server, string, error) { } // UDPServer starts a DNS server with an UDP listener on laddr. -func UDPServer(t *testing.T, laddr string) (*dns.Server, string, error) { +func UDPServer(laddr string) (*dns.Server, string, error) { pc, err := net.ListenPacket("udp", laddr) if err != nil { return nil, "", err @@ -41,7 +40,7 @@ func UDPServer(t *testing.T, laddr string) (*dns.Server, string, error) { waitLock := sync.Mutex{} waitLock.Lock() - server.NotifyStartedFunc = func() { t.Logf("started UDP server on %s", pc.LocalAddr()); waitLock.Unlock() } + server.NotifyStartedFunc = func() { waitLock.Unlock() } go func() { server.ActivateAndServe() diff --git a/test/server.go b/test/server.go index 97e8070e3..d472cc7d0 100644 --- a/test/server.go +++ b/test/server.go @@ -1,6 +1,11 @@ package test import ( + "io/ioutil" + "log" + + "github.com/miekg/coredns/core/dnsserver" + // Hook in CoreDNS. _ "github.com/miekg/coredns/core" @@ -10,6 +15,9 @@ import ( // CoreDNSServer returns a CoreDNS test server. It just takes a normal Corefile as input. func CoreDNSServer(corefile string) (*caddy.Instance, error) { caddy.Quiet = true + dnsserver.Quiet = true + log.SetOutput(ioutil.Discard) + return caddy.Start(NewInput(corefile)) }