aboutsummaryrefslogtreecommitdiff
path: root/plugin/cache/setup_test.go
diff options
context:
space:
mode:
authorGravatar Chris O'Haver <cohaver@infoblox.com> 2022-06-17 15:48:57 -0400
committerGravatar GitHub <noreply@github.com> 2022-06-17 15:48:57 -0400
commitdded10420b8a477ebd86cd2ceed9207a42c226cc (patch)
tree6b0679260b212428c74a3fbdc6ee3013d6460e0b /plugin/cache/setup_test.go
parentd60ce0c8d4fd647e880a118f469e8239d6effc7d (diff)
downloadcoredns-dded10420b8a477ebd86cd2ceed9207a42c226cc.tar.gz
coredns-dded10420b8a477ebd86cd2ceed9207a42c226cc.tar.zst
coredns-dded10420b8a477ebd86cd2ceed9207a42c226cc.zip
plugin/cache: Add option to adjust SERVFAIL response cache TTL (#5320)
* add servfail cache opt Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
Diffstat (limited to 'plugin/cache/setup_test.go')
-rw-r--r--plugin/cache/setup_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/plugin/cache/setup_test.go b/plugin/cache/setup_test.go
index 675147d1b..5e684c510 100644
--- a/plugin/cache/setup_test.go
+++ b/plugin/cache/setup_test.go
@@ -155,3 +155,40 @@ func TestServeStale(t *testing.T) {
}
}
}
+
+func TestServfail(t *testing.T) {
+ tests := []struct {
+ input string
+ shouldErr bool
+ failttl time.Duration
+ }{
+ {"servfail 1s", false, 1 * time.Second},
+ {"servfail 5m", false, 5 * time.Minute},
+ {"servfail 0s", false, 0},
+ {"servfail 0", false, 0},
+ // fails
+ {"servfail", true, minNTTL},
+ {"servfail 6m", true, minNTTL},
+ {"servfail 20", true, minNTTL},
+ {"servfail -1s", true, minNTTL},
+ {"servfail aa", true, minNTTL},
+ {"servfail 1m invalid", true, minNTTL},
+ }
+ for i, test := range tests {
+ c := caddy.NewTestController("dns", fmt.Sprintf("cache {\n%s\n}", test.input))
+ ca, err := cacheParse(c)
+ if test.shouldErr && err == nil {
+ t.Errorf("Test %v: Expected error but found nil", i)
+ continue
+ } else if !test.shouldErr && err != nil {
+ t.Errorf("Test %v: Expected no error but found error: %v", i, err)
+ continue
+ }
+ if test.shouldErr && err != nil {
+ continue
+ }
+ if ca.failttl != test.failttl {
+ t.Errorf("Test %v: Expected stale %v but found: %v", i, test.failttl, ca.staleUpTo)
+ }
+ }
+}