Easier way to dnstap? (#1496)

* Easier way to dnstap?

* Remove unnecessary function parameter from Tapper

* golint

* golint 2

* Proxy dnstap tests

* README.md & doc

* net.IP

* Proxy test was incorrect

* Small changes

* Update README.md

* Was not reporting dnstap errors + test

* Wasn't working at all, now it's ok

* Thanks Travis
This commit is contained in:
varyoo
2018-03-01 03:19:01 +01:00
committed by Miek Gieben
parent f697b33283
commit 6bb08ffee4
12 changed files with 274 additions and 255 deletions

View File

@@ -1,41 +1,14 @@
package taprw
import (
"errors"
"testing"
"github.com/coredns/coredns/plugin/dnstap/msg"
"github.com/coredns/coredns/plugin/dnstap/test"
mwtest "github.com/coredns/coredns/plugin/test"
tap "github.com/dnstap/golang-dnstap"
"github.com/miekg/dns"
)
type TapFailer struct {
}
func (TapFailer) TapMessage(*tap.Message) error {
return errors.New("failed")
}
func (TapFailer) TapBuilder() msg.Builder {
return msg.Builder{Full: true}
}
func TestDnstapError(t *testing.T) {
rw := ResponseWriter{
Query: new(dns.Msg),
ResponseWriter: &mwtest.ResponseWriter{},
Tapper: TapFailer{},
}
if err := rw.WriteMsg(new(dns.Msg)); err != nil {
t.Errorf("dnstap error during Write: %s", err)
}
if rw.DnstapError() == nil {
t.Fatal("no dnstap error")
}
}
func testingMsg() (m *dns.Msg) {
m = new(dns.Msg)
m.SetQuestion("example.com.", dns.TypeA)
@@ -69,12 +42,18 @@ func TestClientQueryResponse(t *testing.T) {
t.Fatalf("%d msg trapped", l)
return
}
want := d.ToClientQuery()
want, err := d.ToClientQuery()
if err != nil {
t.Fatal("Testing data must build", err)
}
have := trapper.Trap[0]
if !test.MsgEqual(want, have) {
t.Fatalf("query: want: %v\nhave: %v", want, have)
}
want = d.ToClientResponse()
want, err = d.ToClientResponse()
if err != nil {
t.Fatal("Testing data must build", err)
}
have = trapper.Trap[1]
if !test.MsgEqual(want, have) {
t.Fatalf("response: want: %v\nhave: %v", want, have)