Debian Codegraph @

cmd/atomdns/handlers/dbhost/dbhost_test.go

raw
1 package dbhost
2
3 import (
4 "context"
5 "net/netip"
6 "testing"
7
8 "codeberg.org/miekg/dns"
9 "codeberg.org/miekg/dns/cmd/atomdns/handlers/whoami"
10 "codeberg.org/miekg/dns/dnstest"
11 )
12
13 func TestDbhost(t *testing.T) {
14 d := &Dbhost{Path: "/etc/hosts"}
15 d.Load()
16
17 m := dns.NewMsg("localhost.", dns.TypeA)
18 m.ID = 3
19 m.Pack()
20
21 tw := dnstest.NewTestRecorder()
22 next := new(whoami.Whoami).HandlerFunc(nil)
23 d.HandlerFunc(next).ServeDNS(context.TODO(), tw, m)
24
25 tw.Msg.Unpack()
26 if x := tw.Msg.Answer[0].(*dns.A).Addr; x != netip.MustParseAddr("127.0.0.1") {
27 t.Fatalf("expected %s, got %s", "127.0.0.1", x)
28 }
29 }