| Jan Schär | 4a18022 | 2024-07-29 16:32:54 +0200 | [diff] [blame^] | 1 | package test |
| 2 | |
| 3 | // Taken and modified from CoreDNS, under Apache 2.0. |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/miekg/dns" |
| 9 | ) |
| 10 | |
| 11 | func TestNewServer(t *testing.T) { |
| 12 | s := NewServer(func(w dns.ResponseWriter, r *dns.Msg) { |
| 13 | ret := new(dns.Msg) |
| 14 | ret.SetReply(r) |
| 15 | w.WriteMsg(ret) |
| 16 | }) |
| 17 | defer s.Close() |
| 18 | |
| 19 | c := new(dns.Client) |
| 20 | c.Net = "tcp" |
| 21 | m := new(dns.Msg) |
| 22 | m.SetQuestion("example.org.", dns.TypeSOA) |
| 23 | ret, _, err := c.Exchange(m, s.Addr) |
| 24 | if err != nil { |
| 25 | t.Fatalf("Could not send message to dnstest.Server: %s", err) |
| 26 | } |
| 27 | if ret.Id != m.Id { |
| 28 | t.Fatalf("Msg ID's should match, expected %d, got %d", m.Id, ret.Id) |
| 29 | } |
| 30 | |
| 31 | c.Net = "udp" |
| 32 | ret, _, err = c.Exchange(m, s.Addr) |
| 33 | if err != nil { |
| 34 | t.Fatalf("Could not send message to dnstest.Server: %s", err) |
| 35 | } |
| 36 | if ret.Id != m.Id { |
| 37 | t.Fatalf("Msg ID's should match, expected %d, got %d", m.Id, ret.Id) |
| 38 | } |
| 39 | } |