dnstest: add multirecorder (#1326)
* dnstest: add multirecorder This adds a new recorder that captures all messages written to it. This can be useful when, for instance, testing AXFR which can write muliple messages back to the client. * docs
This commit is contained in:
parent
08076e5284
commit
1f81d154ed
2 changed files with 80 additions and 0 deletions
39
plugin/pkg/dnstest/multirecorder_test.go
Normal file
39
plugin/pkg/dnstest/multirecorder_test.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package dnstest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
func TestMultiWriteMsg(t *testing.T) {
|
||||
w := &responseWriter{}
|
||||
record := NewMultiRecorder(w)
|
||||
|
||||
responseTestName := "testmsg.example.org."
|
||||
responseTestMsg := new(dns.Msg)
|
||||
responseTestMsg.SetQuestion(responseTestName, dns.TypeA)
|
||||
|
||||
record.WriteMsg(responseTestMsg)
|
||||
record.WriteMsg(responseTestMsg)
|
||||
|
||||
if len(record.Msgs) != 2 {
|
||||
t.Fatalf("Expected 2 messages to be written, but instead found %d\n", len(record.Msgs))
|
||||
|
||||
}
|
||||
if record.Len != responseTestMsg.Len()*2 {
|
||||
t.Fatalf("Expected the bytes written counter to be %d, but instead found %d\n", responseTestMsg.Len()*2, record.Len)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultiWrite(t *testing.T) {
|
||||
w := &responseWriter{}
|
||||
record := NewRecorder(w)
|
||||
responseTest := []byte("testmsg.example.org.")
|
||||
|
||||
record.Write(responseTest)
|
||||
record.Write(responseTest)
|
||||
if record.Len != len(responseTest)*2 {
|
||||
t.Fatalf("Expected the bytes written counter to be %d, but instead found %d\n", len(responseTest)*2, record.Len)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue