@ -49,11 +49,11 @@ func TestNewEndpoint(t *testing.T) {
{ "http:path" , Endpoint { URL : & url . URL { Path : "http:path" } , IsLocal : true } , PathEndpointType , nil } ,
{ "http:path" , Endpoint { URL : & url . URL { Path : "http:path" } , IsLocal : true } , PathEndpointType , nil } ,
{ "http:/path" , Endpoint { URL : & url . URL { Path : "http:/path" } , IsLocal : true } , PathEndpointType , nil } ,
{ "http:/path" , Endpoint { URL : & url . URL { Path : "http:/path" } , IsLocal : true } , PathEndpointType , nil } ,
{ "http:///path" , Endpoint { URL : & url . URL { Path : "http:/path" } , IsLocal : true } , PathEndpointType , nil } ,
{ "http:///path" , Endpoint { URL : & url . URL { Path : "http:/path" } , IsLocal : true } , PathEndpointType , nil } ,
{ "http://localhost/path" , Endpoint { URL : u1 , IsLocal : true } , URLEndpointType , nil } ,
{ "http://localhost/path" , Endpoint { URL : u1 , IsLocal : true , HostName : "localhost" } , URLEndpointType , nil } ,
{ "http://localhost/path//" , Endpoint { URL : u1 , IsLocal : true } , URLEndpointType , nil } ,
{ "http://localhost/path//" , Endpoint { URL : u1 , IsLocal : true , HostName : "localhost" } , URLEndpointType , nil } ,
{ "https://example.org/path" , Endpoint { URL : u2 } , URLEndpointType , nil } ,
{ "https://example.org/path" , Endpoint { URL : u2 , IsLocal : false , HostName : "example.org" } , URLEndpointType , nil } ,
{ "http://127.0.0.1:8080/path" , Endpoint { URL : u3 , IsLocal : true } , URLEndpointType , nil } ,
{ "http://127.0.0.1:8080/path" , Endpoint { URL : u3 , IsLocal : true , HostName : "127.0.0.1" } , URLEndpointType , nil } ,
{ "http://192.168.253.200/path" , Endpoint { URL : u4 } , URLEndpointType , nil } ,
{ "http://192.168.253.200/path" , Endpoint { URL : u4 , IsLocal : false , HostName : "192.168.253.200" } , URLEndpointType , nil } ,
{ "" , Endpoint { } , - 1 , fmt . Errorf ( "empty or root endpoint is not supported" ) } ,
{ "" , Endpoint { } , - 1 , fmt . Errorf ( "empty or root endpoint is not supported" ) } ,
{ "/" , Endpoint { } , - 1 , fmt . Errorf ( "empty or root endpoint is not supported" ) } ,
{ "/" , Endpoint { } , - 1 , fmt . Errorf ( "empty or root endpoint is not supported" ) } ,
{ ` \ ` , Endpoint { } , - 1 , fmt . Errorf ( "empty or root endpoint is not supported" ) } ,
{ ` \ ` , Endpoint { } , - 1 , fmt . Errorf ( "empty or root endpoint is not supported" ) } ,
@ -71,6 +71,10 @@ func TestNewEndpoint(t *testing.T) {
for _ , testCase := range testCases {
for _ , testCase := range testCases {
endpoint , err := NewEndpoint ( testCase . arg )
endpoint , err := NewEndpoint ( testCase . arg )
if err == nil {
err = endpoint . UpdateIsLocal ( )
}
if testCase . expectedErr == nil {
if testCase . expectedErr == nil {
if err != nil {
if err != nil {
t . Fatalf ( "error: expected = <nil>, got = %v" , err )
t . Fatalf ( "error: expected = <nil>, got = %v" , err )
@ -261,46 +265,46 @@ func TestCreateEndpoints(t *testing.T) {
// DistXL type
// DistXL type
{ "127.0.0.1:10000" , [ ] [ ] string { { case1Endpoint1 , case1Endpoint2 , "http://example.org/d3" , "http://example.com/d4" } } , "127.0.0.1:10000" , EndpointList {
{ "127.0.0.1:10000" , [ ] [ ] string { { case1Endpoint1 , case1Endpoint2 , "http://example.org/d3" , "http://example.com/d4" } } , "127.0.0.1:10000" , EndpointList {
Endpoint { URL : case1URLs [ 0 ] , IsLocal : case1LocalFlags [ 0 ] } ,
Endpoint { URL : case1URLs [ 0 ] , IsLocal : case1LocalFlags [ 0 ] , HostName : nonLoopBackIP } ,
Endpoint { URL : case1URLs [ 1 ] , IsLocal : case1LocalFlags [ 1 ] } ,
Endpoint { URL : case1URLs [ 1 ] , IsLocal : case1LocalFlags [ 1 ] , HostName : nonLoopBackIP } ,
Endpoint { URL : case1URLs [ 2 ] , IsLocal : case1LocalFlags [ 2 ] } ,
Endpoint { URL : case1URLs [ 2 ] , IsLocal : case1LocalFlags [ 2 ] , HostName : "example.org" } ,
Endpoint { URL : case1URLs [ 3 ] , IsLocal : case1LocalFlags [ 3 ] } ,
Endpoint { URL : case1URLs [ 3 ] , IsLocal : case1LocalFlags [ 3 ] , HostName : "example.com" } ,
} , DistXLSetupType , nil } ,
} , DistXLSetupType , nil } ,
{ "127.0.0.1:10000" , [ ] [ ] string { { case2Endpoint1 , case2Endpoint2 , "http://example.org/d3" , "http://example.com/d4" } } , "127.0.0.1:10000" , EndpointList {
{ "127.0.0.1:10000" , [ ] [ ] string { { case2Endpoint1 , case2Endpoint2 , "http://example.org/d3" , "http://example.com/d4" } } , "127.0.0.1:10000" , EndpointList {
Endpoint { URL : case2URLs [ 0 ] , IsLocal : case2LocalFlags [ 0 ] } ,
Endpoint { URL : case2URLs [ 0 ] , IsLocal : case2LocalFlags [ 0 ] , HostName : nonLoopBackIP } ,
Endpoint { URL : case2URLs [ 1 ] , IsLocal : case2LocalFlags [ 1 ] } ,
Endpoint { URL : case2URLs [ 1 ] , IsLocal : case2LocalFlags [ 1 ] , HostName : nonLoopBackIP } ,
Endpoint { URL : case2URLs [ 2 ] , IsLocal : case2LocalFlags [ 2 ] } ,
Endpoint { URL : case2URLs [ 2 ] , IsLocal : case2LocalFlags [ 2 ] , HostName : "example.org" } ,
Endpoint { URL : case2URLs [ 3 ] , IsLocal : case2LocalFlags [ 3 ] } ,
Endpoint { URL : case2URLs [ 3 ] , IsLocal : case2LocalFlags [ 3 ] , HostName : "example.com" } ,
} , DistXLSetupType , nil } ,
} , DistXLSetupType , nil } ,
{ ":80" , [ ] [ ] string { { case3Endpoint1 , "http://example.org:9000/d2" , "http://example.com/d3" , "http://example.net/d4" } } , ":80" , EndpointList {
{ ":80" , [ ] [ ] string { { case3Endpoint1 , "http://example.org:9000/d2" , "http://example.com/d3" , "http://example.net/d4" } } , ":80" , EndpointList {
Endpoint { URL : case3URLs [ 0 ] , IsLocal : case3LocalFlags [ 0 ] } ,
Endpoint { URL : case3URLs [ 0 ] , IsLocal : case3LocalFlags [ 0 ] , HostName : nonLoopBackIP } ,
Endpoint { URL : case3URLs [ 1 ] , IsLocal : case3LocalFlags [ 1 ] } ,
Endpoint { URL : case3URLs [ 1 ] , IsLocal : case3LocalFlags [ 1 ] , HostName : "example.org" } ,
Endpoint { URL : case3URLs [ 2 ] , IsLocal : case3LocalFlags [ 2 ] } ,
Endpoint { URL : case3URLs [ 2 ] , IsLocal : case3LocalFlags [ 2 ] , HostName : "example.com" } ,
Endpoint { URL : case3URLs [ 3 ] , IsLocal : case3LocalFlags [ 3 ] } ,
Endpoint { URL : case3URLs [ 3 ] , IsLocal : case3LocalFlags [ 3 ] , HostName : "example.net" } ,
} , DistXLSetupType , nil } ,
} , DistXLSetupType , nil } ,
{ ":9000" , [ ] [ ] string { { case4Endpoint1 , "http://example.org/d2" , "http://example.com/d3" , "http://example.net/d4" } } , ":9000" , EndpointList {
{ ":9000" , [ ] [ ] string { { case4Endpoint1 , "http://example.org/d2" , "http://example.com/d3" , "http://example.net/d4" } } , ":9000" , EndpointList {
Endpoint { URL : case4URLs [ 0 ] , IsLocal : case4LocalFlags [ 0 ] } ,
Endpoint { URL : case4URLs [ 0 ] , IsLocal : case4LocalFlags [ 0 ] , HostName : nonLoopBackIP } ,
Endpoint { URL : case4URLs [ 1 ] , IsLocal : case4LocalFlags [ 1 ] } ,
Endpoint { URL : case4URLs [ 1 ] , IsLocal : case4LocalFlags [ 1 ] , HostName : "example.org" } ,
Endpoint { URL : case4URLs [ 2 ] , IsLocal : case4LocalFlags [ 2 ] } ,
Endpoint { URL : case4URLs [ 2 ] , IsLocal : case4LocalFlags [ 2 ] , HostName : "example.com" } ,
Endpoint { URL : case4URLs [ 3 ] , IsLocal : case4LocalFlags [ 3 ] } ,
Endpoint { URL : case4URLs [ 3 ] , IsLocal : case4LocalFlags [ 3 ] , HostName : "example.net" } ,
} , DistXLSetupType , nil } ,
} , DistXLSetupType , nil } ,
{ ":9000" , [ ] [ ] string { { case5Endpoint1 , case5Endpoint2 , case5Endpoint3 , case5Endpoint4 } } , ":9000" , EndpointList {
{ ":9000" , [ ] [ ] string { { case5Endpoint1 , case5Endpoint2 , case5Endpoint3 , case5Endpoint4 } } , ":9000" , EndpointList {
Endpoint { URL : case5URLs [ 0 ] , IsLocal : case5LocalFlags [ 0 ] } ,
Endpoint { URL : case5URLs [ 0 ] , IsLocal : case5LocalFlags [ 0 ] , HostName : nonLoopBackIP } ,
Endpoint { URL : case5URLs [ 1 ] , IsLocal : case5LocalFlags [ 1 ] } ,
Endpoint { URL : case5URLs [ 1 ] , IsLocal : case5LocalFlags [ 1 ] , HostName : nonLoopBackIP } ,
Endpoint { URL : case5URLs [ 2 ] , IsLocal : case5LocalFlags [ 2 ] } ,
Endpoint { URL : case5URLs [ 2 ] , IsLocal : case5LocalFlags [ 2 ] , HostName : nonLoopBackIP } ,
Endpoint { URL : case5URLs [ 3 ] , IsLocal : case5LocalFlags [ 3 ] } ,
Endpoint { URL : case5URLs [ 3 ] , IsLocal : case5LocalFlags [ 3 ] , HostName : nonLoopBackIP } ,
} , DistXLSetupType , nil } ,
} , DistXLSetupType , nil } ,
// DistXL Setup using only local host.
// DistXL Setup using only local host.
{ ":9003" , [ ] [ ] string { { "http://localhost:9000/d1" , "http://localhost:9001/d2" , "http://127.0.0.1:9002/d3" , case6Endpoint } } , ":9003" , EndpointList {
{ ":9003" , [ ] [ ] string { { "http://localhost:9000/d1" , "http://localhost:9001/d2" , "http://127.0.0.1:9002/d3" , case6Endpoint } } , ":9003" , EndpointList {
Endpoint { URL : case6URLs [ 0 ] , IsLocal : case6LocalFlags [ 0 ] } ,
Endpoint { URL : case6URLs [ 0 ] , IsLocal : case6LocalFlags [ 0 ] , HostName : "localhost" } ,
Endpoint { URL : case6URLs [ 1 ] , IsLocal : case6LocalFlags [ 1 ] } ,
Endpoint { URL : case6URLs [ 1 ] , IsLocal : case6LocalFlags [ 1 ] , HostName : "localhost" } ,
Endpoint { URL : case6URLs [ 2 ] , IsLocal : case6LocalFlags [ 2 ] } ,
Endpoint { URL : case6URLs [ 2 ] , IsLocal : case6LocalFlags [ 2 ] , HostName : "127.0.0.1" } ,
Endpoint { URL : case6URLs [ 3 ] , IsLocal : case6LocalFlags [ 3 ] } ,
Endpoint { URL : case6URLs [ 3 ] , IsLocal : case6LocalFlags [ 3 ] , HostName : nonLoopBackIP } ,
} , DistXLSetupType , nil } ,
} , DistXLSetupType , nil } ,
}
}
@ -357,6 +361,11 @@ func TestGetLocalPeer(t *testing.T) {
for i , testCase := range testCases {
for i , testCase := range testCases {
endpoints , _ := NewEndpointList ( testCase . endpointArgs ... )
endpoints , _ := NewEndpointList ( testCase . endpointArgs ... )
if ! endpoints [ 0 ] . IsLocal {
if err := endpoints . UpdateIsLocal ( ) ; err != nil {
t . Fatalf ( "error: expected = <nil>, got = %v" , err )
}
}
remotePeer := GetLocalPeer ( endpoints )
remotePeer := GetLocalPeer ( endpoints )
if remotePeer != testCase . expectedResult {
if remotePeer != testCase . expectedResult {
t . Fatalf ( "Test %d: expected: %v, got: %v" , i + 1 , testCase . expectedResult , remotePeer )
t . Fatalf ( "Test %d: expected: %v, got: %v" , i + 1 , testCase . expectedResult , remotePeer )
@ -384,6 +393,11 @@ func TestGetRemotePeers(t *testing.T) {
for _ , testCase := range testCases {
for _ , testCase := range testCases {
endpoints , _ := NewEndpointList ( testCase . endpointArgs ... )
endpoints , _ := NewEndpointList ( testCase . endpointArgs ... )
if ! endpoints [ 0 ] . IsLocal {
if err := endpoints . UpdateIsLocal ( ) ; err != nil {
t . Fatalf ( "error: expected = <nil>, got = %v" , err )
}
}
remotePeers := GetRemotePeers ( endpoints )
remotePeers := GetRemotePeers ( endpoints )
if ! reflect . DeepEqual ( remotePeers , testCase . expectedResult ) {
if ! reflect . DeepEqual ( remotePeers , testCase . expectedResult ) {
t . Fatalf ( "expected: %v, got: %v" , testCase . expectedResult , remotePeers )
t . Fatalf ( "expected: %v, got: %v" , testCase . expectedResult , remotePeers )