aboutsummaryrefslogtreecommitdiff
path: root/plugin/dnstap/out/tcp_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/dnstap/out/tcp_test.go')
-rw-r--r--plugin/dnstap/out/tcp_test.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/plugin/dnstap/out/tcp_test.go b/plugin/dnstap/out/tcp_test.go
new file mode 100644
index 000000000..113603cd4
--- /dev/null
+++ b/plugin/dnstap/out/tcp_test.go
@@ -0,0 +1,66 @@
+package out
+
+import (
+ "net"
+ "testing"
+)
+
+func sendOneTCP(tcp *TCP) error {
+ if _, err := tcp.Write([]byte("frame")); err != nil {
+ return err
+ }
+ if err := tcp.Flush(); err != nil {
+ return err
+ }
+ return nil
+}
+func TestTCP(t *testing.T) {
+ tcp := NewTCP("localhost:14000")
+
+ if err := sendOneTCP(tcp); err == nil {
+ t.Fatal("Not listening but no error.")
+ return
+ }
+
+ l, err := net.Listen("tcp", "localhost:14000")
+ if err != nil {
+ t.Fatal(err)
+ return
+ }
+
+ wait := make(chan bool)
+ go func() {
+ acceptOne(t, l)
+ wait <- true
+ }()
+
+ if err := sendOneTCP(tcp); err != nil {
+ t.Fatalf("send one: %s", err)
+ return
+ }
+
+ <-wait
+
+ // TODO: When the server isn't responding according to the framestream protocol
+ // the thread is blocked.
+ /*
+ if err := sendOneTCP(tcp); err == nil {
+ panic("must fail")
+ }
+ */
+
+ go func() {
+ acceptOne(t, l)
+ wait <- true
+ }()
+
+ if err := sendOneTCP(tcp); err != nil {
+ t.Fatalf("send one: %s", err)
+ return
+ }
+
+ <-wait
+ if err := l.Close(); err != nil {
+ t.Error(err)
+ }
+}