aboutsummaryrefslogtreecommitdiff
path: root/plugin/pkg/dnstest/multirecorder_test.go
blob: 1299db5873242a4b0f31ae8c4906e569a072ef15 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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)
	}
}