mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 02:33:14 -04:00
add closest encloser stuff
This commit is contained in:
34
middleware/file/closest_test.go
Normal file
34
middleware/file/closest_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package file
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
func TestClosestEncloser(t *testing.T) {
|
||||
z, err := Parse(strings.NewReader(dbMiekNL), testzone, "stdin")
|
||||
if err != nil {
|
||||
t.Fatalf("expect no error when reading zone, got %q", err)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
in, out string
|
||||
}{
|
||||
{"miek.nl.", "miek.nl."},
|
||||
{"blaat.miek.nl.", "miek.nl."},
|
||||
{"blaat.blaat.miek.nl.", "miek.nl."},
|
||||
{"blaat.a.miek.nl.", "archive.miek.nl."},
|
||||
}
|
||||
|
||||
mk, _ := dns.TypeToRR[dns.TypeA]
|
||||
rr := mk()
|
||||
for _, tc := range tests {
|
||||
rr.Header().Name = tc.in
|
||||
ce := z.ClosestEncloser(rr)
|
||||
if ce != tc.out {
|
||||
t.Errorf("expected ce to be %s for %s, got %s", tc.out, tc.in, ce)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user