aboutsummaryrefslogtreecommitdiff
path: root/plugin/file/lookup_test.go
diff options
context:
space:
mode:
authorGravatar xuweiwei <xuweiwei_yewu@cmss.chinamobile.com> 2022-04-26 00:05:24 +0800
committerGravatar GitHub <noreply@github.com> 2022-04-25 12:05:24 -0400
commitc1857f488922d981f4b33f5c1b8518ff7d13a663 (patch)
treed04e9cc360c5387918c5b9006ea303035a05e61e /plugin/file/lookup_test.go
parentcab19747bcab70ebb3e1ce2b06416abc2fcf2c77 (diff)
downloadcoredns-c1857f488922d981f4b33f5c1b8518ff7d13a663.tar.gz
coredns-c1857f488922d981f4b33f5c1b8518ff7d13a663.tar.zst
coredns-c1857f488922d981f4b33f5c1b8518ff7d13a663.zip
plugin/file: unified NoData result (#5086)
Signed-off-by: xuweiwei <xuweiwei_yewu@cmss.chinamobile.com>
Diffstat (limited to 'plugin/file/lookup_test.go')
-rw-r--r--plugin/file/lookup_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/plugin/file/lookup_test.go b/plugin/file/lookup_test.go
index e84d2fce5..79e560428 100644
--- a/plugin/file/lookup_test.go
+++ b/plugin/file/lookup_test.go
@@ -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.`