diff options
Diffstat (limited to 'plugin/debug/pcap_test.go')
-rw-r--r-- | plugin/debug/pcap_test.go | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/plugin/debug/pcap_test.go b/plugin/debug/pcap_test.go index 724189db7..b2796e399 100644 --- a/plugin/debug/pcap_test.go +++ b/plugin/debug/pcap_test.go @@ -17,10 +17,21 @@ func msg() *dns.Msg { m.SetQuestion("example.local.", dns.TypeA) m.SetEdns0(4096, true) m.Id = 10 - return m } +func TestNoDebug(t *testing.T) { + // Must come first, because set log.D.Set() which is impossible to undo. + var f bytes.Buffer + golog.SetOutput(&f) + + str := "Hi There!" + Hexdumpf(msg(), "%s %d", str, 10) + if len(f.Bytes()) != 0 { + t.Errorf("Expected no output, got %d bytes", len(f.Bytes())) + } +} + func ExampleLogHexdump() { buf, _ := msg().Pack() h := hexdump(buf) @@ -36,7 +47,7 @@ func ExampleLogHexdump() { func TestHexdump(t *testing.T) { var f bytes.Buffer golog.SetOutput(&f) - log.D = true + log.D.Set() str := "Hi There!" Hexdump(msg(), str) @@ -50,7 +61,7 @@ func TestHexdump(t *testing.T) { func TestHexdumpf(t *testing.T) { var f bytes.Buffer golog.SetOutput(&f) - log.D = true + log.D.Set() str := "Hi There!" Hexdumpf(msg(), "%s %d", str, 10) @@ -60,15 +71,3 @@ func TestHexdumpf(t *testing.T) { t.Errorf("The string %s %d, is not contained in the logged output: %s", str, 10, logged) } } - -func TestNoDebug(t *testing.T) { - var f bytes.Buffer - golog.SetOutput(&f) - log.D = false - - str := "Hi There!" - Hexdumpf(msg(), "%s %d", str, 10) - if len(f.Bytes()) != 0 { - t.Errorf("Expected no output, got %d bytes", len(f.Bytes())) - } -} |