diff options
author | 2022-09-08 14:56:27 -0400 | |
---|---|---|
committer | 2022-09-08 14:56:27 -0400 | |
commit | b56b080a7c1125cd97c0a2edd7ae21bc1bdcd2a5 (patch) | |
tree | 1494a9542db6d6f69db39113734c8518a6701daf /plugin/view/setup_test.go | |
parent | 1f0a41a66597cb8ab4aace8ea5b5bad880bcd23b (diff) | |
download | coredns-b56b080a7c1125cd97c0a2edd7ae21bc1bdcd2a5.tar.gz coredns-b56b080a7c1125cd97c0a2edd7ae21bc1bdcd2a5.tar.zst coredns-b56b080a7c1125cd97c0a2edd7ae21bc1bdcd2a5.zip |
plugin/view: Advanced routing interface and new 'view' plugin (#5538)
* introduce new interface "dnsserver.Viewer", that allows a plugin implementing it to decide if a query should be routed into its server block.
* add new plugin "view", that uses the new interface to enable a user to define expression based conditions that must be met for a query to be routed to its server block.
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
Diffstat (limited to 'plugin/view/setup_test.go')
-rw-r--r-- | plugin/view/setup_test.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/plugin/view/setup_test.go b/plugin/view/setup_test.go new file mode 100644 index 000000000..7c7838070 --- /dev/null +++ b/plugin/view/setup_test.go @@ -0,0 +1,38 @@ +package view + +import ( + "testing" + + "github.com/coredns/caddy" +) + +func TestSetup(t *testing.T) { + tests := []struct { + input string + shouldErr bool + progCount int + }{ + {"view example {\n expr name() == 'example.com.'\n}", false, 1}, + {"view example {\n expr incidr(client_ip(), '10.0.0.0/24')\n}", false, 1}, + {"view example {\n expr name() == 'example.com.'\n expr name() == 'example2.com.'\n}", false, 2}, + {"view", true, 0}, + {"view example {\n expr invalid expression\n}", true, 0}, + } + + for i, test := range tests { + v, err := parse(caddy.NewTestController("dns", test.input)) + + if test.shouldErr && err == nil { + t.Errorf("Test %d: Expected error but found none for input %s", i, test.input) + } + if err != nil && !test.shouldErr { + t.Errorf("Test %d: Expected no error but found one for input %s. Error was: %v", i, test.input, err) + } + if test.shouldErr { + continue + } + if test.progCount != len(v.progs) { + t.Errorf("Test %d: Expected prog length %d, but got %d for %s.", i, test.progCount, len(v.progs), test.input) + } + } +} |