mirror of
https://github.com/coredns/coredns.git
synced 2025-12-06 10:25:10 -05:00
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:
39
plugin/cache/setup_test.go
vendored
39
plugin/cache/setup_test.go
vendored
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user