coredns/middleware/etcd/multi_test.go
Miek Gieben 9ac3cab1b7 Make CoreDNS a server type plugin for Caddy (#220)
* Make CoreDNS a server type plugin for Caddy

Remove code we don't need and port all middleware over. Fix all tests
and rework the documentation.

Also make `go generate` build a caddy binary which we then copy into
our directory. This means `go build`-builds remain working as-is.

And new etc instances in each etcd test for better isolation.
Fix more tests and rework test.Server with the newer support Caddy offers.

Fix Makefile to support new mode of operation.
2016-08-19 17:14:17 -07:00

75 lines
1.9 KiB
Go

// +build etcd
package etcd
import (
"sort"
"testing"
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware/etcd/msg"
"github.com/miekg/coredns/middleware/test"
"github.com/miekg/dns"
)
func TestMultiLookup(t *testing.T) {
etc := newEtcdMiddleware()
etc.Zones = []string{"skydns.test.", "miek.nl."}
etc.Next = test.ErrorHandler()
for _, serv := range servicesMulti {
set(t, etc, serv.Key, 0, serv)
defer delete(t, etc, serv.Key)
}
for _, tc := range dnsTestCasesMulti {
m := tc.Msg()
rec := middleware.NewResponseRecorder(&test.ResponseWriter{})
_, err := etc.ServeDNS(ctxt, rec, m)
if err != nil {
t.Errorf("expected no error, got %v\n", err)
return
}
resp := rec.Msg()
sort.Sort(test.RRSet(resp.Answer))
sort.Sort(test.RRSet(resp.Ns))
sort.Sort(test.RRSet(resp.Extra))
if !test.Header(t, tc, resp) {
t.Logf("%v\n", resp)
continue
}
if !test.Section(t, tc, test.Answer, resp.Answer) {
t.Logf("%v\n", resp)
}
if !test.Section(t, tc, test.Ns, resp.Ns) {
t.Logf("%v\n", resp)
}
if !test.Section(t, tc, test.Extra, resp.Extra) {
t.Logf("%v\n", resp)
}
}
}
// Note the key is encoded as DNS name, while in "reality" it is a etcd path.
var servicesMulti = []*msg.Service{
{Host: "dev.server1", Port: 8080, Key: "a.server1.dev.region1.skydns.test."},
{Host: "dev.server1", Port: 8080, Key: "a.server1.dev.region1.miek.nl."},
{Host: "dev.server1", Port: 8080, Key: "a.server1.dev.region1.example.org."},
}
var dnsTestCasesMulti = []test.Case{
{
Qname: "a.server1.dev.region1.skydns.test.", Qtype: dns.TypeSRV,
Answer: []dns.RR{test.SRV("a.server1.dev.region1.skydns.test. 300 SRV 10 100 8080 dev.server1.")},
},
{
Qname: "a.server1.dev.region1.miek.nl.", Qtype: dns.TypeSRV,
Answer: []dns.RR{test.SRV("a.server1.dev.region1.miek.nl. 300 SRV 10 100 8080 dev.server1.")},
},
{
Qname: "a.server1.dev.region1.example.org.", Qtype: dns.TypeSRV, Rcode: dns.RcodeServerFailure,
},
}