2018-06-29 19:28:06 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
package transport
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2018-07-03 09:35:01 +01:00
|
|
|
|
2018-11-29 18:39:27 +00:00
|
|
|
"storj.io/storj/internal/identity"
|
|
|
|
"storj.io/storj/internal/teststorj"
|
2018-09-18 05:39:06 +01:00
|
|
|
"storj.io/storj/pkg/pb"
|
2018-06-29 19:28:06 +01:00
|
|
|
)
|
|
|
|
|
2018-08-24 05:01:03 +01:00
|
|
|
var ctx = context.Background()
|
|
|
|
|
2018-06-29 19:28:06 +01:00
|
|
|
func TestDialNode(t *testing.T) {
|
2018-11-29 18:39:27 +00:00
|
|
|
ca, err := testidentity.NewTestCA(ctx)
|
2018-08-24 05:01:03 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
identity, err := ca.NewIdentity()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
oc := Transport{
|
|
|
|
identity: identity,
|
|
|
|
}
|
2018-06-29 19:28:06 +01:00
|
|
|
|
|
|
|
// node.Address.Address == "" condition test
|
2018-09-18 05:39:06 +01:00
|
|
|
node := pb.Node{
|
2018-11-29 18:39:27 +00:00
|
|
|
Id: teststorj.NodeIDFromString("DUMMYID1"),
|
2018-09-18 05:39:06 +01:00
|
|
|
Address: &pb.NodeAddress{
|
2018-10-15 13:04:21 +01:00
|
|
|
Transport: pb.NodeTransport_TCP_TLS_GRPC,
|
2018-06-29 19:28:06 +01:00
|
|
|
Address: "",
|
|
|
|
},
|
|
|
|
}
|
2018-08-24 05:01:03 +01:00
|
|
|
conn, err := oc.DialNode(ctx, &node)
|
2018-06-29 19:28:06 +01:00
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Nil(t, conn)
|
|
|
|
|
|
|
|
// node.Address == nil condition test
|
2018-09-18 05:39:06 +01:00
|
|
|
node = pb.Node{
|
2018-11-29 18:39:27 +00:00
|
|
|
Id: teststorj.NodeIDFromString("DUMMYID2"),
|
2018-06-29 19:28:06 +01:00
|
|
|
Address: nil,
|
|
|
|
}
|
2018-08-24 05:01:03 +01:00
|
|
|
conn, err = oc.DialNode(ctx, &node)
|
2018-06-29 19:28:06 +01:00
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Nil(t, conn)
|
|
|
|
|
|
|
|
// node is valid argument condition test
|
2018-09-18 05:39:06 +01:00
|
|
|
node = pb.Node{
|
2018-11-29 18:39:27 +00:00
|
|
|
Id: teststorj.NodeIDFromString("DUMMYID3"),
|
2018-09-18 05:39:06 +01:00
|
|
|
Address: &pb.NodeAddress{
|
2018-10-15 13:04:21 +01:00
|
|
|
Transport: pb.NodeTransport_TCP_TLS_GRPC,
|
2018-06-29 19:28:06 +01:00
|
|
|
Address: "127.0.0.0:9000",
|
|
|
|
},
|
|
|
|
}
|
2018-08-24 05:01:03 +01:00
|
|
|
conn, err = oc.DialNode(ctx, &node)
|
2018-06-29 19:28:06 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, conn)
|
|
|
|
}
|