Enable dnstap plugin to insert other plugin's specific data into extra field of tap.Dnstap message (#1101)

* Add custom data into dnstap context

* Fix error and fix UT compile errors

* Add UTs

* Change as per review comments.  Use boolean to indicate which Dnstap message to send out

* Merge with master and fix lint warning

* Remove newline

* Fix review comments
This commit is contained in:
Thong Huynh
2017-09-29 13:38:01 -07:00
committed by John Belamaric
parent 4b3a430ff2
commit 2f9c42d82e
3 changed files with 99 additions and 18 deletions

View File

@@ -80,3 +80,57 @@ func TestClientQueryResponse(t *testing.T) {
t.Fatalf("response: want: %v\nhave: %v", want, have)
}
}
func TestClientQueryResponseWithSendOption(t *testing.T) {
trapper := test.TrapTapper{Full: true}
m := testingMsg()
rw := ResponseWriter{
Query: m,
Tapper: &trapper,
ResponseWriter: &mwtest.ResponseWriter{},
}
d := test.TestingData()
bin, err := m.Pack()
if err != nil {
t.Fatal(err)
return
}
d.Packed = bin
// Do not send both CQ and CR
o := SendOption{Cq: false, Cr: false}
rw.Send = &o
if err := rw.WriteMsg(m); err != nil {
t.Fatal(err)
return
}
if l := len(trapper.Trap); l != 0 {
t.Fatalf("%d msg trapped", l)
return
}
//Send CQ
o.Cq = true
if err := rw.WriteMsg(m); err != nil {
t.Fatal(err)
return
}
if l := len(trapper.Trap); l != 1 {
t.Fatalf("%d msg trapped", l)
return
}
//Send CR
trapper.Trap = trapper.Trap[:0]
o.Cq = false
o.Cr = true
if err := rw.WriteMsg(m); err != nil {
t.Fatal(err)
return
}
if l := len(trapper.Trap); l != 1 {
t.Fatalf("%d msg trapped", l)
return
}
}