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