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>
This commit is contained in:
parent
c2780f42c4
commit
2aa1bda005
2 changed files with 39 additions and 1 deletions
38
plugin/cache/error_test.go
vendored
Normal file
38
plugin/cache/error_test.go
vendored
Normal file
|
@ -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
|
||||
})
|
||||
}
|
2
plugin/cache/spoof_test.go
vendored
2
plugin/cache/spoof_test.go
vendored
|
@ -6,8 +6,8 @@ import (
|
|||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/plugin/pkg/dnstest"
|
||||
|
||||
"github.com/coredns/coredns/plugin/test"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue