mirror of
https://github.com/miekg/dns.git
synced 2025-12-16 17:21:17 +01:00
Test that the server returns the expected records
This commit is contained in:
parent
6f7aad15d8
commit
0a403841d8
@ -14,8 +14,18 @@ func HelloServer(w ResponseWriter, req *Msg) {
|
|||||||
w.Write(m)
|
w.Write(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AnotherHelloServer(w ResponseWriter, req *Msg) {
|
||||||
|
m := new(Msg)
|
||||||
|
m.SetReply(req)
|
||||||
|
|
||||||
|
m.Extra = make([]RR, 1)
|
||||||
|
m.Extra[0] = &RR_TXT{Hdr: RR_Header{Name: m.Question[0].Name, Rrtype: TypeTXT, Class: ClassINET, Ttl: 0}, Txt: []string{"Hello example"}}
|
||||||
|
w.Write(m)
|
||||||
|
}
|
||||||
|
|
||||||
func TestServing(t *testing.T) {
|
func TestServing(t *testing.T) {
|
||||||
HandleFunc("miek.nl.", HelloServer)
|
HandleFunc("miek.nl.", HelloServer)
|
||||||
|
HandleFunc("example.com.", AnotherHelloServer)
|
||||||
go func() {
|
go func() {
|
||||||
err := ListenAndServe(":8053", "udp", nil)
|
err := ListenAndServe(":8053", "udp", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -23,7 +33,24 @@ func TestServing(t *testing.T) {
|
|||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
time.Sleep(1e9)
|
time.Sleep(4e8)
|
||||||
|
c := new(Client)
|
||||||
|
m := new(Msg)
|
||||||
|
|
||||||
|
m.SetQuestion("miek.nl.", TypeTXT)
|
||||||
|
r, _ := c.Exchange(m, "127.0.0.1:8053")
|
||||||
|
txt := r.Extra[0].(*RR_TXT).Txt[0]
|
||||||
|
if txt != "Hello world" {
|
||||||
|
t.Log("Unexpected result for miek.nl", txt, "!= Hello world")
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
m.SetQuestion("example.com.", TypeTXT)
|
||||||
|
r, _ = c.Exchange(m, "127.0.0.1:8053")
|
||||||
|
txt = r.Extra[0].(*RR_TXT).Txt[0]
|
||||||
|
if txt != "Hello example" {
|
||||||
|
t.Log("Unexpected result for example.com", txt, "!= Hello example")
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkServing(b *testing.B) {
|
func BenchmarkServing(b *testing.B) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user