aboutsummaryrefslogtreecommitdiff
path: root/plugin/pkg/variables/variables_test.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-07-01 20:01:17 +0100
committerGravatar GitHub <noreply@github.com> 2018-07-01 20:01:17 +0100
commit99800a687c5da6b5b9c42ad0431e21151828612a (patch)
tree447d777a8e9c3763cb418de2e9c065c7d91e43bc /plugin/pkg/variables/variables_test.go
parent0b326e26865af91474703322d5d9b1eb1e45a8ff (diff)
downloadcoredns-99800a687c5da6b5b9c42ad0431e21151828612a.tar.gz
coredns-99800a687c5da6b5b9c42ad0431e21151828612a.tar.zst
coredns-99800a687c5da6b5b9c42ad0431e21151828612a.zip
plugin/metadata: metadata is just label=value (#1914)
This revert 17d807f0 and re-adds the metadata plugin as a plugin that just sets a label to a value function. Add package documentation on how to use the metadata package. Make it clear that any caching is up to the Func implemented. There are now - no in tree users. We could add the request metadata by default under names that copy request.Request, i.e request/ip - remote IP request/port - remote port Variables.go has been deleted. Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'plugin/pkg/variables/variables_test.go')
-rw-r--r--plugin/pkg/variables/variables_test.go83
1 files changed, 0 insertions, 83 deletions
diff --git a/plugin/pkg/variables/variables_test.go b/plugin/pkg/variables/variables_test.go
deleted file mode 100644
index e0ff64c19..000000000
--- a/plugin/pkg/variables/variables_test.go
+++ /dev/null
@@ -1,83 +0,0 @@
-package variables
-
-import (
- "bytes"
- "testing"
-
- "github.com/coredns/coredns/plugin/test"
- "github.com/coredns/coredns/request"
-
- "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
- state := request.Request{W: &test.ResponseWriter{}, Req: m}
-
- value, err := GetValue(state, tc.varName)
-
- 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)
- }
- }
-}