aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Chris O'Haver <cohaver@infoblox.com> 2018-10-16 09:24:40 -0400
committerGravatar Yong Tang <yong.tang.github@outlook.com> 2018-10-16 06:24:40 -0700
commit4a5641c3793a750c1a0323f09678f3429b9b5649 (patch)
tree19070cdef66f87d98ed341d67656f2dc1860dcac /test
parent8cc8afa96a9cabe132417368e10aaa138e0b8aae (diff)
downloadcoredns-4a5641c3793a750c1a0323f09678f3429b9b5649.tar.gz
coredns-4a5641c3793a750c1a0323f09678f3429b9b5649.tar.zst
coredns-4a5641c3793a750c1a0323f09678f3429b9b5649.zip
plugin/cache: Set min TTL default to zero (#2199)
* set min ttl default to zero * add short TTL test case
Diffstat (limited to 'test')
-rw-r--r--test/cache_test.go23
-rw-r--r--test/example_test.go1
2 files changed, 18 insertions, 6 deletions
diff --git a/test/cache_test.go b/test/cache_test.go
index 6271d5c14..191035b5f 100644
--- a/test/cache_test.go
+++ b/test/cache_test.go
@@ -43,17 +43,28 @@ func TestLookupCache(t *testing.T) {
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
- resp, err := p.Lookup(state, "example.org.", dns.TypeA)
+ t.Run("Long TTL", func(t *testing.T) {
+ testCase(t, state, p, "example.org.", 2, 10)
+ })
+
+ t.Run("Short TTL", func(t *testing.T) {
+ testCase(t, state, p, "short.example.org.", 1, 1)
+ })
+
+}
+
+func testCase(t *testing.T, state request.Request, p proxy.Proxy, name string, expectAnsLen int, expectTTL uint32) {
+ resp, err := p.Lookup(state, name, dns.TypeA)
if err != nil {
t.Fatal("Expected to receive reply, but didn't")
}
- // expect answer section with A record in it
- if len(resp.Answer) == 0 {
- t.Fatal("Expected to at least one RR in the answer section, got none")
+
+ if len(resp.Answer) != expectAnsLen {
+ t.Fatalf("Expected %v RR in the answer section, got %v.", expectAnsLen, len(resp.Answer))
}
ttl := resp.Answer[0].Header().Ttl
- if ttl != 10 { // as set in the Corefile
- t.Errorf("Expected TTL to be %d, got %d", 10, ttl)
+ if ttl != expectTTL {
+ t.Errorf("Expected TTL to be %d, got %d", expectTTL, ttl)
}
}
diff --git a/test/example_test.go b/test/example_test.go
index 39d4ec49c..484cc67d7 100644
--- a/test/example_test.go
+++ b/test/example_test.go
@@ -7,6 +7,7 @@ example.org. IN NS b.iana-servers.net.
example.org. IN NS a.iana-servers.net.
example.org. IN A 127.0.0.1
example.org. IN A 127.0.0.2
+short.example.org. 1 IN A 127.0.0.3
*.w.example.org. IN TXT "Wildcard"
a.b.c.w.example.org. IN TXT "Not a wildcard"
cname.example.org. IN CNAME www.example.net.