cidr everywhere: check all middleware (#915)

* cidr everywhere: check all middleware

Add tests for cidr in only that middleware that already tests for this.
Check the other ones manually (and put reverse in the tests cases
anyway).

Make etcd setup_test run without +build etcd tag - it is not needed
for this test - move rest of the code to lookup_test.go.

Cleanup proxy test a bit and remove TempDir as there is test.TempFile
that does the same thing.

Fixes #909

* coredns package

* Fix test compile
This commit is contained in:
Miek Gieben 2017-08-13 18:16:25 +01:00 committed by GitHub
parent 0c02708d63
commit 818d2b10ad
9 changed files with 135 additions and 127 deletions

View file

@ -1,95 +1,12 @@
// +build etcd
package etcd
import (
"encoding/json"
"sort"
"strings"
"testing"
"time"
"github.com/coredns/coredns/middleware/etcd/msg"
"github.com/coredns/coredns/middleware/pkg/dnsrecorder"
"github.com/coredns/coredns/middleware/pkg/singleflight"
"github.com/coredns/coredns/middleware/pkg/tls"
"github.com/coredns/coredns/middleware/proxy"
"github.com/coredns/coredns/middleware/test"
etcdc "github.com/coreos/etcd/client"
"github.com/mholt/caddy"
"golang.org/x/net/context"
)
func init() {
ctxt, _ = context.WithTimeout(context.Background(), etcdTimeout)
}
func newEtcdMiddleware() *Etcd {
ctxt, _ = context.WithTimeout(context.Background(), etcdTimeout)
endpoints := []string{"http://localhost:2379"}
tlsc, _ := tls.NewTLSConfigFromArgs()
client, _ := newEtcdClient(endpoints, tlsc)
return &Etcd{
Proxy: proxy.NewLookup([]string{"8.8.8.8:53"}),
PathPrefix: "skydns",
Ctx: context.Background(),
Inflight: &singleflight.Group{},
Zones: []string{"skydns.test.", "skydns_extra.test.", "in-addr.arpa."},
Client: client,
}
}
func set(t *testing.T, e *Etcd, k string, ttl time.Duration, m *msg.Service) {
b, err := json.Marshal(m)
if err != nil {
t.Fatal(err)
}
path, _ := msg.PathWithWildcard(k, e.PathPrefix)
e.Client.Set(ctxt, path, string(b), &etcdc.SetOptions{TTL: ttl})
}
func delete(t *testing.T, e *Etcd, k string) {
path, _ := msg.PathWithWildcard(k, e.PathPrefix)
e.Client.Delete(ctxt, path, &etcdc.DeleteOptions{Recursive: false})
}
func TestLookup(t *testing.T) {
etc := newEtcdMiddleware()
for _, serv := range services {
set(t, etc, serv.Key, 0, serv)
defer delete(t, etc, serv.Key)
}
for _, tc := range dnsTestCases {
m := tc.Msg()
rec := dnsrecorder.New(&test.ResponseWriter{})
etc.ServeDNS(ctxt, rec, m)
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)
}
}
}
func TestSetupEtcd(t *testing.T) {
tests := []struct {
input string
@ -145,5 +62,3 @@ func TestSetupEtcd(t *testing.T) {
}
}
}
var ctxt context.Context