aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2017-08-24 11:35:14 +0100
committerGravatar GitHub <noreply@github.com> 2017-08-24 11:35:14 +0100
commitf901b0cefa1475c83e6b6dc859ef35675feb41e1 (patch)
tree93d6d067e1ffe7bb8cea40921d99b5088a12acb8
parentea53f8c21973494d485677ca284116382ab5fa7d (diff)
downloadcoredns-f901b0cefa1475c83e6b6dc859ef35675feb41e1.tar.gz
coredns-f901b0cefa1475c83e6b6dc859ef35675feb41e1.tar.zst
coredns-f901b0cefa1475c83e6b6dc859ef35675feb41e1.zip
tests: CoreDNSServerAndPorts (#972)
* tests: CoreDNSServerAndPorts Copy from kubernetes.go and renamed to fit the style, adapted almost all callers. This is a mechanicl change, no testdata was changed. * typos
-rw-r--r--test/auto_test.go7
-rw-r--r--test/cache_test.go14
-rw-r--r--test/chaos_test.go8
-rw-r--r--test/ds_file_test.go7
-rw-r--r--test/erratic_autopath_test.go7
-rw-r--r--test/etcd_cache_debug_test.go7
-rw-r--r--test/etcd_test.go7
-rw-r--r--test/file_cname_proxy_test.go14
-rw-r--r--test/file_reload_test.go7
-rw-r--r--test/file_srv_additional_test.go7
-rw-r--r--test/grpc_test.go4
-rw-r--r--test/metrics_test.go4
-rw-r--r--test/middleware_dnssec_test.go4
-rw-r--r--test/middleware_test.go3
-rw-r--r--test/proxy_health_test.go7
-rw-r--r--test/proxy_http_health_test.go14
-rw-r--r--test/proxy_test.go14
-rw-r--r--test/reload_test.go2
-rw-r--r--test/reverse_test.go7
-rw-r--r--test/rewrite_test.go6
-rw-r--r--test/secondary_test.go7
-rw-r--r--test/server.go11
-rw-r--r--test/server_test.go7
-rw-r--r--test/wildcard_test.go7
24 files changed, 39 insertions, 143 deletions
diff --git a/test/auto_test.go b/test/auto_test.go
index ed7d4aa9a..b5a9c2b09 100644
--- a/test/auto_test.go
+++ b/test/auto_test.go
@@ -29,15 +29,10 @@ func TestAuto(t *testing.T) {
}
`
- i, err := CoreDNSServer(corefile)
+ i, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
-
- udp, _ := CoreDNSServerPorts(i, 0)
- if udp == "" {
- t.Fatal("Could not get UDP listening port")
- }
defer i.Stop()
log.SetOutput(ioutil.Discard)
diff --git a/test/cache_test.go b/test/cache_test.go
index 43ef29efb..bb5017a24 100644
--- a/test/cache_test.go
+++ b/test/cache_test.go
@@ -26,15 +26,10 @@ func TestLookupCache(t *testing.T) {
file ` + name + `
}
`
- i, err := CoreDNSServer(corefile)
+ i, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
-
- udp, _ := CoreDNSServerPorts(i, 0)
- if udp == "" {
- t.Fatalf("Could not get UDP listening port")
- }
defer i.Stop()
// Start caching proxy CoreDNS that we want to test.
@@ -43,15 +38,10 @@ func TestLookupCache(t *testing.T) {
cache
}
`
- i, err = CoreDNSServer(corefile)
+ i, udp, _, err = CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
-
- udp, _ = CoreDNSServerPorts(i, 0)
- if udp == "" {
- t.Fatalf("Could not get UDP listening port")
- }
defer i.Stop()
log.SetOutput(ioutil.Discard)
diff --git a/test/chaos_test.go b/test/chaos_test.go
index 4f902c841..991b6aa85 100644
--- a/test/chaos_test.go
+++ b/test/chaos_test.go
@@ -18,18 +18,12 @@ func TestChaos(t *testing.T) {
}
`
- i, err := CoreDNSServer(corefile)
+ i, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
- // Stop the server.
defer i.Stop()
- udp, _ := CoreDNSServerPorts(i, 0)
- if udp == "" {
- t.Fatalf("Could not get UDP listening port")
- }
-
log.SetOutput(ioutil.Discard)
m := new(dns.Msg)
diff --git a/test/ds_file_test.go b/test/ds_file_test.go
index 3775c9033..2ec19c5b4 100644
--- a/test/ds_file_test.go
+++ b/test/ds_file_test.go
@@ -43,15 +43,10 @@ func TestLookupDS(t *testing.T) {
}
`
- i, err := CoreDNSServer(corefile)
+ i, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
-
- udp, _ := CoreDNSServerPorts(i, 0)
- if udp == "" {
- t.Fatalf("Could not get UDP listening port")
- }
defer i.Stop()
log.SetOutput(ioutil.Discard)
diff --git a/test/erratic_autopath_test.go b/test/erratic_autopath_test.go
index cd9a077d1..215928b03 100644
--- a/test/erratic_autopath_test.go
+++ b/test/erratic_autopath_test.go
@@ -14,15 +14,10 @@ func TestLookupAutoPathErratic(t *testing.T) {
debug
}
`
- i, err := CoreDNSServer(corefile)
+ i, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
-
- udp, _ := CoreDNSServerPorts(i, 0)
- if udp == "" {
- t.Fatalf("Could not get UDP listening port")
- }
defer i.Stop()
tests := []struct {
diff --git a/test/etcd_cache_debug_test.go b/test/etcd_cache_debug_test.go
index 59fdd8d6b..599e95b5c 100644
--- a/test/etcd_cache_debug_test.go
+++ b/test/etcd_cache_debug_test.go
@@ -27,15 +27,10 @@ func TestEtcdCacheAndDebug(t *testing.T) {
cache skydns.test
}`
- ex, err := CoreDNSServer(corefile)
+ ex, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
-
- udp, _ := CoreDNSServerPorts(ex, 0)
- if udp == "" {
- t.Fatalf("Could not get UDP listening port")
- }
defer ex.Stop()
etc := etcdMiddleware()
diff --git a/test/etcd_test.go b/test/etcd_test.go
index f8a699661..eaab7a730 100644
--- a/test/etcd_test.go
+++ b/test/etcd_test.go
@@ -47,15 +47,10 @@ func TestEtcdStubAndProxyLookup(t *testing.T) {
proxy . 8.8.8.8:53
}`
- ex, err := CoreDNSServer(corefile)
+ ex, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
-
- udp, _ := CoreDNSServerPorts(ex, 0)
- if udp == "" {
- t.Fatalf("Could not get UDP listening port")
- }
defer ex.Stop()
etc := etcdMiddleware()
diff --git a/test/file_cname_proxy_test.go b/test/file_cname_proxy_test.go
index a6ab8e59e..6630abb42 100644
--- a/test/file_cname_proxy_test.go
+++ b/test/file_cname_proxy_test.go
@@ -27,15 +27,10 @@ func TestZoneExternalCNAMELookupWithoutProxy(t *testing.T) {
file ` + name + `
}
`
- i, err := CoreDNSServer(corefile)
+ i, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
-
- udp, _ := CoreDNSServerPorts(i, 0)
- if udp == "" {
- t.Fatalf("Could not get UDP listening port")
- }
defer i.Stop()
p := proxy.NewLookup([]string{udp})
@@ -68,15 +63,10 @@ func TestZoneExternalCNAMELookupWithProxy(t *testing.T) {
}
}
`
- i, err := CoreDNSServer(corefile)
+ i, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
-
- udp, _ := CoreDNSServerPorts(i, 0)
- if udp == "" {
- t.Fatalf("Could not get UDP listening port")
- }
defer i.Stop()
p := proxy.NewLookup([]string{udp})
diff --git a/test/file_reload_test.go b/test/file_reload_test.go
index fd21a73b8..e7ecc4d09 100644
--- a/test/file_reload_test.go
+++ b/test/file_reload_test.go
@@ -32,15 +32,10 @@ example.net:0 {
file ` + name + `
}
`
- i, err := CoreDNSServer(corefile)
+ i, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
-
- udp, _ := CoreDNSServerPorts(i, 0)
- if udp == "" {
- t.Fatalf("Could not get UDP listening port")
- }
defer i.Stop()
p := proxy.NewLookup([]string{udp})
diff --git a/test/file_srv_additional_test.go b/test/file_srv_additional_test.go
index 0fad80758..1925f98c1 100644
--- a/test/file_srv_additional_test.go
+++ b/test/file_srv_additional_test.go
@@ -27,15 +27,10 @@ func TestZoneSRVAdditional(t *testing.T) {
file ` + name + `
}
`
- i, err := CoreDNSServer(corefile)
+ i, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
-
- udp, _ := CoreDNSServerPorts(i, 0)
- if udp == "" {
- t.Fatalf("Could not get UDP listening port")
- }
defer i.Stop()
p := proxy.NewLookup([]string{udp})
diff --git a/test/grpc_test.go b/test/grpc_test.go
index 4795819fb..50d1643fb 100644
--- a/test/grpc_test.go
+++ b/test/grpc_test.go
@@ -20,12 +20,10 @@ func TestGrpc(t *testing.T) {
whoami
}
`
- g, err := CoreDNSServer(corefile)
+ g, _, tcp, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
-
- _, tcp := CoreDNSServerPorts(g, 0)
defer g.Stop()
conn, err := grpc.Dial(tcp, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(5*time.Second))
diff --git a/test/metrics_test.go b/test/metrics_test.go
index 9ed0f2f5a..fa7adee80 100644
--- a/test/metrics_test.go
+++ b/test/metrics_test.go
@@ -45,14 +45,12 @@ func TestMetricsRefused(t *testing.T) {
prometheus localhost:0
}
`
- srv, err := CoreDNSServer(corefile)
+ srv, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
defer srv.Stop()
- udp, _ := CoreDNSServerPorts(srv, 0)
-
m := new(dns.Msg)
m.SetQuestion("google.com.", dns.TypeA)
diff --git a/test/middleware_dnssec_test.go b/test/middleware_dnssec_test.go
index 34df9bb0f..d1dbfc594 100644
--- a/test/middleware_dnssec_test.go
+++ b/test/middleware_dnssec_test.go
@@ -30,12 +30,10 @@ func TestLookupBalanceRewriteCacheDnssec(t *testing.T) {
loadbalance
}
`
- ex, err := CoreDNSServer(corefile)
+ ex, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
-
- udp, _ := CoreDNSServerPorts(ex, 0)
defer ex.Stop()
log.SetOutput(ioutil.Discard)
diff --git a/test/middleware_test.go b/test/middleware_test.go
index 10bd3864c..745d47d7b 100644
--- a/test/middleware_test.go
+++ b/test/middleware_test.go
@@ -25,11 +25,10 @@ func benchmarkLookupBalanceRewriteCache(b *testing.B) {
}
`
- ex, err := CoreDNSServer(corefile)
+ ex, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
- udp, _ := CoreDNSServerPorts(ex, 0)
defer ex.Stop()
log.SetOutput(ioutil.Discard)
diff --git a/test/proxy_health_test.go b/test/proxy_health_test.go
index 5cf168acb..34c2c24c5 100644
--- a/test/proxy_health_test.go
+++ b/test/proxy_health_test.go
@@ -22,15 +22,10 @@ func TestProxyErratic(t *testing.T) {
}
`
- backend, err := CoreDNSServer(corefile)
+ backend, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
-
- udp, _ := CoreDNSServerPorts(backend, 0)
- if udp == "" {
- t.Fatalf("Could not get UDP listening port")
- }
defer backend.Stop()
p := proxy.NewLookup([]string{udp})
diff --git a/test/proxy_http_health_test.go b/test/proxy_http_health_test.go
index b190f2b45..a331083de 100644
--- a/test/proxy_http_health_test.go
+++ b/test/proxy_http_health_test.go
@@ -51,15 +51,10 @@ func TestProxyWithHTTPCheckOK(t *testing.T) {
}
`
- authoritativeInstance, err := CoreDNSServer(authoritativeCorefile)
+ authoritativeInstance, authoritativeAddr, _, err := CoreDNSServerAndPorts(authoritativeCorefile)
if err != nil {
t.Fatalf("Could not get CoreDNS authoritative instance: %s", err)
}
-
- authoritativeAddr, _ := CoreDNSServerPorts(authoritativeInstance, 0)
- if authoritativeAddr == "" {
- t.Fatalf("Could not get CoreDNS authoritative instance UDP listening port")
- }
defer authoritativeInstance.Stop()
proxyCorefile := `example.org:0 {
@@ -70,15 +65,10 @@ func TestProxyWithHTTPCheckOK(t *testing.T) {
}
`
- proxyInstance, err := CoreDNSServer(proxyCorefile)
+ proxyInstance, proxyAddr, _, err := CoreDNSServerAndPorts(proxyCorefile)
if err != nil {
t.Fatalf("Could not get CoreDNS proxy instance: %s", err)
}
-
- proxyAddr, _ := CoreDNSServerPorts(proxyInstance, 0)
- if proxyAddr == "" {
- t.Fatalf("Could not get CoreDNS proxy instance UDP listening port")
- }
defer proxyInstance.Stop()
p := proxy.NewLookup([]string{proxyAddr})
diff --git a/test/proxy_test.go b/test/proxy_test.go
index 1e90048f6..01402ed27 100644
--- a/test/proxy_test.go
+++ b/test/proxy_test.go
@@ -25,15 +25,10 @@ func TestLookupProxy(t *testing.T) {
}
`
- i, err := CoreDNSServer(corefile)
+ i, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
-
- udp, _ := CoreDNSServerPorts(i, 0)
- if udp == "" {
- t.Fatalf("Could not get UDP listening port")
- }
defer i.Stop()
log.SetOutput(ioutil.Discard)
@@ -69,15 +64,10 @@ func TestLookupDnsWithForcedTcp(t *testing.T) {
}
`
- i, err := CoreDNSServer(corefile)
+ i, _, tcp, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
-
- _, tcp := CoreDNSServerPorts(i, 0)
- if tcp == "" {
- t.Fatalf("Could not get TCP listening port")
- }
defer i.Stop()
log.SetOutput(ioutil.Discard)
diff --git a/test/reload_test.go b/test/reload_test.go
index 0f9db5059..61fc76b26 100644
--- a/test/reload_test.go
+++ b/test/reload_test.go
@@ -45,6 +45,6 @@ func send(t *testing.T, server string) {
t.Fatalf("Expected successful reply, got %s", dns.RcodeToString[r.Rcode])
}
if len(r.Extra) != 2 {
- t.Fatalf("Expected 2 RRs in additional, got %d", len(r.Extra))
+ t.Fatalf("Expected 2 RRs in additional, got %s", len(r.Extra))
}
}
diff --git a/test/reverse_test.go b/test/reverse_test.go
index 2a32ed968..25b3d9068 100644
--- a/test/reverse_test.go
+++ b/test/reverse_test.go
@@ -29,16 +29,11 @@ func TestReverseFallthrough(t *testing.T) {
}
`
- i, err := CoreDNSServer(corefile)
+ i, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
- udp, _ := CoreDNSServerPorts(i, 0)
- if udp == "" {
- t.Fatalf("Could not get UDP listening port")
- }
-
log.SetOutput(ioutil.Discard)
p := proxy.NewLookup([]string{udp})
diff --git a/test/rewrite_test.go b/test/rewrite_test.go
index 9aedd7417..0ec3a9a70 100644
--- a/test/rewrite_test.go
+++ b/test/rewrite_test.go
@@ -19,15 +19,11 @@ func TestRewrite(t *testing.T) {
}
}`
- i, err := CoreDNSServer(corefile)
+ i, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
- udp, _ := CoreDNSServerPorts(i, 0)
- if udp == "" {
- t.Fatalf("Could not get UDP listening port")
- }
defer i.Stop()
log.SetOutput(ioutil.Discard)
diff --git a/test/secondary_test.go b/test/secondary_test.go
index dbf410047..b3eed5c1b 100644
--- a/test/secondary_test.go
+++ b/test/secondary_test.go
@@ -21,15 +21,10 @@ func TestEmptySecondaryZone(t *testing.T) {
}
`
- i, err := CoreDNSServer(corefile)
+ i, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
-
- udp, _ := CoreDNSServerPorts(i, 0)
- if udp == "" {
- t.Fatal("Could not get UDP listening port")
- }
defer i.Stop()
log.SetOutput(ioutil.Discard)
diff --git a/test/server.go b/test/server.go
index 61fe8ea15..4a0c200ee 100644
--- a/test/server.go
+++ b/test/server.go
@@ -48,6 +48,17 @@ func CoreDNSServerPorts(i *caddy.Instance, k int) (udp, tcp string) {
return
}
+// CoreDNSServerAndPorts combines CoreDNSServer and CoreDNSServerPorts to start a CoreDNS
+// server and returns the udp and tcp ports of the first instance.
+func CoreDNSServerAndPorts(corefile string) (i *caddy.Instance, udp, tcp string, err error) {
+ i, err = CoreDNSServer(corefile)
+ if err != nil {
+ return nil, "", "", err
+ }
+ udp, tcp = CoreDNSServerPorts(i, 0)
+ return i, udp, tcp, nil
+}
+
// Input implements the caddy.Input interface and acts as an easy way to use a string as a Corefile.
type Input struct {
corefile []byte
diff --git a/test/server_test.go b/test/server_test.go
index b7abc86c3..a0dfed7dd 100644
--- a/test/server_test.go
+++ b/test/server_test.go
@@ -13,24 +13,21 @@ func TestProxyToChaosServer(t *testing.T) {
chaos CoreDNS-001 miek@miek.nl
}
`
- chaos, err := CoreDNSServer(corefile)
+ chaos, udpChaos, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
- udpChaos, _ := CoreDNSServerPorts(chaos, 0)
defer chaos.Stop()
corefileProxy := `.:0 {
proxy . ` + udpChaos + `
}
`
- proxy, err := CoreDNSServer(corefileProxy)
+ proxy, udp, _, err := CoreDNSServerAndPorts(corefileProxy)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance")
}
-
- udp, _ := CoreDNSServerPorts(proxy, 0)
defer proxy.Stop()
chaosTest(t, udpChaos)
diff --git a/test/wildcard_test.go b/test/wildcard_test.go
index a8f103ccc..67feb2e77 100644
--- a/test/wildcard_test.go
+++ b/test/wildcard_test.go
@@ -25,15 +25,10 @@ func TestLookupWildcard(t *testing.T) {
}
`
- i, err := CoreDNSServer(corefile)
+ i, udp, _, err := CoreDNSServerAndPorts(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
-
- udp, _ := CoreDNSServerPorts(i, 0)
- if udp == "" {
- t.Fatalf("Could not get UDP listening port")
- }
defer i.Stop()
log.SetOutput(ioutil.Discard)