diff options
author | 2017-08-30 17:04:19 +0200 | |
---|---|---|
committer | 2017-08-30 17:04:19 +0200 | |
commit | 3974071f483f4cc8ae59140eaf4ade7808e3e761 (patch) | |
tree | a496df67a23b82dd7c0484d1335f727d436e5fae /test/kubernetes_pods_test.go | |
parent | 7b8cf9df905a5e5f3fe9918a31edb406d50941d1 (diff) | |
download | coredns-3974071f483f4cc8ae59140eaf4ade7808e3e761.tar.gz coredns-3974071f483f4cc8ae59140eaf4ade7808e3e761.tar.zst coredns-3974071f483f4cc8ae59140eaf4ade7808e3e761.zip |
mw/kubernetes: split integration tests (#1004)
* mw/kubernetes: split integration tests
* separate file and test for api fallthrough, does not need all other
servers to be started.
* more split ups: make it clear when or when not we need an upstream server,
as just needlessly start it in doIntegrationTests.
* use identifiers from dns package -> "TypeSRV" -> dns.TypeSRV, as there
is no need to reinvent these.
* updates
* deploy work-around
* re-add weird sleep
Diffstat (limited to 'test/kubernetes_pods_test.go')
-rw-r--r-- | test/kubernetes_pods_test.go | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/test/kubernetes_pods_test.go b/test/kubernetes_pods_test.go new file mode 100644 index 000000000..933b41dab --- /dev/null +++ b/test/kubernetes_pods_test.go @@ -0,0 +1,108 @@ +package test + +import ( + "testing" + "time" + + "github.com/coredns/coredns/middleware/test" + + "github.com/miekg/dns" +) + +var dnsTestCasesPodsInsecure = []test.Case{ + { + Qname: "10-20-0-101.test-1.pod.cluster.local.", Qtype: dns.TypeA, + Rcode: dns.RcodeSuccess, + Answer: []dns.RR{ + test.A("10-20-0-101.test-1.pod.cluster.local. 303 IN A 10.20.0.101"), + }, + }, + { + Qname: "10-20-0-101.test-X.pod.cluster.local.", Qtype: dns.TypeA, + Rcode: dns.RcodeNameError, + Ns: []dns.RR{ + test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502307903 7200 1800 86400 60"), + }, + }, +} + +func TestKubernetesPodsInsecure(t *testing.T) { + corefile := `.:0 { + kubernetes cluster.local 0.0.10.in-addr.arpa { + endpoint http://localhost:8080 + namespaces test-1 + pods insecure + } +` + + server, udp, _, err := CoreDNSServerAndPorts(corefile) + if err != nil { + t.Fatalf("Could not get CoreDNS serving instance: %s", err) + } + defer server.Stop() + + // Work-around for timing condition that results in no-data being returned in test environment. + time.Sleep(3 * time.Second) + + for _, tc := range dnsTestCasesPodsInsecure { + + c := new(dns.Client) + m := tc.Msg() + + res, _, err := c.Exchange(m, udp) + if err != nil { + t.Fatalf("Could not send query: %s", err) + } + + test.SortAndCheck(t, res, tc) + } +} + +var dnsTestCasesPodsVerified = []test.Case{ + { + Qname: "10-20-0-101.test-1.pod.cluster.local.", Qtype: dns.TypeA, + Rcode: dns.RcodeNameError, + Ns: []dns.RR{ + test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502308197 7200 1800 86400 60"), + }, + }, + { + Qname: "10-20-0-101.test-X.pod.cluster.local.", Qtype: dns.TypeA, + Rcode: dns.RcodeNameError, + Ns: []dns.RR{ + test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502307960 7200 1800 86400 60"), + }, + }, +} + +func TestKubernetesPodsVerified(t *testing.T) { + corefile := `.:0 { + kubernetes cluster.local 0.0.10.in-addr.arpa { + endpoint http://localhost:8080 + namespaces test-1 + pods verified + } +` + + server, udp, _, err := CoreDNSServerAndPorts(corefile) + if err != nil { + t.Fatalf("Could not get CoreDNS serving instance: %s", err) + } + defer server.Stop() + + // Work-around for timing condition that results in no-data being returned in test environment. + time.Sleep(3 * time.Second) + + for _, tc := range dnsTestCasesPodsVerified { + + c := new(dns.Client) + m := tc.Msg() + + res, _, err := c.Exchange(m, udp) + if err != nil { + t.Fatalf("Could not send query: %s", err) + } + + test.SortAndCheck(t, res, tc) + } +} |