diff options
author | 2016-04-07 08:03:57 +0100 | |
---|---|---|
committer | 2016-04-07 08:03:57 +0100 | |
commit | 09207867e40a85bafb3a93d659d7c428293bb6a7 (patch) | |
tree | 25cddf65ec9a374d1d29a96fc3276d69e17fe73e /middleware/testing/server.go | |
parent | e4c72719bfb10d5bc5d79a172d8a0b5e852acc2a (diff) | |
download | coredns-09207867e40a85bafb3a93d659d7c428293bb6a7.tar.gz coredns-09207867e40a85bafb3a93d659d7c428293bb6a7.tar.zst coredns-09207867e40a85bafb3a93d659d7c428293bb6a7.zip |
Add missing test file and fix notify
We should not check the port of the request, we *should* actually
normalize it to port 53 - as that will probably be the address of
the server. Still need to double check if this will work if the
axfr should actually be done from a different port. That will come
later, this is good enough for now.
Diffstat (limited to 'middleware/testing/server.go')
-rw-r--r-- | middleware/testing/server.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/middleware/testing/server.go b/middleware/testing/server.go new file mode 100644 index 000000000..b32b8b965 --- /dev/null +++ b/middleware/testing/server.go @@ -0,0 +1,53 @@ +package testing + +import ( + "net" + "sync" + "time" + + "github.com/miekg/dns" +) + +func TCPServer(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 = waitLock.Unlock + + go func() { + server.ActivateAndServe() + l.Close() + }() + + waitLock.Lock() + return server, l.Addr().String(), nil +} + +func UDPServer(laddr string) (*dns.Server, string, chan bool, error) { + pc, err := net.ListenPacket("udp", laddr) + if err != nil { + return nil, "", nil, err + } + server := &dns.Server{PacketConn: pc, ReadTimeout: time.Hour, WriteTimeout: time.Hour} + + waitLock := sync.Mutex{} + waitLock.Lock() + server.NotifyStartedFunc = waitLock.Unlock + + stop := make(chan bool) + + go func() { + server.ActivateAndServe() + close(stop) + pc.Close() + }() + + waitLock.Lock() + return server, pc.LocalAddr().String(), stop, nil +} |