diff options
author | 2018-07-03 12:00:22 +0100 | |
---|---|---|
committer | 2018-07-03 04:00:22 -0700 | |
commit | 2aa1bda00529d6e168628c704955d132272f6436 (patch) | |
tree | e4b09fcd5ebc8164d02f2badf30de66d097c2987 /plugin/cache/error_test.go | |
parent | c2780f42c446dd1e6d5cbba7be9d07d297666d96 (diff) | |
download | coredns-2aa1bda00529d6e168628c704955d132272f6436.tar.gz coredns-2aa1bda00529d6e168628c704955d132272f6436.tar.zst coredns-2aa1bda00529d6e168628c704955d132272f6436.zip |
plugin/cache: add extra test for FORMERR (#1930)
* plugin/cache: add extra test for FORMERR
Add extra test that test for not caching a formerr.
Signed-off-by: Miek Gieben <miek@miek.nl>
* govet
Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'plugin/cache/error_test.go')
-rw-r--r-- | plugin/cache/error_test.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/plugin/cache/error_test.go b/plugin/cache/error_test.go new file mode 100644 index 000000000..7ae603e10 --- /dev/null +++ b/plugin/cache/error_test.go @@ -0,0 +1,38 @@ +package cache + +import ( + "context" + "testing" + + "github.com/coredns/coredns/plugin" + "github.com/coredns/coredns/plugin/pkg/dnstest" + "github.com/coredns/coredns/plugin/test" + + "github.com/miekg/dns" +) + +func TestFormErr(t *testing.T) { + c := New() + c.Next = formErrHandler() + + req := new(dns.Msg) + req.SetQuestion("example.org.", dns.TypeA) + rec := dnstest.NewRecorder(&test.ResponseWriter{}) + + c.ServeDNS(context.TODO(), rec, req) + + if c.pcache.Len() != 0 { + t.Errorf("Cached %s, while reply had %d", "example.org.", rec.Msg.Rcode) + } +} + +// formErrHanlder is a fake plugin implementation which returns a FORMERR for a reply. +func formErrHandler() plugin.Handler { + return plugin.HandlerFunc(func(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { + m := new(dns.Msg) + m.SetQuestion("example.net.", dns.TypeA) + m.Rcode = dns.RcodeFormatError + w.WriteMsg(m) + return dns.RcodeSuccess, nil + }) +} |