mirror of
https://github.com/coredns/coredns.git
synced 2025-10-31 18:23:13 -04:00
IP endpoint for dnstap (#1002)
* adds the option to log to a remote endpoint * examples * tests * tcp:// or default to unix:// * cosmetic update * bad naked returns
This commit is contained in:
66
middleware/dnstap/out/tcp_test.go
Normal file
66
middleware/dnstap/out/tcp_test.go
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user