plugin/file: unified NoData result (#5086)

Signed-off-by: xuweiwei <xuweiwei_yewu@cmss.chinamobile.com>
This commit is contained in:
xuweiwei 2022-04-26 00:05:24 +08:00 committed by GitHub
parent cab19747bc
commit c1857f4889
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View file

@ -230,7 +230,7 @@ func (z *Zone) Lookup(ctx context.Context, state request.Request, qname string)
nsec := typeFromElem(wildElem, dns.TypeNSEC, do)
ret = append(ret, nsec...)
}
return nil, ret, nil, Success
return nil, ret, nil, NoData
}
if do {

View file

@ -7,6 +7,7 @@ import (
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/test"
"github.com/coredns/coredns/request"
"github.com/miekg/dns"
)
@ -188,6 +189,33 @@ func TestLookupNil(t *testing.T) {
fm.ServeDNS(ctx, rec, m)
}
func TestLookUpNoDataResult(t *testing.T) {
zone, err := Parse(strings.NewReader(dbMiekNL), testzone, "stdin", 0)
if err != nil {
t.Fatalf("Expected no error when reading zone, got %q", err)
}
fm := File{Next: test.ErrorHandler(), Zones: Zones{Z: map[string]*Zone{testzone: zone}, Names: []string{testzone}}}
ctx := context.TODO()
var noDataTestCases = []test.Case{
{
Qname: "a.miek.nl.", Qtype: dns.TypeMX,
},
{
Qname: "wildcard.nodata.miek.nl.", Qtype: dns.TypeMX,
},
}
for _, tc := range noDataTestCases {
m := tc.Msg()
state := request.Request{W: &test.ResponseWriter{}, Req: m}
_, _, _, result := fm.Z[testzone].Lookup(ctx, state, tc.Qname)
if result != NoData {
t.Errorf("Expected result == 3 but result == %v ", result)
}
}
}
func BenchmarkFileLookup(b *testing.B) {
zone, err := Parse(strings.NewReader(dbMiekNL), testzone, "stdin", 0)
if err != nil {
@ -252,4 +280,5 @@ mx IN MX 10 a.miek.nl.
txt IN TXT "v=spf1 a mx ~all"
caa IN CAA 0 issue letsencrypt.org
*.nodata IN A 139.162.196.79
ext-cname IN CNAME example.com.`