aboutsummaryrefslogtreecommitdiff
path: root/middleware
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2016-04-10 18:50:11 +0100
committerGravatar Miek Gieben <miek@miek.nl> 2016-04-10 18:50:11 +0100
commit0ea2a6088dc95aea57bd6f502c5fb4b567623e66 (patch)
tree2c442aeae211d0cd832e9a13805cd314a790280c /middleware
parentdb98cd4e4bced5a383ae2914f438617bcea28f73 (diff)
downloadcoredns-0ea2a6088dc95aea57bd6f502c5fb4b567623e66.tar.gz
coredns-0ea2a6088dc95aea57bd6f502c5fb4b567623e66.tar.zst
coredns-0ea2a6088dc95aea57bd6f502c5fb4b567623e66.zip
Add TestServer (#102)
Add a fullblown testing server. This allows us to do integration tests. Also add a basic proxy test. Further tests will test etcd proxy and stub zone communication and other "wildish" configurations. Redo the server startup, so we can access the ports it listens on when it has started up (with dns.ActivateAndServer). Extend the .travis file to download etcd and test for that as well. Put integration tests in test dir
Diffstat (limited to 'middleware')
-rw-r--r--middleware/etcd/cname_test.go27
-rw-r--r--middleware/etcd/group_test.go27
-rw-r--r--middleware/etcd/multi_test.go27
-rw-r--r--middleware/etcd/other_test.go27
-rw-r--r--middleware/etcd/setup_test.go28
-rw-r--r--middleware/etcd/stub_test.go1
-rw-r--r--middleware/file/wildcard_test.go1
7 files changed, 21 insertions, 117 deletions
diff --git a/middleware/etcd/cname_test.go b/middleware/etcd/cname_test.go
index 33e42aac7..147498d64 100644
--- a/middleware/etcd/cname_test.go
+++ b/middleware/etcd/cname_test.go
@@ -31,36 +31,17 @@ func TestCnameLookup(t *testing.T) {
}
resp := rec.Msg()
- if resp.Rcode != tc.Rcode {
- t.Errorf("rcode is %q, expected %q", dns.RcodeToString[resp.Rcode], dns.RcodeToString[tc.Rcode])
+ if !coretest.Header(t, tc, resp) {
t.Logf("%v\n", resp)
continue
}
-
- if len(resp.Answer) != len(tc.Answer) {
- t.Errorf("answer for %q contained %d results, %d expected", tc.Qname, len(resp.Answer), len(tc.Answer))
- t.Logf("%v\n", resp)
- continue
- }
- if len(resp.Ns) != len(tc.Ns) {
- t.Errorf("authority for %q contained %d results, %d expected", tc.Qname, len(resp.Ns), len(tc.Ns))
- t.Logf("%v\n", resp)
- continue
- }
- if len(resp.Extra) != len(tc.Extra) {
- t.Errorf("additional for %q contained %d results, %d expected", tc.Qname, len(resp.Extra), len(tc.Extra))
- t.Logf("%v\n", resp)
- continue
- }
-
- if !coretest.CheckSection(t, tc, coretest.Answer, resp.Answer) {
+ if !coretest.Section(t, tc, coretest.Answer, resp.Answer) {
t.Logf("%v\n", resp)
}
- if !coretest.CheckSection(t, tc, coretest.Ns, resp.Ns) {
+ if !coretest.Section(t, tc, coretest.Ns, resp.Ns) {
t.Logf("%v\n", resp)
-
}
- if !coretest.CheckSection(t, tc, coretest.Extra, resp.Extra) {
+ if !coretest.Section(t, tc, coretest.Extra, resp.Extra) {
t.Logf("%v\n", resp)
}
}
diff --git a/middleware/etcd/group_test.go b/middleware/etcd/group_test.go
index d7098c0c7..e37159f3f 100644
--- a/middleware/etcd/group_test.go
+++ b/middleware/etcd/group_test.go
@@ -37,36 +37,17 @@ func TestGroupLookup(t *testing.T) {
sort.Sort(coretest.RRSet(resp.Ns))
sort.Sort(coretest.RRSet(resp.Extra))
- if resp.Rcode != tc.Rcode {
- t.Errorf("rcode is %q, expected %q", dns.RcodeToString[resp.Rcode], dns.RcodeToString[tc.Rcode])
+ if !coretest.Header(t, tc, resp) {
t.Logf("%v\n", resp)
continue
}
-
- if len(resp.Answer) != len(tc.Answer) {
- t.Errorf("answer for %q contained %d results, %d expected", tc.Qname, len(resp.Answer), len(tc.Answer))
- t.Logf("%v\n", resp)
- continue
- }
- if len(resp.Ns) != len(tc.Ns) {
- t.Errorf("authority for %q contained %d results, %d expected", tc.Qname, len(resp.Ns), len(tc.Ns))
- t.Logf("%v\n", resp)
- continue
- }
- if len(resp.Extra) != len(tc.Extra) {
- t.Errorf("additional for %q contained %d results, %d expected", tc.Qname, len(resp.Extra), len(tc.Extra))
- t.Logf("%v\n", resp)
- continue
- }
-
- if !coretest.CheckSection(t, tc, coretest.Answer, resp.Answer) {
+ if !coretest.Section(t, tc, coretest.Answer, resp.Answer) {
t.Logf("%v\n", resp)
}
- if !coretest.CheckSection(t, tc, coretest.Ns, resp.Ns) {
+ if !coretest.Section(t, tc, coretest.Ns, resp.Ns) {
t.Logf("%v\n", resp)
-
}
- if !coretest.CheckSection(t, tc, coretest.Extra, resp.Extra) {
+ if !coretest.Section(t, tc, coretest.Extra, resp.Extra) {
t.Logf("%v\n", resp)
}
}
diff --git a/middleware/etcd/multi_test.go b/middleware/etcd/multi_test.go
index cae43f18a..980b17a53 100644
--- a/middleware/etcd/multi_test.go
+++ b/middleware/etcd/multi_test.go
@@ -40,36 +40,17 @@ func TestMultiLookup(t *testing.T) {
sort.Sort(coretest.RRSet(resp.Ns))
sort.Sort(coretest.RRSet(resp.Extra))
- if resp.Rcode != tc.Rcode {
- t.Errorf("rcode is %q, expected %q", dns.RcodeToString[resp.Rcode], dns.RcodeToString[tc.Rcode])
+ if !coretest.Header(t, tc, resp) {
t.Logf("%v\n", resp)
continue
}
-
- if len(resp.Answer) != len(tc.Answer) {
- t.Errorf("answer for %q contained %d results, %d expected", tc.Qname, len(resp.Answer), len(tc.Answer))
- t.Logf("%v\n", resp)
- continue
- }
- if len(resp.Ns) != len(tc.Ns) {
- t.Errorf("authority for %q contained %d results, %d expected", tc.Qname, len(resp.Ns), len(tc.Ns))
- t.Logf("%v\n", resp)
- continue
- }
- if len(resp.Extra) != len(tc.Extra) {
- t.Errorf("additional for %q contained %d results, %d expected", tc.Qname, len(resp.Extra), len(tc.Extra))
- t.Logf("%v\n", resp)
- continue
- }
-
- if !coretest.CheckSection(t, tc, coretest.Answer, resp.Answer) {
+ if !coretest.Section(t, tc, coretest.Answer, resp.Answer) {
t.Logf("%v\n", resp)
}
- if !coretest.CheckSection(t, tc, coretest.Ns, resp.Ns) {
+ if !coretest.Section(t, tc, coretest.Ns, resp.Ns) {
t.Logf("%v\n", resp)
-
}
- if !coretest.CheckSection(t, tc, coretest.Extra, resp.Extra) {
+ if !coretest.Section(t, tc, coretest.Extra, resp.Extra) {
t.Logf("%v\n", resp)
}
}
diff --git a/middleware/etcd/other_test.go b/middleware/etcd/other_test.go
index da1cc7d74..ac0db7d3e 100644
--- a/middleware/etcd/other_test.go
+++ b/middleware/etcd/other_test.go
@@ -39,36 +39,17 @@ func TestOtherLookup(t *testing.T) {
sort.Sort(coretest.RRSet(resp.Ns))
sort.Sort(coretest.RRSet(resp.Extra))
- if resp.Rcode != tc.Rcode {
- t.Errorf("rcode is %q, expected %q", dns.RcodeToString[resp.Rcode], dns.RcodeToString[tc.Rcode])
+ if !coretest.Header(t, tc, resp) {
t.Logf("%v\n", resp)
continue
}
-
- if len(resp.Answer) != len(tc.Answer) {
- t.Errorf("answer for %q contained %d results, %d expected", tc.Qname, len(resp.Answer), len(tc.Answer))
- t.Logf("%v\n", resp)
- continue
- }
- if len(resp.Ns) != len(tc.Ns) {
- t.Errorf("authority for %q contained %d results, %d expected", tc.Qname, len(resp.Ns), len(tc.Ns))
- t.Logf("%v\n", resp)
- continue
- }
- if len(resp.Extra) != len(tc.Extra) {
- t.Errorf("additional for %q contained %d results, %d expected", tc.Qname, len(resp.Extra), len(tc.Extra))
- t.Logf("%v\n", resp)
- continue
- }
-
- if !coretest.CheckSection(t, tc, coretest.Answer, resp.Answer) {
+ if !coretest.Section(t, tc, coretest.Answer, resp.Answer) {
t.Logf("%v\n", resp)
}
- if !coretest.CheckSection(t, tc, coretest.Ns, resp.Ns) {
+ if !coretest.Section(t, tc, coretest.Ns, resp.Ns) {
t.Logf("%v\n", resp)
-
}
- if !coretest.CheckSection(t, tc, coretest.Extra, resp.Extra) {
+ if !coretest.Section(t, tc, coretest.Extra, resp.Extra) {
t.Logf("%v\n", resp)
}
}
diff --git a/middleware/etcd/setup_test.go b/middleware/etcd/setup_test.go
index acc062f1d..8fbfd1b5f 100644
--- a/middleware/etcd/setup_test.go
+++ b/middleware/etcd/setup_test.go
@@ -18,7 +18,6 @@ import (
coretest "github.com/miekg/coredns/middleware/testing"
etcdc "github.com/coreos/etcd/client"
- "github.com/miekg/dns"
"golang.org/x/net/context"
)
@@ -79,36 +78,17 @@ func TestLookup(t *testing.T) {
sort.Sort(coretest.RRSet(resp.Ns))
sort.Sort(coretest.RRSet(resp.Extra))
- if resp.Rcode != tc.Rcode {
- t.Errorf("rcode is %q, expected %q", dns.RcodeToString[resp.Rcode], dns.RcodeToString[tc.Rcode])
+ if !coretest.Header(t, tc, resp) {
t.Logf("%v\n", resp)
continue
}
-
- if len(resp.Answer) != len(tc.Answer) {
- t.Errorf("answer for %q contained %d results, %d expected", tc.Qname, len(resp.Answer), len(tc.Answer))
- t.Logf("%v\n", resp)
- continue
- }
- if len(resp.Ns) != len(tc.Ns) {
- t.Errorf("authority for %q contained %d results, %d expected", tc.Qname, len(resp.Ns), len(tc.Ns))
- t.Logf("%v\n", resp)
- continue
- }
- if len(resp.Extra) != len(tc.Extra) {
- t.Errorf("additional for %q contained %d results, %d expected", tc.Qname, len(resp.Extra), len(tc.Extra))
- t.Logf("%v\n", resp)
- continue
- }
-
- if !coretest.CheckSection(t, tc, coretest.Answer, resp.Answer) {
+ if !coretest.Section(t, tc, coretest.Answer, resp.Answer) {
t.Logf("%v\n", resp)
}
- if !coretest.CheckSection(t, tc, coretest.Ns, resp.Ns) {
+ if !coretest.Section(t, tc, coretest.Ns, resp.Ns) {
t.Logf("%v\n", resp)
-
}
- if !coretest.CheckSection(t, tc, coretest.Extra, resp.Extra) {
+ if !coretest.Section(t, tc, coretest.Extra, resp.Extra) {
t.Logf("%v\n", resp)
}
}
diff --git a/middleware/etcd/stub_test.go b/middleware/etcd/stub_test.go
index 789809a50..37bd840a7 100644
--- a/middleware/etcd/stub_test.go
+++ b/middleware/etcd/stub_test.go
@@ -5,6 +5,7 @@ package etcd
import "testing"
func TestStubLookup(t *testing.T) {
+ // MOVE THIS TO etcd_Test.go in the main directory
// e.updateStubZones()
}
diff --git a/middleware/file/wildcard_test.go b/middleware/file/wildcard_test.go
index 703938a4e..896889208 100644
--- a/middleware/file/wildcard_test.go
+++ b/middleware/file/wildcard_test.go
@@ -73,7 +73,6 @@ func TestLookupWildcard(t *testing.T) {
t.Logf("%v\n", resp)
continue
}
-
if !coretest.Section(t, tc, coretest.Answer, resp.Answer) {
t.Logf("%v\n", resp)
}