coredns/plugin/hosts/hosts_test.go
Miek Gieben 8722336fff
global: move to context (#1699)
* global: move to context

Move from golang.org/x/net/context to std lib's context.

Change done with:

for i in $(grep -l '/context' **/*.go); do sed -e 's|golang.org/x/net/context|context|' -i $i; echo $i; done
for i in **/*.go; do goimports -w $i; done

* drop from dns.pb.go as well
2018-04-20 11:01:06 +01:00

75 lines
1.5 KiB
Go

package hosts
import (
"strings"
"testing"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/test"
"context"
"github.com/miekg/dns"
)
func TestLookupA(t *testing.T) {
h := Hosts{Next: test.ErrorHandler(), Hostsfile: &Hostsfile{Origins: []string{"."}}}
h.parseReader(strings.NewReader(hostsExample))
ctx := context.TODO()
for _, tc := range hostsTestCases {
m := tc.Msg()
rec := dnstest.NewRecorder(&test.ResponseWriter{})
_, err := h.ServeDNS(ctx, rec, m)
if err != nil {
t.Errorf("Expected no error, got %v\n", err)
return
}
resp := rec.Msg
test.SortAndCheck(t, resp, tc)
}
}
var hostsTestCases = []test.Case{
{
Qname: "example.org.", Qtype: dns.TypeA,
Answer: []dns.RR{
test.A("example.org. 3600 IN A 10.0.0.1"),
},
},
{
Qname: "localhost.", Qtype: dns.TypeAAAA,
Answer: []dns.RR{
test.AAAA("localhost. 3600 IN AAAA ::1"),
},
},
{
Qname: "1.0.0.10.in-addr.arpa.", Qtype: dns.TypePTR,
Answer: []dns.RR{
test.PTR("1.0.0.10.in-addr.arpa. 3600 PTR example.org."),
},
},
{
Qname: "1.0.0.127.in-addr.arpa.", Qtype: dns.TypePTR,
Answer: []dns.RR{
test.PTR("1.0.0.127.in-addr.arpa. 3600 PTR localhost."),
test.PTR("1.0.0.127.in-addr.arpa. 3600 PTR localhost.domain."),
},
},
{
Qname: "example.org.", Qtype: dns.TypeAAAA,
Answer: []dns.RR{},
},
{
Qname: "example.org.", Qtype: dns.TypeMX,
Answer: []dns.RR{},
},
}
const hostsExample = `
127.0.0.1 localhost localhost.domain
::1 localhost localhost.domain
10.0.0.1 example.org`