diff options
author | 2021-07-15 09:32:39 +0200 | |
---|---|---|
committer | 2021-07-15 09:32:39 +0200 | |
commit | 00128bda4e2fa56ec4bf66e321bf3e00263d1188 (patch) | |
tree | 777af2d1db0a5133046f00e38eb41de98685fa91 /plugin/header/setup_test.go | |
parent | faa10f61aff9cce538375586b71a9bdd0fab6422 (diff) | |
download | coredns-00128bda4e2fa56ec4bf66e321bf3e00263d1188.tar.gz coredns-00128bda4e2fa56ec4bf66e321bf3e00263d1188.tar.zst coredns-00128bda4e2fa56ec4bf66e321bf3e00263d1188.zip |
plugin/header: Introduce header plugin (#4752)
* Add header plugin
Signed-off-by: MQasimSarfraz <syed.qasim.sarfraz@gmail.com>
* fix import format
* improve README.md
* Add codeowners for header plugin
Diffstat (limited to '')
-rw-r--r-- | plugin/header/setup_test.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/plugin/header/setup_test.go b/plugin/header/setup_test.go new file mode 100644 index 000000000..a8570cc2e --- /dev/null +++ b/plugin/header/setup_test.go @@ -0,0 +1,53 @@ +package header + +import ( + "strings" + "testing" + + "github.com/coredns/caddy" +) + +func TestSetupHeader(t *testing.T) { + tests := []struct { + input string + shouldErr bool + expectedErrContent string + }{ + {`header {}`, true, "Wrong argument count or unexpected line ending after"}, + {`header { + set +}`, true, "invalid length for flags, at least one should be provided"}, + {`header { + foo +}`, true, "invalid length for flags, at least one should be provided"}, + {`header { + foo bar +}`, true, "unknown flag action=foo, should be set or clear"}, + {`header { + set ra +}`, false, ""}, + {`header { + set ra aa + clear rd +}`, false, ""}, + } + + for i, test := range tests { + c := caddy.NewTestController("dns", test.input) + err := setup(c) + + if test.shouldErr && err == nil { + t.Errorf("Test %d: Expected error but found none for input %s", i, test.input) + } + + if err != nil { + if !test.shouldErr { + t.Errorf("Test %d: Expected no error but found one for input %s. Error was: %v", i, test.input, err) + } + + if !strings.Contains(err.Error(), test.expectedErrContent) { + t.Errorf("Test %d: Expected error to contain: %v, found error: %v, input: %s", i, test.expectedErrContent, err, test.input) + } + } + } +} |