diff options
author | 2018-06-29 12:44:16 +0300 | |
---|---|---|
committer | 2018-06-29 10:44:16 +0100 | |
commit | 17d807f05fddbcd58656cd6888c7d5b85d52e441 (patch) | |
tree | 891c9f786bd4591dd2a3fb3545d5889dd195922a /plugin/pkg/variables/variables_test.go | |
parent | dae506b5638c7309399cb273d7f76bc20ee518dd (diff) | |
download | coredns-17d807f05fddbcd58656cd6888c7d5b85d52e441.tar.gz coredns-17d807f05fddbcd58656cd6888c7d5b85d52e441.tar.zst coredns-17d807f05fddbcd58656cd6888c7d5b85d52e441.zip |
plugin/metadata: add metadata plugin (#1894)
* plugin/metadata: add metadata plugin
* plugin/metadata: Add MD struct, refactor code, fix doc
* plugin/metadata: simplify metadata key
* plugin/metadata: improve setup_test
* Support of metadata by rewrite plugin. Move calculated variables to metadata.
* Move variables from metadata to pkg, add UTs, READMEs change, metadata small fixes
* Add client port validation to variables_test
* plugin/metadata: improve README
* plugin/metadata: rename methods
* plugin/metadata: Update Metadataer interface, update doc, cosmetic code changes
* plugin/metadata: move colllisions check to OnStartup(). Fix default variables metadataer.
* plugin/metadata: Fix comment for method setValue
* plugin/metadata: change variables order to fix linter warning
* plugin/metadata: rename Metadataer to Provider
Diffstat (limited to 'plugin/pkg/variables/variables_test.go')
-rw-r--r-- | plugin/pkg/variables/variables_test.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/plugin/pkg/variables/variables_test.go b/plugin/pkg/variables/variables_test.go new file mode 100644 index 000000000..939add323 --- /dev/null +++ b/plugin/pkg/variables/variables_test.go @@ -0,0 +1,80 @@ +package variables + +import ( + "bytes" + "testing" + + "github.com/coredns/coredns/plugin/test" + "github.com/miekg/dns" +) + +func TestGetValue(t *testing.T) { + // test.ResponseWriter has the following values: + // The remote will always be 10.240.0.1 and port 40212. + // The local address is always 127.0.0.1 and port 53. + tests := []struct { + varName string + expectedValue []byte + shouldErr bool + }{ + { + queryName, + []byte("example.com."), + false, + }, + { + queryType, + []byte{0x00, 0x01}, + false, + }, + { + clientIP, + []byte{10, 240, 0, 1}, + false, + }, + { + clientPort, + []byte{0x9D, 0x14}, + false, + }, + { + protocol, + []byte("udp"), + false, + }, + { + serverIP, + []byte{127, 0, 0, 1}, + false, + }, + { + serverPort, + []byte{0, 53}, + false, + }, + { + "wrong_var", + []byte{}, + true, + }, + } + + for i, tc := range tests { + m := new(dns.Msg) + m.SetQuestion("example.com.", dns.TypeA) + m.Question[0].Qclass = dns.ClassINET + + value, err := GetValue(tc.varName, &test.ResponseWriter{}, m) + + if tc.shouldErr && err == nil { + t.Errorf("Test %d: Expected error, but didn't recieve", i) + } + if !tc.shouldErr && err != nil { + t.Errorf("Test %d: Expected no error, but got error: %v", i, err.Error()) + } + + if !bytes.Equal(tc.expectedValue, value) { + t.Errorf("Test %d: Expected %v but got %v", i, tc.expectedValue, value) + } + } +} |