Skip to content

Commit

Permalink
Update test for bad ID
Browse files Browse the repository at this point in the history
The new test sends two replies: the first one has a bad ID, which should
be ignored, and the second one has the correct ID.
  • Loading branch information
AGWA committed Sep 2, 2020
1 parent c165241 commit ddbee29
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 12 additions & 4 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,20 @@ func TestClientSyncBadID(t *testing.T) {
m.SetQuestion("miek.nl.", TypeSOA)

c := new(Client)
if _, _, err := c.Exchange(m, addrstr); err != ErrId {
t.Errorf("did not find a bad Id")
r, _, err := c.Exchange(m, addrstr)
if err != nil {
t.Errorf("failed to exchange: %v", err)
}
if r.Id != m.Id {
t.Errorf("failed to get response with expected Id")
}
// And now with plain Exchange().
if _, err := Exchange(m, addrstr); err != ErrId {
t.Errorf("did not find a bad Id")
r, err = Exchange(m, addrstr)
if err != nil {
t.Errorf("failed to exchange: %v", err)
}
if r.Id != m.Id {
t.Errorf("failed to get response with expected Id")
}
}

Expand Down
3 changes: 3 additions & 0 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func HelloServerBadID(w ResponseWriter, req *Msg) {
m.Extra = make([]RR, 1)
m.Extra[0] = &TXT{Hdr: RR_Header{Name: m.Question[0].Name, Rrtype: TypeTXT, Class: ClassINET, Ttl: 0}, Txt: []string{"Hello world"}}
w.WriteMsg(m)

m.Id--
w.WriteMsg(m)
}

func HelloServerEchoAddrPort(w ResponseWriter, req *Msg) {
Expand Down

0 comments on commit ddbee29

Please sign in to comment.