tests: clean up output
Some document improvements and add a few more tests.
This commit is contained in:
parent
e43384b501
commit
e8b4412564
8 changed files with 53 additions and 13 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
29
middleware/pkg/rcode/rcode_test.go
Normal file
29
middleware/pkg/rcode/rcode_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue