diff --git a/client_test.go b/client_test.go index a6158967..52557ced 100644 --- a/client_test.go +++ b/client_test.go @@ -29,6 +29,8 @@ const ( port = 3699 username = "root" password = "nebula" + + addressIPv6 = "::1" ) var poolAddress = []HostAddress{ @@ -104,6 +106,50 @@ func TestConnection(t *testing.T) { } } +func TestConnectionIPv6(t *testing.T) { + hostAdress := HostAddress{Host: addressIPv6, Port: port} + conn := newConnection(hostAdress) + err := conn.open(hostAdress, testPoolConfig.TimeOut, nil) + if err != nil { + t.Fatalf("fail to open connection, address: %s, port: %d, %s", address, port, err.Error()) + } + + authresp, authErr := conn.authenticate(username, password) + if authErr != nil { + t.Fatalf("fail to authenticate, username: %s, password: %s, %s", username, password, authErr.Error()) + } + + sessionID := authresp.GetSessionID() + + defer logoutAndClose(conn, sessionID) + + resp, err := conn.execute(sessionID, "SHOW HOSTS;") + if err != nil { + t.Fatalf(err.Error()) + return + } + checkConResp(t, "show hosts", resp) + + resp, err = conn.execute(sessionID, "CREATE SPACE client_test(partition_num=1024, replica_factor=1, vid_type = FIXED_STRING(30));") + if err != nil { + t.Error(err.Error()) + return + } + checkConResp(t, "create space", resp) + resp, err = conn.execute(sessionID, "DROP SPACE client_test;") + if err != nil { + t.Error(err.Error()) + return + } + checkConResp(t, "drop space", resp) + + res := conn.ping() + if res != true { + t.Error("Connection ping failed") + return + } +} + func TestConfigs(t *testing.T) { hostAdress := HostAddress{Host: address, Port: port} hostList := []HostAddress{} diff --git a/connection.go b/connection.go index 28e1c6c3..e16381a7 100644 --- a/connection.go +++ b/connection.go @@ -12,6 +12,8 @@ import ( "crypto/tls" "fmt" "math" + "net" + "strconv" "time" "github.com/facebook/fbthrift/thrift/lib/go/thrift" @@ -42,7 +44,7 @@ func newConnection(severAddress HostAddress) *connection { func (cn *connection) open(hostAddress HostAddress, timeout time.Duration, sslConfig *tls.Config) error { ip := hostAddress.Host port := hostAddress.Port - newAdd := fmt.Sprintf("%s:%d", ip, port) + newAdd := net.JoinHostPort(ip, strconv.Itoa(port)) cn.timeout = timeout bufferSize := 128 << 10 frameMaxLength := uint32(math.MaxUint32)