diff options
Diffstat (limited to 'plugin/cache/cache_test.go')
-rw-r--r-- | plugin/cache/cache_test.go | 22 |
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) + } + } +} |