diff options
author | 2017-07-24 23:12:50 +0200 | |
---|---|---|
committer | 2017-07-24 14:12:50 -0700 | |
commit | 1b7492be6e07f4b8306c0b4a56d79f37485ae61c (patch) | |
tree | 02510da5a7cf228821373a8090bac29055764aba /middleware/dnstap/test/helpers.go | |
parent | f33b02689c564c1de8774f7f99d2400231a76069 (diff) | |
download | coredns-1b7492be6e07f4b8306c0b4a56d79f37485ae61c.tar.gz coredns-1b7492be6e07f4b8306c0b4a56d79f37485ae61c.tar.zst coredns-1b7492be6e07f4b8306c0b4a56d79f37485ae61c.zip |
WIP: middleware/dnstap (#711)
middleware/dnstap add
Diffstat (limited to 'middleware/dnstap/test/helpers.go')
-rw-r--r-- | middleware/dnstap/test/helpers.go | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/middleware/dnstap/test/helpers.go b/middleware/dnstap/test/helpers.go new file mode 100644 index 000000000..fba291dfe --- /dev/null +++ b/middleware/dnstap/test/helpers.go @@ -0,0 +1,64 @@ +package test + +import ( + "net" + "reflect" + + "github.com/coredns/coredns/middleware/dnstap/msg" + + tap "github.com/dnstap/golang-dnstap" +) + +func TestingData() (d *msg.Data) { + d = &msg.Data{ + Type: tap.Message_CLIENT_RESPONSE, + SocketFam: tap.SocketFamily_INET, + SocketProto: tap.SocketProtocol_UDP, + Address: net.ParseIP("10.240.0.1"), + Port: 40212, + } + return +} + +type comp struct { + Type *tap.Message_Type + SF *tap.SocketFamily + SP *tap.SocketProtocol + QA []byte + RA []byte + QP *uint32 + RP *uint32 + QTSec bool + RTSec bool + RM []byte + QM []byte +} + +func toComp(m *tap.Message) comp { + return comp{ + Type: m.Type, + SF: m.SocketFamily, + SP: m.SocketProtocol, + QA: m.QueryAddress, + RA: m.ResponseAddress, + QP: m.QueryPort, + RP: m.ResponsePort, + QTSec: m.QueryTimeSec != nil, + RTSec: m.ResponseTimeSec != nil, + RM: m.ResponseMessage, + QM: m.QueryMessage, + } +} + +func MsgEqual(a, b *tap.Message) bool { + return reflect.DeepEqual(toComp(a), toComp(b)) +} + +type TrapTaper struct { + Trap []*tap.Message +} + +func (t *TrapTaper) TapMessage(m *tap.Message) error { + t.Trap = append(t.Trap, m) + return nil +} |