mw/kubernetes: move fallthrough tests out (#1008)

* mw/kubernetes: move fallthrough tests out

Remove the testcase duplication and put fallthrough tests in separate
file.

Also make some names shorter and more descriptive.

* fix test build

* fix corefile
This commit is contained in:
Miek Gieben 2017-09-01 08:53:42 +02:00 committed by GitHub
parent a08a4beec4
commit 7d47af4f06
2 changed files with 85 additions and 346 deletions

View file

@ -0,0 +1,75 @@
// +build k8s
package test
import (
"io/ioutil"
"log"
"os"
"testing"
"github.com/coredns/coredns/middleware/test"
"github.com/miekg/dns"
)
func init() {
log.SetOutput(ioutil.Discard)
}
var dnsTestCasesFallthrough = []test.Case{
{
Qname: "ext-svc.test-1.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.A("example.net. 303 IN A 13.14.15.16"),
test.CNAME("ext-svc.test-1.svc.cluster.local. 303 IN CNAME example.net."),
},
},
{
Qname: "f.b.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.A("f.b.svc.cluster.local. 303 IN A 10.10.10.11"),
},
Ns: []dns.RR{
test.NS("cluster.local. 303 IN NS a.iana-servers.net."),
test.NS("cluster.local. 303 IN NS b.iana-servers.net."),
},
},
{
Qname: "foo.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.A("foo.cluster.local. 303 IN A 10.10.10.10"),
},
Ns: []dns.RR{
test.NS("cluster.local. 303 IN NS a.iana-servers.net."),
test.NS("cluster.local. 303 IN NS b.iana-servers.net."),
},
},
}
func TestKubernetesFallthrough(t *testing.T) {
dbfile, rmFunc, err := TempFile(os.TempDir(), clusterLocal)
if err != nil {
t.Fatalf("Could not create zonefile for fallthrough server: %s", err)
}
defer rmFunc()
rmFunc, upstream, udp := upstreamServer(t)
defer upstream.Stop()
defer rmFunc()
corefile :=
`.:0 {
file ` + dbfile + ` cluster.local
kubernetes cluster.local {
endpoint http://localhost:8080
namespaces test-1
upstream ` + udp + `
fallthrough
}
`
doIntegrationTests(t, corefile, dnsTestCasesFallthrough)
}

View file

@ -270,309 +270,6 @@ var dnsTestCases = []test.Case{
test.TXT(`dns-version.cluster.local. 303 IN TXT "1.0.1"`), test.TXT(`dns-version.cluster.local. 303 IN TXT "1.0.1"`),
}, },
}, },
{
Qname: "ext-svc.test-1.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.A("example.net. 303 IN A 13.14.15.16"),
test.CNAME("ext-svc.test-1.svc.cluster.local. 303 IN CNAME example.net."),
},
},
{
Qname: "ext-svc.test-1.svc.cluster.local.", Qtype: dns.TypeCNAME,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.CNAME("ext-svc.test-1.svc.cluster.local. 303 IN CNAME example.net."),
},
},
}
var dnsTestCasesFallthrough = []test.Case{
{
Qname: "svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.A("svc-1-a.test-1.svc.cluster.local. 303 IN A 10.0.0.100"),
},
},
{
Qname: "bogusservice.test-1.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeNameError,
Ns: []dns.RR{
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
},
},
{
Qname: "bogusendpoint.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeNameError,
Ns: []dns.RR{
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
},
},
{
Qname: "bogusendpoint.headless-svc.test-1.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeNameError,
Ns: []dns.RR{
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
},
},
{
Qname: "svc-1-a.*.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.A("svc-1-a.*.svc.cluster.local. 303 IN A 10.0.0.100"),
},
},
{
Qname: "svc-1-a.any.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.A("svc-1-a.any.svc.cluster.local. 303 IN A 10.0.0.100"),
},
},
{
Qname: "bogusservice.*.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeNameError,
Ns: []dns.RR{
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
},
},
{
Qname: "bogusservice.any.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeNameError,
Ns: []dns.RR{
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
},
},
{
Qname: "*.test-1.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeSuccess,
Answer: append([]dns.RR{
test.A("*.test-1.svc.cluster.local. 303 IN A 10.0.0.100"),
test.A("*.test-1.svc.cluster.local. 303 IN A 10.0.0.110"),
test.A("*.test-1.svc.cluster.local. 303 IN A 10.0.0.115"),
test.CNAME("*.test-1.svc.cluster.local. 303 IN CNAME example.net."),
test.A("example.net. 303 IN A 13.14.15.16"),
}, headlessAResponse("*.test-1.svc.cluster.local.", "headless-svc", "test-1")...),
},
{
Qname: "any.test-1.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeSuccess,
Answer: append([]dns.RR{
test.A("any.test-1.svc.cluster.local. 303 IN A 10.0.0.100"),
test.A("any.test-1.svc.cluster.local. 303 IN A 10.0.0.110"),
test.A("any.test-1.svc.cluster.local. 303 IN A 10.0.0.115"),
test.CNAME("any.test-1.svc.cluster.local. 303 IN CNAME example.net."),
test.A("example.net. 303 IN A 13.14.15.16"),
}, headlessAResponse("any.test-1.svc.cluster.local.", "headless-svc", "test-1")...),
},
{
Qname: "any.test-2.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeNameError,
Ns: []dns.RR{
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
},
},
{
Qname: "*.test-2.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeNameError,
Ns: []dns.RR{
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
},
},
{
Qname: "*.*.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeSuccess,
Answer: append([]dns.RR{
test.A("*.*.svc.cluster.local. 303 IN A 10.0.0.100"),
test.A("*.*.svc.cluster.local. 303 IN A 10.0.0.110"),
test.A("*.*.svc.cluster.local. 303 IN A 10.0.0.115"),
test.CNAME("*.*.svc.cluster.local. 303 IN CNAME example.net."),
test.A("example.net. 303 IN A 13.14.15.16"),
}, headlessAResponse("*.*.svc.cluster.local.", "headless-svc", "test-1")...),
},
{
Qname: "headless-svc.test-1.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeSuccess,
Answer: headlessAResponse("headless-svc.test-1.svc.cluster.local.", "headless-svc", "test-1"),
},
{
Qname: "*._TcP.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.SRV("*._TcP.svc-1-a.test-1.svc.cluster.local. 303 IN SRV 0 50 443 svc-1-a.test-1.svc.cluster.local."),
test.SRV("*._TcP.svc-1-a.test-1.svc.cluster.local. 303 IN SRV 0 50 80 svc-1-a.test-1.svc.cluster.local."),
},
Extra: []dns.RR{
test.A("svc-1-a.test-1.svc.cluster.local. 303 IN A 10.0.0.100"),
},
},
{
Qname: "*.*.bogusservice.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
Rcode: dns.RcodeNameError,
Ns: []dns.RR{
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
},
},
{
Qname: "*.any.svc-1-a.*.svc.cluster.local.", Qtype: dns.TypeSRV,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.SRV("*.any.svc-1-a.*.svc.cluster.local. 303 IN SRV 0 50 443 svc-1-a.test-1.svc.cluster.local."),
test.SRV("*.any.svc-1-a.*.svc.cluster.local. 303 IN SRV 0 50 80 svc-1-a.test-1.svc.cluster.local."),
},
Extra: []dns.RR{
test.A("svc-1-a.test-1.svc.cluster.local. 303 IN A 10.0.0.100"),
},
},
{
Qname: "ANY.*.svc-1-a.any.svc.cluster.local.", Qtype: dns.TypeSRV,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.SRV("ANY.*.svc-1-a.any.svc.cluster.local. 303 IN SRV 0 50 443 svc-1-a.test-1.svc.cluster.local."),
test.SRV("ANY.*.svc-1-a.any.svc.cluster.local. 303 IN SRV 0 50 80 svc-1-a.test-1.svc.cluster.local."),
},
Extra: []dns.RR{
test.A("svc-1-a.test-1.svc.cluster.local. 303 IN A 10.0.0.100"),
},
},
{
Qname: "*.*.bogusservice.*.svc.cluster.local.", Qtype: dns.TypeSRV,
Rcode: dns.RcodeNameError,
Ns: []dns.RR{
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
},
},
{
Qname: "*.*.bogusservice.any.svc.cluster.local.", Qtype: dns.TypeSRV,
Rcode: dns.RcodeNameError,
Ns: []dns.RR{
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
},
},
{
Qname: "_c-port._UDP.*.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
Rcode: dns.RcodeSuccess,
Answer: append(srvResponse("_c-port._UDP.*.test-1.svc.cluster.local.", dns.TypeSRV, "headless-svc", "test-1"),
[]dns.RR{
test.SRV("_c-port._UDP.*.test-1.svc.cluster.local. 303 IN SRV 0 33 1234 svc-c.test-1.svc.cluster.local.")}...),
Extra: append(srvResponse("_c-port._UDP.*.test-1.svc.cluster.local.", dns.TypeA, "headless-svc", "test-1"),
[]dns.RR{
test.A("svc-c.test-1.svc.cluster.local. 303 IN A 10.0.0.115"),
}...),
},
{
Qname: "*._tcp.any.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.SRV("*._tcp.any.test-1.svc.cluster.local. 303 IN SRV 0 33 443 svc-1-a.test-1.svc.cluster.local."),
test.SRV("*._tcp.any.test-1.svc.cluster.local. 303 IN SRV 0 33 80 svc-1-a.test-1.svc.cluster.local."),
test.SRV("*._tcp.any.test-1.svc.cluster.local. 303 IN SRV 0 33 80 svc-1-b.test-1.svc.cluster.local."),
},
Extra: []dns.RR{
test.A("svc-1-a.test-1.svc.cluster.local. 303 IN A 10.0.0.100"),
test.A("svc-1-b.test-1.svc.cluster.local. 303 IN A 10.0.0.110"),
},
},
{
Qname: "*.*.any.test-2.svc.cluster.local.", Qtype: dns.TypeSRV,
Rcode: dns.RcodeNameError,
Ns: []dns.RR{
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
},
},
{
Qname: "*.*.*.test-2.svc.cluster.local.", Qtype: dns.TypeSRV,
Rcode: dns.RcodeNameError,
Ns: []dns.RR{
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
},
},
{
Qname: "_http._tcp.*.*.svc.cluster.local.", Qtype: dns.TypeSRV,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.SRV("_http._tcp.*.*.svc.cluster.local. 303 IN SRV 0 50 80 svc-1-a.test-1.svc.cluster.local."),
test.SRV("_http._tcp.*.*.svc.cluster.local. 303 IN SRV 0 50 80 svc-1-b.test-1.svc.cluster.local."),
},
Extra: []dns.RR{
test.A("svc-1-a.test-1.svc.cluster.local. 303 IN A 10.0.0.100"),
test.A("svc-1-b.test-1.svc.cluster.local. 303 IN A 10.0.0.110"),
},
},
{
Qname: "*.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
Rcode: dns.RcodeSuccess,
Answer: srvResponse("*.svc-1-a.test-1.svc.cluster.local.", dns.TypeSRV, "svc-1-a", "test-1"),
Extra: srvResponse("*.svc-1-a.test-1.svc.cluster.local.", dns.TypeA, "svc-1-a", "test-1"),
},
{
Qname: "*._not-udp-or-tcp.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
Rcode: dns.RcodeNameError,
Ns: []dns.RR{
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
},
},
{
Qname: "svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.SRV("svc-1-a.test-1.svc.cluster.local. 303 IN SRV 0 50 443 svc-1-a.test-1.svc.cluster.local."),
test.SRV("svc-1-a.test-1.svc.cluster.local. 303 IN SRV 0 50 80 svc-1-a.test-1.svc.cluster.local."),
},
Extra: []dns.RR{
test.A("svc-1-a.test-1.svc.cluster.local. 303 IN A 10.0.0.100"),
},
},
{
Qname: "10-20-0-101.test-1.pod.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeServerFailure,
Answer: []dns.RR{},
},
{
Qname: "dns-version.cluster.local.", Qtype: dns.TypeTXT,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.TXT("dns-version.cluster.local. 28800 IN TXT \"1.0.1\""),
},
},
{
Qname: "ext-svc.test-1.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.A("example.net. 303 IN A 13.14.15.16"),
test.CNAME("ext-svc.test-1.svc.cluster.local. 303 IN CNAME example.net."),
},
},
{
Qname: "ext-svc.test-1.svc.cluster.local.", Qtype: dns.TypeCNAME,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.CNAME("ext-svc.test-1.svc.cluster.local. 303 IN CNAME example.net."),
},
},
{
Qname: "f.b.svc.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.A("f.b.svc.cluster.local. 303 IN A 10.10.10.11"),
},
Ns: []dns.RR{
test.NS("cluster.local. 303 IN NS a.iana-servers.net."),
test.NS("cluster.local. 303 IN NS b.iana-servers.net."),
},
},
{
Qname: "foo.cluster.local.", Qtype: dns.TypeA,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.A("foo.cluster.local. 303 IN A 10.10.10.10"),
},
Ns: []dns.RR{
test.NS("cluster.local. 303 IN NS a.iana-servers.net."),
test.NS("cluster.local. 303 IN NS b.iana-servers.net."),
},
},
} }
func doIntegrationTests(t *testing.T, corefile string, testCases []test.Case) { func doIntegrationTests(t *testing.T, corefile string, testCases []test.Case) {
@ -605,29 +302,26 @@ func doIntegrationTests(t *testing.T, corefile string, testCases []test.Case) {
} }
} }
func createUpstreamServer(t *testing.T) (func(), *caddy.Instance, string) { func upstreamServer(t *testing.T) (func(), *caddy.Instance, string) {
upfile, rmfile, err := TempFile(os.TempDir(), exampleNet) upfile, rmFunc, err := TempFile(os.TempDir(), exampleNet)
if err != nil { if err != nil {
t.Fatalf("Could not create file for CNAME upstream lookups: %s", err) t.Fatalf("Could not create file for CNAME upstream lookups: %s", err)
} }
upstreamServerCorefile := `.:0 { upstreamCorefile := `.:0 {
file ` + upfile + ` example.net file ` + upfile + ` example.net
erratic . { }`
drop 0 server, udp, _, err := CoreDNSServerAndPorts(upstreamCorefile)
}
`
server, udp, _, err := CoreDNSServerAndPorts(upstreamServerCorefile)
if err != nil { if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err) t.Fatalf("Could not get CoreDNS serving instance: %s", err)
} }
return rmfile, server, udp return rmFunc, server, udp
} }
func TestKubernetesIntegration(t *testing.T) { func TestKubernetes(t *testing.T) {
removeUpstreamConfig, upstreamServer, udp := createUpstreamServer(t) rmFunc, upstream, udp := upstreamServer(t)
defer upstreamServer.Stop() defer upstream.Stop()
defer removeUpstreamConfig() defer rmFunc()
corefile := corefile :=
`.:0 { `.:0 {
@ -637,40 +331,10 @@ func TestKubernetesIntegration(t *testing.T) {
pods disabled pods disabled
upstream ` + udp + ` upstream ` + udp + `
} }
erratic . {
drop 0
}
` `
doIntegrationTests(t, corefile, dnsTestCases) doIntegrationTests(t, corefile, dnsTestCases)
} }
func TestKubernetesIntegrationFallthrough(t *testing.T) {
dbfile, rmFunc, err := TempFile(os.TempDir(), clusterLocal)
if err != nil {
t.Fatalf("Could not create TempFile for fallthrough: %s", err)
}
defer rmFunc()
removeUpstreamConfig, upstreamServer, udp := createUpstreamServer(t)
defer upstreamServer.Stop()
defer removeUpstreamConfig()
corefile :=
`.:0 {
file ` + dbfile + ` cluster.local
kubernetes cluster.local {
endpoint http://localhost:8080
namespaces test-1
upstream ` + udp + `
fallthrough
}
erratic {
drop 0
}
`
doIntegrationTests(t, corefile, dnsTestCasesFallthrough)
}
// headlessAResponse returns the answer to an A request for the specific name and namespace. // headlessAResponse returns the answer to an A request for the specific name and namespace.
func headlessAResponse(qname, namespace, name string) []dns.RR { func headlessAResponse(qname, namespace, name string) []dns.RR {
rr := []dns.RR{} rr := []dns.RR{}