aboutsummaryrefslogtreecommitdiff
path: root/plugin/cache/cache_test.go
diff options
context:
space:
mode:
authorGravatar Aaron Riekenberg <aaron.riekenberg@gmail.com> 2018-09-03 14:26:02 -0500
committerGravatar Tobias Schmidt <tobidt@gmail.com> 2018-09-03 21:26:02 +0200
commitb42eae7a04b8f789d7a20c0664895cd8e4638a22 (patch)
treece3c4fe568fda2368e9c103451d6c4364ac1e349 /plugin/cache/cache_test.go
parent4c6c9d4b2700c3e4606d4b98bde64e7c1ed0c231 (diff)
downloadcoredns-b42eae7a04b8f789d7a20c0664895cd8e4638a22.tar.gz
coredns-b42eae7a04b8f789d7a20c0664895cd8e4638a22.tar.zst
coredns-b42eae7a04b8f789d7a20c0664895cd8e4638a22.zip
Add MINTTL parameter to cache configuration. (#2055)
* Add success min TTL parameter to cache. * Add MINTTL to README. * Update README. * Add MINTTL to negative cache. * Remove unnecessary variable name. * Address review comments. * Configure cache in TestCacheZeroTTL to have 0 min ttl.
Diffstat (limited to 'plugin/cache/cache_test.go')
-rw-r--r--plugin/cache/cache_test.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/plugin/cache/cache_test.go b/plugin/cache/cache_test.go
index 08ff667a7..6ef8c8c3a 100644
--- a/plugin/cache/cache_test.go
+++ b/plugin/cache/cache_test.go
@@ -205,6 +205,8 @@ func TestCache(t *testing.T) {
func TestCacheZeroTTL(t *testing.T) {
c := New()
+ c.minpttl = 0
+ c.minnttl = 0
c.Next = zeroTTLBackend()
req := new(dns.Msg)
@@ -270,3 +272,23 @@ func zeroTTLBackend() plugin.Handler {
return dns.RcodeSuccess, nil
})
}
+
+func TestComputeTTL(t *testing.T) {
+ tests := []struct {
+ msgTTL time.Duration
+ minTTL time.Duration
+ maxTTL time.Duration
+ expectedTTL time.Duration
+ }{
+ {1800 * time.Second, 300 * time.Second, 3600 * time.Second, 1800 * time.Second},
+ {299 * time.Second, 300 * time.Second, 3600 * time.Second, 300 * time.Second},
+ {299 * time.Second, 0 * time.Second, 3600 * time.Second, 299 * time.Second},
+ {3601 * time.Second, 300 * time.Second, 3600 * time.Second, 3600 * time.Second},
+ }
+ for i, test := range tests {
+ ttl := computeTTL(test.msgTTL, test.minTTL, test.maxTTL)
+ if ttl != test.expectedTTL {
+ t.Errorf("Test %v: Expected ttl %v but found: %v", i, test.expectedTTL, ttl)
+ }
+ }
+}