diff --git a/client_test.go b/client_test.go index be81c0d6..03013506 100644 --- a/client_test.go +++ b/client_test.go @@ -19,34 +19,18 @@ func TestClientSync(t *testing.T) { } } -func helloMiek(w RequestWriter, r *Msg) { - w.Send(r) - reply, _ := w.Receive() - w.Write(reply) -} - func TestClientASync(t *testing.T) { - HandleQueryFunc("miek.nl.", helloMiek) // All queries for miek.nl will be handled by HelloMiek - ListenAndQuery(nil) // Detect if this isn't running - m := new(Msg) m.SetQuestion("miek.nl.", TypeSOA) c := new(Client) - c.Do(m, "85.223.71.124:53") - -forever: - for { - select { - case n := <-c.Reply: - if n.Reply != nil && n.Reply.Rcode != RcodeSuccess { - t.Log("Failed to get an valid answer") - t.Fail() - t.Logf("%v\n", n.Reply) - } - break forever + c.Do(m, "85.223.71.124:53", nil, func(m, r *Msg, e error, d interface{}) { + if r != nil && r.Rcode != RcodeSuccess { + t.Log("Failed to get an valid answer") + t.Fail() + t.Logf("%v\n", r) } - } + }) } func TestClientEDNS0(t *testing.T) { diff --git a/defaults.go b/defaults.go index 3064a7d2..ac4649ce 100644 --- a/defaults.go +++ b/defaults.go @@ -284,7 +284,7 @@ func IsDomainName(s string) (uint8, uint8, bool) { // copied from net package. // IsSubDomain checks if child is indeed a child of the parent. func IsSubDomain(parent, child string) bool { // Entire child is contained in parent - return CompareLabels(child, parent) == LenLabels(child) + return CompareLabels(parent, child) == LenLabels(parent) } // IsFqdn checks if a domain name is fully qualified. diff --git a/dns_test.go b/dns_test.go index 430c1585..4463965a 100644 --- a/dns_test.go +++ b/dns_test.go @@ -75,6 +75,8 @@ func TestBailiwick(t *testing.T) { for parent, child := range yes { if !IsSubDomain(parent, child) { t.Logf("%s should be child of %s\n", child, parent) + t.Logf("comparelabels %d", CompareLabels(parent, child)) + t.Logf("lenlabels %d %d", LenLabels(parent), LenLabels(child)) t.Fail() } } @@ -85,6 +87,8 @@ func TestBailiwick(t *testing.T) { for parent, child := range no { if IsSubDomain(parent, child) { t.Logf("%s should not be child of %s\n", child, parent) + t.Logf("comparelabels %d", CompareLabels(parent, child)) + t.Logf("lenlabels %d %d", LenLabels(parent), LenLabels(child)) t.Fail() } }