storj/pkg/node/node_test.go
nfarah86 e228d090e8
Mutex/nsclient- WIP (#104)
* working on put request for nsclient

* working on put request for nsclient

* netstate put

* netstate put

* wip testing client

* wip - testing client
 and working through some errors

* wip - testing client
 and working through some errors

* put request works

* put request works for client

* get request working

* get request working

* get request working-minor edit

* get request working-minor edit

* list request works

* list request works

* working through delete error

* working through delete error

* fixed exp client, still working through delete error

* fixed exp client, still working through delete error

* delete works; fixed formatting issues

* delete works; fixed formatting issues

* deleted comment

* deleted comment

* resolving merge conflicts

* resolving merge conflict

* fixing merge conflict

* implemented and modified kayloyans paths file

* working on testing

* added test for path_test.go

* fixed string, read through netstate test

* deleted env variables

* initial commit for mocking out grpc client- got it working

* mocked grpc client

* mock put passed test

* 2 tests pass for PUT with mock

* put requests test pass, wip- want mini review

* get tests pass mock

* list test working

* initial commit for list test

* all list req. working, starting on delete tests

* delete tests passed

* cleaned up tests

* resolved merge conflicts

* resolved merge conflicts

* fixed linter errors

* fixed error found in travis

* initial commit for fixes from PR comments

* fixed pr comments and linting

* added error handling for api creds, and rebased

* fixes from dennis comments

* fixed pr with dennis suggestioon

* added copyrights to files

* fixed casing per dennis great comment

* fixed travis complaint on sprintf
2018-07-19 15:57:22 -07:00

70 lines
1.6 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package node
import (
"context"
"fmt"
"net"
"testing"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"storj.io/storj/internal/test"
proto "storj.io/storj/protos/overlay"
)
func TestLookup(t *testing.T) {
cases := []struct {
self proto.Node
to proto.Node
find proto.Node
expectedErr error
expectedNumNodes int
}{
{
self: proto.Node{Id: test.NewNodeID(t), Address: &proto.NodeAddress{Address: ":7070"}},
to: proto.Node{Id: test.NewNodeID(t), Address: &proto.NodeAddress{Address: ":8080"}},
find: proto.Node{Id: test.NewNodeID(t), Address: &proto.NodeAddress{Address: ":9090"}},
expectedErr: nil,
},
}
for _, v := range cases {
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", 8080))
assert.NoError(t, err)
srv, mock := newTestServer()
go srv.Serve(lis)
defer srv.Stop()
nc, err := NewNodeClient(v.self)
assert.NoError(t, err)
_, err = nc.Lookup(context.Background(), v.to, v.find)
assert.Equal(t, v.expectedErr, err)
assert.Equal(t, 1, mock.queryCalled)
}
}
func newTestServer() (*grpc.Server, *mockNodeServer) {
grpcServer := grpc.NewServer()
mn := &mockNodeServer{queryCalled: 0}
proto.RegisterNodesServer(grpcServer, mn)
return grpcServer, mn
}
type mockNodeServer struct {
queryCalled int
}
func (mn *mockNodeServer) Query(ctx context.Context, req *proto.QueryRequest) (*proto.QueryResponse, error) {
mn.queryCalled++
return &proto.QueryResponse{}, nil
}