plugin/cache: Add cache disable option (#5540)

* add cache disable options

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
This commit is contained in:
Chris O'Haver 2022-07-28 10:51:08 -04:00 committed by GitHub
parent 2fe5273cd1
commit 95fcf2c480
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 158 additions and 3 deletions

View file

@ -192,3 +192,42 @@ func TestServfail(t *testing.T) {
}
}
}
func TestDisable(t *testing.T) {
tests := []struct {
input string
shouldErr bool
nexcept []string
pexcept []string
}{
// positive
{"disable denial example.com example.org", false, []string{"example.com.", "example.org."}, nil},
{"disable success example.com example.org", false, nil, []string{"example.com.", "example.org."}},
{"disable denial", false, []string{"."}, nil},
{"disable success", false, nil, []string{"."}},
{"disable denial example.com example.org\ndisable success example.com example.org", false,
[]string{"example.com.", "example.org."}, []string{"example.com.", "example.org."}},
// negative
{"disable invalid example.com example.org", true, nil, nil},
}
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 {
continue
}
if fmt.Sprintf("%v", test.nexcept) != fmt.Sprintf("%v", ca.nexcept) {
t.Errorf("Test %v: Expected %v but got: %v", i, test.nexcept, ca.nexcept)
}
if fmt.Sprintf("%v", test.pexcept) != fmt.Sprintf("%v", ca.pexcept) {
t.Errorf("Test %v: Expected %v but got: %v", i, test.pexcept, ca.pexcept)
}
}
}