Test that the server returns the expected records

This commit is contained in:
Ask Bjørn Hansen 2012-08-24 15:46:35 -07:00
parent 6f7aad15d8
commit 0a403841d8
1 changed files with 28 additions and 1 deletions

View File

@ -14,8 +14,18 @@ func HelloServer(w ResponseWriter, req *Msg) {
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) {
HandleFunc("miek.nl.", HelloServer)
HandleFunc("example.com.", AnotherHelloServer)
go func() {
err := ListenAndServe(":8053", "udp", nil)
if err != nil {
@ -23,7 +33,24 @@ func TestServing(t *testing.T) {
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) {