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.
This commit is contained in:
parent
4c6c9d4b27
commit
b42eae7a04
5 changed files with 111 additions and 31 deletions
22
plugin/cache/cache_test.go
vendored
22
plugin/cache/cache_test.go
vendored
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue