mirror of
https://github.com/coredns/coredns.git
synced 2025-12-06 02:15:11 -05:00
Run golint and go vet (#276)
Cleanup the errors and removed deadcode along the way. The leaves some error laying around, mostly about commenting exported identifier. We should look hard if those really are needed.
This commit is contained in:
@@ -1,70 +1,22 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
// Hook in CoreDNS.
|
||||
_ "github.com/miekg/coredns/core"
|
||||
|
||||
"github.com/mholt/caddy"
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
// TCPServer returns a generic DNS server listening for TCP connections on laddr.
|
||||
func TCPServer(t *testing.T, laddr string) (*dns.Server, string, error) {
|
||||
l, err := net.Listen("tcp", laddr)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
server := &dns.Server{Listener: l, ReadTimeout: time.Hour, WriteTimeout: time.Hour}
|
||||
|
||||
waitLock := sync.Mutex{}
|
||||
waitLock.Lock()
|
||||
server.NotifyStartedFunc = func() { t.Logf("started TCP server on %s", l.Addr()); waitLock.Unlock() }
|
||||
|
||||
go func() {
|
||||
server.ActivateAndServe()
|
||||
l.Close()
|
||||
}()
|
||||
|
||||
waitLock.Lock()
|
||||
return server, l.Addr().String(), nil
|
||||
}
|
||||
|
||||
// UDPServer returns a generic DNS server listening for UDP connections on laddr.
|
||||
func UDPServer(t *testing.T, laddr string) (*dns.Server, string, error) {
|
||||
pc, err := net.ListenPacket("udp", laddr)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
server := &dns.Server{PacketConn: pc, ReadTimeout: time.Hour, WriteTimeout: time.Hour}
|
||||
|
||||
waitLock := sync.Mutex{}
|
||||
waitLock.Lock()
|
||||
server.NotifyStartedFunc = func() { t.Logf("started UDP server on %s", pc.LocalAddr()); waitLock.Unlock() }
|
||||
|
||||
go func() {
|
||||
server.ActivateAndServe()
|
||||
pc.Close()
|
||||
}()
|
||||
|
||||
waitLock.Lock()
|
||||
return server, pc.LocalAddr().String(), nil
|
||||
}
|
||||
|
||||
// CoreDNSServer returns a CoreDNS test server. It just takes a normal Corefile as input.
|
||||
func CoreDNSServer(corefile string) (*caddy.Instance, error) {
|
||||
caddy.Quiet = true
|
||||
return caddy.Start(NewInput(corefile))
|
||||
}
|
||||
|
||||
// CoreDNSSserverStop stops a server.
|
||||
// CoreDNSServerStop stops a server.
|
||||
func CoreDNSServerStop(i *caddy.Instance) { i.Stop() }
|
||||
|
||||
// CoreDNSServeRPorts returns the ports the instance is listening on. The integer k indicates
|
||||
// CoreDNSServerPorts returns the ports the instance is listening on. The integer k indicates
|
||||
// which ServerListener you want.
|
||||
func CoreDNSServerPorts(i *caddy.Instance, k int) (udp, tcp string) {
|
||||
srvs := i.Servers()
|
||||
@@ -83,14 +35,21 @@ func CoreDNSServerPorts(i *caddy.Instance, k int) (udp, tcp string) {
|
||||
return
|
||||
}
|
||||
|
||||
// Input implements the caddy.Input interface and acts as an easy way to use a string as a Corefile.
|
||||
type Input struct {
|
||||
corefile []byte
|
||||
}
|
||||
|
||||
// NewInput returns a pointer to Input, containing the corefile string as input.
|
||||
func NewInput(corefile string) *Input {
|
||||
return &Input{corefile: []byte(corefile)}
|
||||
}
|
||||
|
||||
func (i *Input) Body() []byte { return i.corefile }
|
||||
func (i *Input) Path() string { return "Corefile" }
|
||||
// Body implements the Input interface.
|
||||
func (i *Input) Body() []byte { return i.corefile }
|
||||
|
||||
// Path implements the Input interface.
|
||||
func (i *Input) Path() string { return "Corefile" }
|
||||
|
||||
// ServerType implements the Input interface.
|
||||
func (i *Input) ServerType() string { return "dns" }
|
||||
|
||||
Reference in New Issue
Block a user