Skip to content

Commit

Permalink
fix for supporting changed ip format xxx.xxx.xxx.xxx:xxxx(x)
Browse files Browse the repository at this point in the history
  • Loading branch information
owljoa committed Sep 17, 2018
1 parent cd0038d commit 33c7186
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ func TestDial(t *testing.T) {

// then
assert.NoError(t, err)
assert.Equal(t, testConn.GetIP(), serverIP)
assert.Equal(t, testConn.GetIP(), bifrost.Address{serverIP})
}
18 changes: 15 additions & 3 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestGrpcConnection_Send(t *testing.T) {
}}
crypto := bifrost.GetMockCrypto()

conn, err := bifrost.NewConnection("127.0.0.1", keyOpts.PubKey, mockStreamWrapper, crypto)
conn, err := bifrost.NewConnection("127.0.0.1:1234", keyOpts.PubKey, mockStreamWrapper, crypto)

mockStreamWrapper.SendCallBack = func(envelope *pb.Envelope) {
//then
Expand All @@ -88,7 +88,7 @@ func TestGrpcConnection_GetPeerKey(t *testing.T) {
mockStreamWrapper := bifrost.MockStreamWrapper{}
crypto := bifrost.GetMockCrypto()

conn, err := bifrost.NewConnection("127.0.0.1", keyOpts.PubKey, mockStreamWrapper, crypto)
conn, err := bifrost.NewConnection("127.0.0.1:1234", keyOpts.PubKey, mockStreamWrapper, crypto)
assert.NoError(t, err)

go func() {
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestGrpcConnection_Close(t *testing.T) {
}
crypto := bifrost.GetMockCrypto()

conn, err := bifrost.NewConnection("127.0.0.1", keyOpts.PubKey, mockStreamWrapper, crypto)
conn, err := bifrost.NewConnection("127.0.0.1:1234", keyOpts.PubKey, mockStreamWrapper, crypto)
assert.NoError(t, err)

go func() {
Expand All @@ -132,3 +132,15 @@ func TestGrpcConnection_Close(t *testing.T) {
conn.Close()
wg.Wait()
}

func TestGrpcConnection_GetIP(t *testing.T) {
keyOpts := bifrost.GetKeyOpts()

mockStreamWrapper := bifrost.MockStreamWrapper{}
crypto := bifrost.GetMockCrypto()

conn, err := bifrost.NewConnection("127.0.0.1:1234", keyOpts.PubKey, mockStreamWrapper, crypto)
assert.NoError(t, err)
ipAddr := conn.GetIP()
assert.Equal(t, bifrost.Address{IP: "127.0.0.1:1234"}, ipAddr)
}
2 changes: 1 addition & 1 deletion mux/mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestMux_ServeRequest(t *testing.T) {

func TestMux_ServeError(t *testing.T) {
// given
targetIP := "127.0.0.1"
targetIP := "127.0.0.1:1234"
testMux := mux.New()

testMux.HandleError(func(conn bifrost.Connection, err error) {
Expand Down
6 changes: 3 additions & 3 deletions store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestConnectionStore_AddConnection(t *testing.T) {
testConnStroe := bifrost.NewConnectionStore()
testConn, err := bifrost.GetMockConnection("127.0.0.1")
testConn, err := bifrost.GetMockConnection("127.0.0.1:1234")
assert.NoError(t, err)

err = testConnStroe.AddConnection(testConn)
Expand All @@ -18,7 +18,7 @@ func TestConnectionStore_AddConnection(t *testing.T) {

func TestConnectionStore_DeleteConnection(t *testing.T) {
testConnStore := bifrost.NewConnectionStore()
testConn, err := bifrost.GetMockConnection("127.0.0.1")
testConn, err := bifrost.GetMockConnection("127.0.0.1:1234")
assert.NoError(t, err)

err = testConnStore.AddConnection(testConn)
Expand All @@ -33,7 +33,7 @@ func TestConnectionStore_DeleteConnection(t *testing.T) {

func TestConnectionStore_GetConnection(t *testing.T) {
testConnStore := bifrost.NewConnectionStore()
testConn, err := bifrost.GetMockConnection("127.0.0.1")
testConn, err := bifrost.GetMockConnection("127.0.0.1:1234")
assert.NoError(t, err)

err = testConnStore.AddConnection(testConn)
Expand Down

0 comments on commit 33c7186

Please sign in to comment.