| 1 |
package whoami_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"codeberg.org/miekg/dns" |
| 8 |
"codeberg.org/miekg/dns/cmd/atomdns/atomtest" |
| 9 |
"codeberg.org/miekg/dns/cmd/atomdns/handlers/whoami" |
| 10 |
"codeberg.org/miekg/dns/dnstest" |
| 11 |
) |
| 12 |
|
| 13 |
func TestWhoami(t *testing.T) { |
| 14 |
w := new(whoami.Whoami) |
| 15 |
m := dnstest.NewMsg() |
| 16 |
|
| 17 |
tw := dnstest.NewTestRecorder() |
| 18 |
w.HandlerFunc(atomtest.Echo).ServeDNS(context.TODO(), tw, m) |
| 19 |
|
| 20 |
tw.Msg.Unpack() |
| 21 |
if len(tw.Msg.Answer) != 1 { |
| 22 |
t.Fatal("expected answer section") |
| 23 |
} |
| 24 |
if x := tw.Msg.Answer[0].(*dns.A).Addr.String(); x != dnstest.IPv4.String() { |
| 25 |
t.Fatalf("expected %q, got %q ", dnstest.IPv4.String(), x) |
| 26 |
} |
| 27 |
} |