tests: clean up output

Some document improvements and add a few more tests.
This commit is contained in:
Miek Gieben 2016-10-08 16:44:43 +01:00
parent e43384b501
commit e8b4412564
8 changed files with 53 additions and 13 deletions

View file

@ -143,7 +143,7 @@ Github: <https://github.com/miekg/coredns>
## Systemd Service File ## 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`: and the binary lives in /opt/bin and the config in `/etc/coredns/Corefile`:
~~~ txt ~~~ txt
@ -154,12 +154,11 @@ After=network.target
[Service] [Service]
PermissionsStartOnly=true PermissionsStartOnly=true
PIDFile=/home/coredns/coredns.pid
LimitNOFILE=8192 LimitNOFILE=8192
User=coredns User=coredns
WorkingDirectory=/home/coredns WorkingDirectory=/home/coredns
ExecStartPre=/sbin/setcap cap_net_bind_service=+ep /opt/bin/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 ExecReload=/bin/kill -SIGUSR1 $MAINPID
Restart=on-failure Restart=on-failure

View file

@ -10,7 +10,6 @@ func TestParseNSEC3PARAM(t *testing.T) {
if err == nil { if err == nil {
t.Fatalf("expected error when reading zone, got nothing") t.Fatalf("expected error when reading zone, got nothing")
} }
t.Logf("%v\n", err)
} }
func TestParseNSEC3(t *testing.T) { func TestParseNSEC3(t *testing.T) {
@ -18,7 +17,6 @@ func TestParseNSEC3(t *testing.T) {
if err == nil { if err == nil {
t.Fatalf("expected error when reading zone, got nothing") 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 const nsec3paramTest = `miek.nl. 1800 IN SOA linode.atoom.net. miek.miek.nl. 1460175181 14400 3600 604800 14400

View file

@ -2,6 +2,7 @@ package file
import ( import (
"io/ioutil" "io/ioutil"
"log"
"os" "os"
"testing" "testing"
"time" "time"
@ -11,6 +12,8 @@ import (
) )
func TestZoneReload(t *testing.T) { func TestZoneReload(t *testing.T) {
log.SetOutput(ioutil.Discard)
fileName, rm, err := test.TempFile(".", reloadZoneTest) fileName, rm, err := test.TempFile(".", reloadZoneTest)
if err != nil { if err != nil {
t.Fatalf("failed to create zone: %s", err) t.Fatalf("failed to create zone: %s", err)

View file

@ -2,6 +2,8 @@ package file
import ( import (
"fmt" "fmt"
"io/ioutil"
"log"
"testing" "testing"
"github.com/miekg/coredns/middleware/test" "github.com/miekg/coredns/middleware/test"
@ -70,11 +72,12 @@ const testZone = "secondary.miek.nl."
func TestShouldTransfer(t *testing.T) { func TestShouldTransfer(t *testing.T) {
soa := soa{250} soa := soa{250}
log.SetOutput(ioutil.Discard)
dns.HandleFunc(testZone, soa.Handler) dns.HandleFunc(testZone, soa.Handler)
defer dns.HandleRemove(testZone) 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 { if err != nil {
t.Fatalf("unable to run test server: %v", err) t.Fatalf("unable to run test server: %v", err)
} }
@ -114,11 +117,12 @@ func TestShouldTransfer(t *testing.T) {
func TestTransferIn(t *testing.T) { func TestTransferIn(t *testing.T) {
soa := soa{250} soa := soa{250}
log.SetOutput(ioutil.Discard)
dns.HandleFunc(testZone, soa.Handler) dns.HandleFunc(testZone, soa.Handler)
defer dns.HandleRemove(testZone) 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 { if err != nil {
t.Fatalf("unable to run test server: %v", err) t.Fatalf("unable to run test server: %v", err)
} }

View file

@ -6,7 +6,7 @@ import (
"github.com/mholt/caddy" "github.com/mholt/caddy"
) )
func TestPrometheus(t *testing.T) { func TestPrometheusParse(t *testing.T) {
tests := []struct { tests := []struct {
input string input string
shouldErr bool shouldErr bool

View file

@ -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)
}
}
}

View file

@ -3,14 +3,13 @@ package test
import ( import (
"net" "net"
"sync" "sync"
"testing"
"time" "time"
"github.com/miekg/dns" "github.com/miekg/dns"
) )
// TCPServer starts a DNS server with a TCP listener on laddr. // 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) l, err := net.Listen("tcp", laddr)
if err != nil { if err != nil {
return nil, "", err return nil, "", err
@ -20,7 +19,7 @@ func TCPServer(t *testing.T, laddr string) (*dns.Server, string, error) {
waitLock := sync.Mutex{} waitLock := sync.Mutex{}
waitLock.Lock() waitLock.Lock()
server.NotifyStartedFunc = func() { t.Logf("started TCP server on %s", l.Addr()); waitLock.Unlock() } server.NotifyStartedFunc = func() { waitLock.Unlock() }
go func() { go func() {
server.ActivateAndServe() 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. // 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) pc, err := net.ListenPacket("udp", laddr)
if err != nil { if err != nil {
return nil, "", err return nil, "", err
@ -41,7 +40,7 @@ func UDPServer(t *testing.T, laddr string) (*dns.Server, string, error) {
waitLock := sync.Mutex{} waitLock := sync.Mutex{}
waitLock.Lock() waitLock.Lock()
server.NotifyStartedFunc = func() { t.Logf("started UDP server on %s", pc.LocalAddr()); waitLock.Unlock() } server.NotifyStartedFunc = func() { waitLock.Unlock() }
go func() { go func() {
server.ActivateAndServe() server.ActivateAndServe()

View file

@ -1,6 +1,11 @@
package test package test
import ( import (
"io/ioutil"
"log"
"github.com/miekg/coredns/core/dnsserver"
// Hook in CoreDNS. // Hook in CoreDNS.
_ "github.com/miekg/coredns/core" _ "github.com/miekg/coredns/core"
@ -10,6 +15,9 @@ import (
// CoreDNSServer returns a CoreDNS test server. It just takes a normal Corefile as input. // CoreDNSServer returns a CoreDNS test server. It just takes a normal Corefile as input.
func CoreDNSServer(corefile string) (*caddy.Instance, error) { func CoreDNSServer(corefile string) (*caddy.Instance, error) {
caddy.Quiet = true caddy.Quiet = true
dnsserver.Quiet = true
log.SetOutput(ioutil.Discard)
return caddy.Start(NewInput(corefile)) return caddy.Start(NewInput(corefile))
} }