1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
package dbus
import (
"fmt"
"net"
"testing"
)
func TestTcpConnection(t *testing.T) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal("Failed to create listener")
}
host, port, err := net.SplitHostPort(listener.Addr().String())
if err != nil {
t.Fatal("Failed to parse host/port")
}
conn, err := Dial(fmt.Sprintf("tcp:host=%s,port=%s", host, port))
if err != nil {
t.Error("Expected no error, got", err)
}
if conn == nil {
t.Error("Expected connection, got nil")
}
}
|