-
Notifications
You must be signed in to change notification settings - Fork 2
/
request_test.go
57 lines (46 loc) · 1.07 KB
/
request_test.go
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"testing"
"github.com/markdingo/rrl"
"github.com/miekg/dns"
"github.com/markdingo/autoreverse/dnsutil"
"github.com/markdingo/autoreverse/log"
"github.com/markdingo/autoreverse/mock"
)
// Meet the net.Addr interface so we can mock into the request struct
type mockNetAddr struct {
net string
str string
}
func (t *mockNetAddr) Network() string {
return t.net
}
func (t *mockNetAddr) String() string {
return t.str
}
func TestRequestLog(t *testing.T) {
out := &mock.IOWriter{}
log.SetOut(out)
req := &request{}
req.network = dnsutil.TCPNetwork
req.compressed = true
req.truncated = true
req.response = new(dns.Msg)
req.question = dns.Question{}
req.src = &mockNetAddr{}
req.log()
got := out.String()
exp := "ru=ne q=None/ s= id=0 h=Tzt sz=0/0 C=0/0/0\n"
if exp != got {
t.Error("Log wrong. Exp", exp, "Got", got)
}
out = &mock.IOWriter{}
log.SetOut(out)
req.rrlAction = rrl.Drop
req.log()
got = out.String()
exp = "ru=ne/D q=None/ s= id=0 h=Tzt sz=0/0 C=0/0/0\n"
if exp != got {
t.Error("Log wrong. Exp", exp, "Got", got)
}
}