Skip to content

Commit

Permalink
Fix ipv6 issue #158 (#204)
Browse files Browse the repository at this point in the history
* update test to check ipv6 version of localhost

* use net.JoinHostPort to handle the ipv6 case properly

* remove remote services, the code is not necessary to use this project as a nebula driver (#200)

* remove remote services, the code is not necessary to use this project as a nebula driver

* Create integration tests (#201)

* add build tag for integration tests

* add unit rule to run unit tests

* add unit as phony

* improve formatting of each _test file, enable coverate on functional tests

* add badge for test results

Co-authored-by: Yichen Wang <[email protected]>

Co-authored-by: Yichen Wang <[email protected]>
  • Loading branch information
peczenyj and Aiee authored Jul 1, 2022
1 parent 2f85fa9 commit 4e1c4a4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
46 changes: 46 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const (
port = 3699
username = "root"
password = "nebula"

addressIPv6 = "::1"
)

var poolAddress = []HostAddress{
Expand Down Expand Up @@ -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{}
Expand Down
4 changes: 3 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"crypto/tls"
"fmt"
"math"
"net"
"strconv"
"time"

"github.com/facebook/fbthrift/thrift/lib/go/thrift"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4e1c4a4

Please sign in to comment.