diff options
author | 2022-07-28 10:51:08 -0400 | |
---|---|---|
committer | 2022-07-28 10:51:08 -0400 | |
commit | 95fcf2c480b7ab6a291d97520d0d93296ddfdb6f (patch) | |
tree | 3f4b316b400ad41abea13e3d2d00dcffcf1a4fb0 /plugin/cache/setup_test.go | |
parent | 2fe5273cd12562aca6939540f0a9e03b51d34aba (diff) | |
download | coredns-95fcf2c480b7ab6a291d97520d0d93296ddfdb6f.tar.gz coredns-95fcf2c480b7ab6a291d97520d0d93296ddfdb6f.tar.zst coredns-95fcf2c480b7ab6a291d97520d0d93296ddfdb6f.zip |
plugin/cache: Add cache disable option (#5540)
* add cache disable options
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
Diffstat (limited to 'plugin/cache/setup_test.go')
-rw-r--r-- | plugin/cache/setup_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/plugin/cache/setup_test.go b/plugin/cache/setup_test.go index 5e684c510..5d8b9653c 100644 --- a/plugin/cache/setup_test.go +++ b/plugin/cache/setup_test.go @@ -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) + } + } +} |