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