storj/pkg/pointerdb/pointerdb_test.go

345 lines
8.8 KiB
Go
Raw Normal View History

adds netstate pagination (#95) * adds netstate rpc server pagination, mocks pagination in test/util.go * updates ns client example, combines ns client and server test to netstate_test, adds pagination to bolt client * better organizes netstate test calls * wip breaking netstate test into smaller tests * wip modularizing netstate tests * adds some test panics * wip netstate test attempts * testing bug in netstate TestDeleteAuth * wip fixes global variable problem, still issues with list * wip fixes get request params and args * fixes bug in path when using MakePointers helper fn * updates mockdb list func, adds test, changes Limit to int * fixes merge conflicts * fixes broken tests from merge * remove unnecessary PointerEntry struct * removes error when Get returns nil value from boltdb * breaks boltdb client tests into smaller tests * renames AssertNoErr test helper to HandleErr * adds StartingKey and Limit parameters to redis list func, adds beginning of redis tests * adds helper func for mockdb List function * if no starting key provided for netstate List, the first value in storage will be used * adds basic pagination for redis List function, adds tests * adds list limit to call in overlay/server.go * streamlines/fixes some nits from review * removes use of obsolete EncryptedUnencryptedSize * uses MockKeyValueStore instead of redis instance in redis client test * changes test to expect nil returned for getting missing key * remove error from `KeyValueStore#Get` * fix bolt test * Merge pull request #1 from bryanchriswhite/nat-pagination remove error from `KeyValueStore#Get` * adds Get returning error back to KeyValueStore interface and affected clients * trying to appease travis: returns errors in Get calls in overlay/cache and cache_test * handles redis get error when no key found
2018-06-29 21:06:25 +01:00
// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package pointerdb
adds netstate pagination (#95) * adds netstate rpc server pagination, mocks pagination in test/util.go * updates ns client example, combines ns client and server test to netstate_test, adds pagination to bolt client * better organizes netstate test calls * wip breaking netstate test into smaller tests * wip modularizing netstate tests * adds some test panics * wip netstate test attempts * testing bug in netstate TestDeleteAuth * wip fixes global variable problem, still issues with list * wip fixes get request params and args * fixes bug in path when using MakePointers helper fn * updates mockdb list func, adds test, changes Limit to int * fixes merge conflicts * fixes broken tests from merge * remove unnecessary PointerEntry struct * removes error when Get returns nil value from boltdb * breaks boltdb client tests into smaller tests * renames AssertNoErr test helper to HandleErr * adds StartingKey and Limit parameters to redis list func, adds beginning of redis tests * adds helper func for mockdb List function * if no starting key provided for netstate List, the first value in storage will be used * adds basic pagination for redis List function, adds tests * adds list limit to call in overlay/server.go * streamlines/fixes some nits from review * removes use of obsolete EncryptedUnencryptedSize * uses MockKeyValueStore instead of redis instance in redis client test * changes test to expect nil returned for getting missing key * remove error from `KeyValueStore#Get` * fix bolt test * Merge pull request #1 from bryanchriswhite/nat-pagination remove error from `KeyValueStore#Get` * adds Get returning error back to KeyValueStore interface and affected clients * trying to appease travis: returns errors in Get calls in overlay/cache and cache_test * handles redis get error when no key found
2018-06-29 21:06:25 +01:00
import (
"context"
"crypto/tls"
"crypto/x509"
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 23:57:22 +01:00
"errors"
"fmt"
adds netstate pagination (#95) * adds netstate rpc server pagination, mocks pagination in test/util.go * updates ns client example, combines ns client and server test to netstate_test, adds pagination to bolt client * better organizes netstate test calls * wip breaking netstate test into smaller tests * wip modularizing netstate tests * adds some test panics * wip netstate test attempts * testing bug in netstate TestDeleteAuth * wip fixes global variable problem, still issues with list * wip fixes get request params and args * fixes bug in path when using MakePointers helper fn * updates mockdb list func, adds test, changes Limit to int * fixes merge conflicts * fixes broken tests from merge * remove unnecessary PointerEntry struct * removes error when Get returns nil value from boltdb * breaks boltdb client tests into smaller tests * renames AssertNoErr test helper to HandleErr * adds StartingKey and Limit parameters to redis list func, adds beginning of redis tests * adds helper func for mockdb List function * if no starting key provided for netstate List, the first value in storage will be used * adds basic pagination for redis List function, adds tests * adds list limit to call in overlay/server.go * streamlines/fixes some nits from review * removes use of obsolete EncryptedUnencryptedSize * uses MockKeyValueStore instead of redis instance in redis client test * changes test to expect nil returned for getting missing key * remove error from `KeyValueStore#Get` * fix bolt test * Merge pull request #1 from bryanchriswhite/nat-pagination remove error from `KeyValueStore#Get` * adds Get returning error back to KeyValueStore interface and affected clients * trying to appease travis: returns errors in Get calls in overlay/cache and cache_test * handles redis get error when no key found
2018-06-29 21:06:25 +01:00
"testing"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"github.com/google/go-cmp/cmp"
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 23:57:22 +01:00
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/status"
adds netstate pagination (#95) * adds netstate rpc server pagination, mocks pagination in test/util.go * updates ns client example, combines ns client and server test to netstate_test, adds pagination to bolt client * better organizes netstate test calls * wip breaking netstate test into smaller tests * wip modularizing netstate tests * adds some test panics * wip netstate test attempts * testing bug in netstate TestDeleteAuth * wip fixes global variable problem, still issues with list * wip fixes get request params and args * fixes bug in path when using MakePointers helper fn * updates mockdb list func, adds test, changes Limit to int * fixes merge conflicts * fixes broken tests from merge * remove unnecessary PointerEntry struct * removes error when Get returns nil value from boltdb * breaks boltdb client tests into smaller tests * renames AssertNoErr test helper to HandleErr * adds StartingKey and Limit parameters to redis list func, adds beginning of redis tests * adds helper func for mockdb List function * if no starting key provided for netstate List, the first value in storage will be used * adds basic pagination for redis List function, adds tests * adds list limit to call in overlay/server.go * streamlines/fixes some nits from review * removes use of obsolete EncryptedUnencryptedSize * uses MockKeyValueStore instead of redis instance in redis client test * changes test to expect nil returned for getting missing key * remove error from `KeyValueStore#Get` * fix bolt test * Merge pull request #1 from bryanchriswhite/nat-pagination remove error from `KeyValueStore#Get` * adds Get returning error back to KeyValueStore interface and affected clients * trying to appease travis: returns errors in Get calls in overlay/cache and cache_test * handles redis get error when no key found
2018-06-29 21:06:25 +01:00
"storj.io/storj/pkg/auth"
"storj.io/storj/pkg/pb"
"storj.io/storj/pkg/provider"
"storj.io/storj/pkg/storage/meta"
"storj.io/storj/storage"
"storj.io/storj/storage/teststore"
)
func TestServicePut(t *testing.T) {
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 23:57:22 +01:00
for i, tt := range []struct {
apiKey []byte
err error
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 23:57:22 +01:00
errString string
}{
{nil, nil, ""},
{[]byte("wrong key"), nil, status.Errorf(codes.Unauthenticated, "Invalid API credential").Error()},
{nil, errors.New("put error"), status.Errorf(codes.Internal, "internal error").Error()},
} {
ctx := context.Background()
ctx = auth.WithAPIKey(ctx, tt.apiKey)
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 23:57:22 +01:00
errTag := fmt.Sprintf("Test case #%d", i)
db := teststore.New()
s := Server{DB: db, logger: zap.NewNop()}
path := "a/b/c"
pr := pb.Pointer{}
if tt.err != nil {
db.ForceError++
}
req := pb.PutRequest{Path: path, Pointer: &pr}
_, err := s.Put(ctx, &req)
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 23:57:22 +01:00
if err != nil {
assert.EqualError(t, err, tt.errString, errTag)
} else {
assert.NoError(t, err, errTag)
}
adds netstate pagination (#95) * adds netstate rpc server pagination, mocks pagination in test/util.go * updates ns client example, combines ns client and server test to netstate_test, adds pagination to bolt client * better organizes netstate test calls * wip breaking netstate test into smaller tests * wip modularizing netstate tests * adds some test panics * wip netstate test attempts * testing bug in netstate TestDeleteAuth * wip fixes global variable problem, still issues with list * wip fixes get request params and args * fixes bug in path when using MakePointers helper fn * updates mockdb list func, adds test, changes Limit to int * fixes merge conflicts * fixes broken tests from merge * remove unnecessary PointerEntry struct * removes error when Get returns nil value from boltdb * breaks boltdb client tests into smaller tests * renames AssertNoErr test helper to HandleErr * adds StartingKey and Limit parameters to redis list func, adds beginning of redis tests * adds helper func for mockdb List function * if no starting key provided for netstate List, the first value in storage will be used * adds basic pagination for redis List function, adds tests * adds list limit to call in overlay/server.go * streamlines/fixes some nits from review * removes use of obsolete EncryptedUnencryptedSize * uses MockKeyValueStore instead of redis instance in redis client test * changes test to expect nil returned for getting missing key * remove error from `KeyValueStore#Get` * fix bolt test * Merge pull request #1 from bryanchriswhite/nat-pagination remove error from `KeyValueStore#Get` * adds Get returning error back to KeyValueStore interface and affected clients * trying to appease travis: returns errors in Get calls in overlay/cache and cache_test * handles redis get error when no key found
2018-06-29 21:06:25 +01:00
}
}
func TestServiceGet(t *testing.T) {
ctx := context.Background()
ca, err := provider.NewTestCA(ctx)
assert.NoError(t, err)
identity, err := ca.NewIdentity()
assert.NoError(t, err)
peerCertificates := make([]*x509.Certificate, 2)
peerCertificates[0] = identity.Leaf
peerCertificates[1] = identity.CA
info := credentials.TLSInfo{State: tls.ConnectionState{PeerCertificates: peerCertificates}}
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 23:57:22 +01:00
for i, tt := range []struct {
apiKey []byte
err error
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 23:57:22 +01:00
errString string
}{
{nil, nil, ""},
{[]byte("wrong key"), nil, status.Errorf(codes.Unauthenticated, "Invalid API credential").Error()},
{nil, errors.New("get error"), status.Errorf(codes.Internal, "internal error").Error()},
} {
ctx = auth.WithAPIKey(ctx, tt.apiKey)
ctx = peer.NewContext(ctx, &peer.Peer{AuthInfo: info})
errTag := fmt.Sprintf("Test case #%d", i)
adds netstate pagination (#95) * adds netstate rpc server pagination, mocks pagination in test/util.go * updates ns client example, combines ns client and server test to netstate_test, adds pagination to bolt client * better organizes netstate test calls * wip breaking netstate test into smaller tests * wip modularizing netstate tests * adds some test panics * wip netstate test attempts * testing bug in netstate TestDeleteAuth * wip fixes global variable problem, still issues with list * wip fixes get request params and args * fixes bug in path when using MakePointers helper fn * updates mockdb list func, adds test, changes Limit to int * fixes merge conflicts * fixes broken tests from merge * remove unnecessary PointerEntry struct * removes error when Get returns nil value from boltdb * breaks boltdb client tests into smaller tests * renames AssertNoErr test helper to HandleErr * adds StartingKey and Limit parameters to redis list func, adds beginning of redis tests * adds helper func for mockdb List function * if no starting key provided for netstate List, the first value in storage will be used * adds basic pagination for redis List function, adds tests * adds list limit to call in overlay/server.go * streamlines/fixes some nits from review * removes use of obsolete EncryptedUnencryptedSize * uses MockKeyValueStore instead of redis instance in redis client test * changes test to expect nil returned for getting missing key * remove error from `KeyValueStore#Get` * fix bolt test * Merge pull request #1 from bryanchriswhite/nat-pagination remove error from `KeyValueStore#Get` * adds Get returning error back to KeyValueStore interface and affected clients * trying to appease travis: returns errors in Get calls in overlay/cache and cache_test * handles redis get error when no key found
2018-06-29 21:06:25 +01:00
db := teststore.New()
s := Server{DB: db, logger: zap.NewNop(), identity: identity}
adds netstate pagination (#95) * adds netstate rpc server pagination, mocks pagination in test/util.go * updates ns client example, combines ns client and server test to netstate_test, adds pagination to bolt client * better organizes netstate test calls * wip breaking netstate test into smaller tests * wip modularizing netstate tests * adds some test panics * wip netstate test attempts * testing bug in netstate TestDeleteAuth * wip fixes global variable problem, still issues with list * wip fixes get request params and args * fixes bug in path when using MakePointers helper fn * updates mockdb list func, adds test, changes Limit to int * fixes merge conflicts * fixes broken tests from merge * remove unnecessary PointerEntry struct * removes error when Get returns nil value from boltdb * breaks boltdb client tests into smaller tests * renames AssertNoErr test helper to HandleErr * adds StartingKey and Limit parameters to redis list func, adds beginning of redis tests * adds helper func for mockdb List function * if no starting key provided for netstate List, the first value in storage will be used * adds basic pagination for redis List function, adds tests * adds list limit to call in overlay/server.go * streamlines/fixes some nits from review * removes use of obsolete EncryptedUnencryptedSize * uses MockKeyValueStore instead of redis instance in redis client test * changes test to expect nil returned for getting missing key * remove error from `KeyValueStore#Get` * fix bolt test * Merge pull request #1 from bryanchriswhite/nat-pagination remove error from `KeyValueStore#Get` * adds Get returning error back to KeyValueStore interface and affected clients * trying to appease travis: returns errors in Get calls in overlay/cache and cache_test * handles redis get error when no key found
2018-06-29 21:06:25 +01:00
path := "a/b/c"
pr := &pb.Pointer{Size: 123}
prBytes, err := proto.Marshal(pr)
assert.NoError(t, err, errTag)
adds netstate pagination (#95) * adds netstate rpc server pagination, mocks pagination in test/util.go * updates ns client example, combines ns client and server test to netstate_test, adds pagination to bolt client * better organizes netstate test calls * wip breaking netstate test into smaller tests * wip modularizing netstate tests * adds some test panics * wip netstate test attempts * testing bug in netstate TestDeleteAuth * wip fixes global variable problem, still issues with list * wip fixes get request params and args * fixes bug in path when using MakePointers helper fn * updates mockdb list func, adds test, changes Limit to int * fixes merge conflicts * fixes broken tests from merge * remove unnecessary PointerEntry struct * removes error when Get returns nil value from boltdb * breaks boltdb client tests into smaller tests * renames AssertNoErr test helper to HandleErr * adds StartingKey and Limit parameters to redis list func, adds beginning of redis tests * adds helper func for mockdb List function * if no starting key provided for netstate List, the first value in storage will be used * adds basic pagination for redis List function, adds tests * adds list limit to call in overlay/server.go * streamlines/fixes some nits from review * removes use of obsolete EncryptedUnencryptedSize * uses MockKeyValueStore instead of redis instance in redis client test * changes test to expect nil returned for getting missing key * remove error from `KeyValueStore#Get` * fix bolt test * Merge pull request #1 from bryanchriswhite/nat-pagination remove error from `KeyValueStore#Get` * adds Get returning error back to KeyValueStore interface and affected clients * trying to appease travis: returns errors in Get calls in overlay/cache and cache_test * handles redis get error when no key found
2018-06-29 21:06:25 +01:00
_ = db.Put(storage.Key(path), storage.Value(prBytes))
if tt.err != nil {
db.ForceError++
}
adds netstate pagination (#95) * adds netstate rpc server pagination, mocks pagination in test/util.go * updates ns client example, combines ns client and server test to netstate_test, adds pagination to bolt client * better organizes netstate test calls * wip breaking netstate test into smaller tests * wip modularizing netstate tests * adds some test panics * wip netstate test attempts * testing bug in netstate TestDeleteAuth * wip fixes global variable problem, still issues with list * wip fixes get request params and args * fixes bug in path when using MakePointers helper fn * updates mockdb list func, adds test, changes Limit to int * fixes merge conflicts * fixes broken tests from merge * remove unnecessary PointerEntry struct * removes error when Get returns nil value from boltdb * breaks boltdb client tests into smaller tests * renames AssertNoErr test helper to HandleErr * adds StartingKey and Limit parameters to redis list func, adds beginning of redis tests * adds helper func for mockdb List function * if no starting key provided for netstate List, the first value in storage will be used * adds basic pagination for redis List function, adds tests * adds list limit to call in overlay/server.go * streamlines/fixes some nits from review * removes use of obsolete EncryptedUnencryptedSize * uses MockKeyValueStore instead of redis instance in redis client test * changes test to expect nil returned for getting missing key * remove error from `KeyValueStore#Get` * fix bolt test * Merge pull request #1 from bryanchriswhite/nat-pagination remove error from `KeyValueStore#Get` * adds Get returning error back to KeyValueStore interface and affected clients * trying to appease travis: returns errors in Get calls in overlay/cache and cache_test * handles redis get error when no key found
2018-06-29 21:06:25 +01:00
req := pb.GetRequest{Path: path}
resp, err := s.Get(ctx, &req)
adds netstate pagination (#95) * adds netstate rpc server pagination, mocks pagination in test/util.go * updates ns client example, combines ns client and server test to netstate_test, adds pagination to bolt client * better organizes netstate test calls * wip breaking netstate test into smaller tests * wip modularizing netstate tests * adds some test panics * wip netstate test attempts * testing bug in netstate TestDeleteAuth * wip fixes global variable problem, still issues with list * wip fixes get request params and args * fixes bug in path when using MakePointers helper fn * updates mockdb list func, adds test, changes Limit to int * fixes merge conflicts * fixes broken tests from merge * remove unnecessary PointerEntry struct * removes error when Get returns nil value from boltdb * breaks boltdb client tests into smaller tests * renames AssertNoErr test helper to HandleErr * adds StartingKey and Limit parameters to redis list func, adds beginning of redis tests * adds helper func for mockdb List function * if no starting key provided for netstate List, the first value in storage will be used * adds basic pagination for redis List function, adds tests * adds list limit to call in overlay/server.go * streamlines/fixes some nits from review * removes use of obsolete EncryptedUnencryptedSize * uses MockKeyValueStore instead of redis instance in redis client test * changes test to expect nil returned for getting missing key * remove error from `KeyValueStore#Get` * fix bolt test * Merge pull request #1 from bryanchriswhite/nat-pagination remove error from `KeyValueStore#Get` * adds Get returning error back to KeyValueStore interface and affected clients * trying to appease travis: returns errors in Get calls in overlay/cache and cache_test * handles redis get error when no key found
2018-06-29 21:06:25 +01:00
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 23:57:22 +01:00
if err != nil {
assert.EqualError(t, err, tt.errString, errTag)
} else {
assert.NoError(t, err, errTag)
assert.NoError(t, err, errTag)
assert.True(t, proto.Equal(pr, resp.Pointer), errTag)
assert.NotNil(t, resp.GetAuthorization())
assert.NotNil(t, resp.GetPba())
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 23:57:22 +01:00
}
adds netstate pagination (#95) * adds netstate rpc server pagination, mocks pagination in test/util.go * updates ns client example, combines ns client and server test to netstate_test, adds pagination to bolt client * better organizes netstate test calls * wip breaking netstate test into smaller tests * wip modularizing netstate tests * adds some test panics * wip netstate test attempts * testing bug in netstate TestDeleteAuth * wip fixes global variable problem, still issues with list * wip fixes get request params and args * fixes bug in path when using MakePointers helper fn * updates mockdb list func, adds test, changes Limit to int * fixes merge conflicts * fixes broken tests from merge * remove unnecessary PointerEntry struct * removes error when Get returns nil value from boltdb * breaks boltdb client tests into smaller tests * renames AssertNoErr test helper to HandleErr * adds StartingKey and Limit parameters to redis list func, adds beginning of redis tests * adds helper func for mockdb List function * if no starting key provided for netstate List, the first value in storage will be used * adds basic pagination for redis List function, adds tests * adds list limit to call in overlay/server.go * streamlines/fixes some nits from review * removes use of obsolete EncryptedUnencryptedSize * uses MockKeyValueStore instead of redis instance in redis client test * changes test to expect nil returned for getting missing key * remove error from `KeyValueStore#Get` * fix bolt test * Merge pull request #1 from bryanchriswhite/nat-pagination remove error from `KeyValueStore#Get` * adds Get returning error back to KeyValueStore interface and affected clients * trying to appease travis: returns errors in Get calls in overlay/cache and cache_test * handles redis get error when no key found
2018-06-29 21:06:25 +01:00
}
}
func TestServiceDelete(t *testing.T) {
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 23:57:22 +01:00
for i, tt := range []struct {
apiKey []byte
err error
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 23:57:22 +01:00
errString string
}{
{nil, nil, ""},
{[]byte("wrong key"), nil, status.Errorf(codes.Unauthenticated, "Invalid API credential").Error()},
{nil, errors.New("delete error"), status.Errorf(codes.Internal, "internal error").Error()},
} {
ctx := context.Background()
ctx = auth.WithAPIKey(ctx, tt.apiKey)
errTag := fmt.Sprintf("Test case #%d", i)
adds netstate pagination (#95) * adds netstate rpc server pagination, mocks pagination in test/util.go * updates ns client example, combines ns client and server test to netstate_test, adds pagination to bolt client * better organizes netstate test calls * wip breaking netstate test into smaller tests * wip modularizing netstate tests * adds some test panics * wip netstate test attempts * testing bug in netstate TestDeleteAuth * wip fixes global variable problem, still issues with list * wip fixes get request params and args * fixes bug in path when using MakePointers helper fn * updates mockdb list func, adds test, changes Limit to int * fixes merge conflicts * fixes broken tests from merge * remove unnecessary PointerEntry struct * removes error when Get returns nil value from boltdb * breaks boltdb client tests into smaller tests * renames AssertNoErr test helper to HandleErr * adds StartingKey and Limit parameters to redis list func, adds beginning of redis tests * adds helper func for mockdb List function * if no starting key provided for netstate List, the first value in storage will be used * adds basic pagination for redis List function, adds tests * adds list limit to call in overlay/server.go * streamlines/fixes some nits from review * removes use of obsolete EncryptedUnencryptedSize * uses MockKeyValueStore instead of redis instance in redis client test * changes test to expect nil returned for getting missing key * remove error from `KeyValueStore#Get` * fix bolt test * Merge pull request #1 from bryanchriswhite/nat-pagination remove error from `KeyValueStore#Get` * adds Get returning error back to KeyValueStore interface and affected clients * trying to appease travis: returns errors in Get calls in overlay/cache and cache_test * handles redis get error when no key found
2018-06-29 21:06:25 +01:00
path := "a/b/c"
adds netstate pagination (#95) * adds netstate rpc server pagination, mocks pagination in test/util.go * updates ns client example, combines ns client and server test to netstate_test, adds pagination to bolt client * better organizes netstate test calls * wip breaking netstate test into smaller tests * wip modularizing netstate tests * adds some test panics * wip netstate test attempts * testing bug in netstate TestDeleteAuth * wip fixes global variable problem, still issues with list * wip fixes get request params and args * fixes bug in path when using MakePointers helper fn * updates mockdb list func, adds test, changes Limit to int * fixes merge conflicts * fixes broken tests from merge * remove unnecessary PointerEntry struct * removes error when Get returns nil value from boltdb * breaks boltdb client tests into smaller tests * renames AssertNoErr test helper to HandleErr * adds StartingKey and Limit parameters to redis list func, adds beginning of redis tests * adds helper func for mockdb List function * if no starting key provided for netstate List, the first value in storage will be used * adds basic pagination for redis List function, adds tests * adds list limit to call in overlay/server.go * streamlines/fixes some nits from review * removes use of obsolete EncryptedUnencryptedSize * uses MockKeyValueStore instead of redis instance in redis client test * changes test to expect nil returned for getting missing key * remove error from `KeyValueStore#Get` * fix bolt test * Merge pull request #1 from bryanchriswhite/nat-pagination remove error from `KeyValueStore#Get` * adds Get returning error back to KeyValueStore interface and affected clients * trying to appease travis: returns errors in Get calls in overlay/cache and cache_test * handles redis get error when no key found
2018-06-29 21:06:25 +01:00
db := teststore.New()
_ = db.Put(storage.Key(path), storage.Value("hello"))
s := Server{DB: db, logger: zap.NewNop()}
if tt.err != nil {
db.ForceError++
}
adds netstate pagination (#95) * adds netstate rpc server pagination, mocks pagination in test/util.go * updates ns client example, combines ns client and server test to netstate_test, adds pagination to bolt client * better organizes netstate test calls * wip breaking netstate test into smaller tests * wip modularizing netstate tests * adds some test panics * wip netstate test attempts * testing bug in netstate TestDeleteAuth * wip fixes global variable problem, still issues with list * wip fixes get request params and args * fixes bug in path when using MakePointers helper fn * updates mockdb list func, adds test, changes Limit to int * fixes merge conflicts * fixes broken tests from merge * remove unnecessary PointerEntry struct * removes error when Get returns nil value from boltdb * breaks boltdb client tests into smaller tests * renames AssertNoErr test helper to HandleErr * adds StartingKey and Limit parameters to redis list func, adds beginning of redis tests * adds helper func for mockdb List function * if no starting key provided for netstate List, the first value in storage will be used * adds basic pagination for redis List function, adds tests * adds list limit to call in overlay/server.go * streamlines/fixes some nits from review * removes use of obsolete EncryptedUnencryptedSize * uses MockKeyValueStore instead of redis instance in redis client test * changes test to expect nil returned for getting missing key * remove error from `KeyValueStore#Get` * fix bolt test * Merge pull request #1 from bryanchriswhite/nat-pagination remove error from `KeyValueStore#Get` * adds Get returning error back to KeyValueStore interface and affected clients * trying to appease travis: returns errors in Get calls in overlay/cache and cache_test * handles redis get error when no key found
2018-06-29 21:06:25 +01:00
req := pb.DeleteRequest{Path: path}
_, err := s.Delete(ctx, &req)
adds netstate pagination (#95) * adds netstate rpc server pagination, mocks pagination in test/util.go * updates ns client example, combines ns client and server test to netstate_test, adds pagination to bolt client * better organizes netstate test calls * wip breaking netstate test into smaller tests * wip modularizing netstate tests * adds some test panics * wip netstate test attempts * testing bug in netstate TestDeleteAuth * wip fixes global variable problem, still issues with list * wip fixes get request params and args * fixes bug in path when using MakePointers helper fn * updates mockdb list func, adds test, changes Limit to int * fixes merge conflicts * fixes broken tests from merge * remove unnecessary PointerEntry struct * removes error when Get returns nil value from boltdb * breaks boltdb client tests into smaller tests * renames AssertNoErr test helper to HandleErr * adds StartingKey and Limit parameters to redis list func, adds beginning of redis tests * adds helper func for mockdb List function * if no starting key provided for netstate List, the first value in storage will be used * adds basic pagination for redis List function, adds tests * adds list limit to call in overlay/server.go * streamlines/fixes some nits from review * removes use of obsolete EncryptedUnencryptedSize * uses MockKeyValueStore instead of redis instance in redis client test * changes test to expect nil returned for getting missing key * remove error from `KeyValueStore#Get` * fix bolt test * Merge pull request #1 from bryanchriswhite/nat-pagination remove error from `KeyValueStore#Get` * adds Get returning error back to KeyValueStore interface and affected clients * trying to appease travis: returns errors in Get calls in overlay/cache and cache_test * handles redis get error when no key found
2018-06-29 21:06:25 +01:00
if err != nil {
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 23:57:22 +01:00
assert.EqualError(t, err, tt.errString, errTag)
} else {
assert.NoError(t, err, errTag)
adds netstate pagination (#95) * adds netstate rpc server pagination, mocks pagination in test/util.go * updates ns client example, combines ns client and server test to netstate_test, adds pagination to bolt client * better organizes netstate test calls * wip breaking netstate test into smaller tests * wip modularizing netstate tests * adds some test panics * wip netstate test attempts * testing bug in netstate TestDeleteAuth * wip fixes global variable problem, still issues with list * wip fixes get request params and args * fixes bug in path when using MakePointers helper fn * updates mockdb list func, adds test, changes Limit to int * fixes merge conflicts * fixes broken tests from merge * remove unnecessary PointerEntry struct * removes error when Get returns nil value from boltdb * breaks boltdb client tests into smaller tests * renames AssertNoErr test helper to HandleErr * adds StartingKey and Limit parameters to redis list func, adds beginning of redis tests * adds helper func for mockdb List function * if no starting key provided for netstate List, the first value in storage will be used * adds basic pagination for redis List function, adds tests * adds list limit to call in overlay/server.go * streamlines/fixes some nits from review * removes use of obsolete EncryptedUnencryptedSize * uses MockKeyValueStore instead of redis instance in redis client test * changes test to expect nil returned for getting missing key * remove error from `KeyValueStore#Get` * fix bolt test * Merge pull request #1 from bryanchriswhite/nat-pagination remove error from `KeyValueStore#Get` * adds Get returning error back to KeyValueStore interface and affected clients * trying to appease travis: returns errors in Get calls in overlay/cache and cache_test * handles redis get error when no key found
2018-06-29 21:06:25 +01:00
}
}
}
func TestServiceList(t *testing.T) {
db := teststore.New()
server := Server{DB: db, logger: zap.NewNop()}
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 23:57:22 +01:00
pointer := &pb.Pointer{}
pointer.CreationDate = ptypes.TimestampNow()
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 23:57:22 +01:00
pointerBytes, err := proto.Marshal(pointer)
if err != nil {
t.Fatal(err)
}
pointerValue := storage.Value(pointerBytes)
err = storage.PutAll(db, []storage.ListItem{
{Key: storage.Key("sample.😶"), Value: pointerValue},
{Key: storage.Key("müsic"), Value: pointerValue},
{Key: storage.Key("müsic/söng1.mp3"), Value: pointerValue},
{Key: storage.Key("müsic/söng2.mp3"), Value: pointerValue},
{Key: storage.Key("müsic/album/söng3.mp3"), Value: pointerValue},
{Key: storage.Key("müsic/söng4.mp3"), Value: pointerValue},
{Key: storage.Key("ビデオ/movie.mkv"), Value: pointerValue},
}...)
if err != nil {
t.Fatal(err)
}
type Test struct {
APIKey string
Request pb.ListRequest
Expected *pb.ListResponse
Error func(i int, err error)
}
errorWithCode := func(code codes.Code) func(i int, err error) {
t.Helper()
return func(i int, err error) {
t.Helper()
if status.Code(err) != code {
t.Fatalf("%d: should fail with %v, got: %v", i, code, err)
}
}
}
tests := []Test{
{
Request: pb.ListRequest{Recursive: true},
Expected: &pb.ListResponse{
Items: []*pb.ListResponse_Item{
{Path: "müsic"},
{Path: "müsic/album/söng3.mp3"},
{Path: "müsic/söng1.mp3"},
{Path: "müsic/söng2.mp3"},
{Path: "müsic/söng4.mp3"},
{Path: "sample.😶"},
{Path: "ビデオ/movie.mkv"},
},
},
}, {
Request: pb.ListRequest{Recursive: true, MetaFlags: meta.All},
Expected: &pb.ListResponse{
Items: []*pb.ListResponse_Item{
{Path: "müsic", Pointer: pointer},
{Path: "müsic/album/söng3.mp3", Pointer: pointer},
{Path: "müsic/söng1.mp3", Pointer: pointer},
{Path: "müsic/söng2.mp3", Pointer: pointer},
{Path: "müsic/söng4.mp3", Pointer: pointer},
{Path: "sample.😶", Pointer: pointer},
{Path: "ビデオ/movie.mkv", Pointer: pointer},
},
},
}, {
APIKey: "wrong key",
Request: pb.ListRequest{Recursive: true, MetaFlags: meta.All}, //, APIKey: []byte("wrong key")},
Error: errorWithCode(codes.Unauthenticated),
}, {
Request: pb.ListRequest{Recursive: true, Limit: 3},
Expected: &pb.ListResponse{
Items: []*pb.ListResponse_Item{
{Path: "müsic"},
{Path: "müsic/album/söng3.mp3"},
{Path: "müsic/söng1.mp3"},
},
More: true,
},
}, {
Request: pb.ListRequest{MetaFlags: meta.All},
Expected: &pb.ListResponse{
Items: []*pb.ListResponse_Item{
{Path: "müsic", Pointer: pointer},
{Path: "müsic/", IsPrefix: true},
{Path: "sample.😶", Pointer: pointer},
{Path: "ビデオ/", IsPrefix: true},
},
More: false,
},
}, {
Request: pb.ListRequest{EndBefore: "ビデオ"},
Expected: &pb.ListResponse{
Items: []*pb.ListResponse_Item{
{Path: "müsic"},
{Path: "müsic/", IsPrefix: true},
{Path: "sample.😶"},
},
More: false,
},
}, {
Request: pb.ListRequest{Recursive: true, Prefix: "müsic/"},
Expected: &pb.ListResponse{
Items: []*pb.ListResponse_Item{
2018-09-09 07:34:23 +01:00
{Path: "album/söng3.mp3"},
{Path: "söng1.mp3"},
{Path: "söng2.mp3"},
{Path: "söng4.mp3"},
},
},
}, {
Request: pb.ListRequest{Recursive: true, Prefix: "müsic/", StartAfter: "album/söng3.mp3"},
Expected: &pb.ListResponse{
Items: []*pb.ListResponse_Item{
2018-09-09 07:34:23 +01:00
{Path: "söng1.mp3"},
{Path: "söng2.mp3"},
{Path: "söng4.mp3"},
},
},
}, {
Request: pb.ListRequest{Prefix: "müsic/"},
Expected: &pb.ListResponse{
Items: []*pb.ListResponse_Item{
2018-09-09 07:34:23 +01:00
{Path: "album/", IsPrefix: true},
{Path: "söng1.mp3"},
{Path: "söng2.mp3"},
{Path: "söng4.mp3"},
},
},
}, {
Request: pb.ListRequest{Prefix: "müsic/", StartAfter: "söng1.mp3"},
Expected: &pb.ListResponse{
Items: []*pb.ListResponse_Item{
2018-09-09 07:34:23 +01:00
{Path: "söng2.mp3"},
{Path: "söng4.mp3"},
},
},
}, {
Request: pb.ListRequest{Prefix: "müsic/", EndBefore: "söng4.mp3"},
Expected: &pb.ListResponse{
Items: []*pb.ListResponse_Item{
2018-09-09 07:34:23 +01:00
{Path: "album/", IsPrefix: true},
{Path: "söng1.mp3"},
{Path: "söng2.mp3"},
},
},
}, {
Request: pb.ListRequest{Prefix: "müs", Recursive: true, EndBefore: "ic/söng4.mp3", Limit: 1},
Expected: &pb.ListResponse{
Items: []*pb.ListResponse_Item{
// {Path: "ic/söng2.mp3"},
},
// More: true,
},
},
}
// TODO:
// pb.ListRequest{Prefix: "müsic/", StartAfter: "söng1.mp3", EndBefore: "söng4.mp3"},
// failing database
for i, test := range tests {
ctx := context.Background()
ctx = auth.WithAPIKey(ctx, []byte(test.APIKey))
resp, err := server.List(ctx, &test.Request)
if test.Error == nil {
if err != nil {
t.Fatalf("%d: failed %v", i, err)
}
} else {
test.Error(i, err)
}
if diff := cmp.Diff(test.Expected, resp, cmp.Comparer(proto.Equal)); diff != "" {
t.Errorf("%d: (-want +got) %v\n%s", i, test.Request.String(), diff)
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 23:57:22 +01:00
}
adds netstate pagination (#95) * adds netstate rpc server pagination, mocks pagination in test/util.go * updates ns client example, combines ns client and server test to netstate_test, adds pagination to bolt client * better organizes netstate test calls * wip breaking netstate test into smaller tests * wip modularizing netstate tests * adds some test panics * wip netstate test attempts * testing bug in netstate TestDeleteAuth * wip fixes global variable problem, still issues with list * wip fixes get request params and args * fixes bug in path when using MakePointers helper fn * updates mockdb list func, adds test, changes Limit to int * fixes merge conflicts * fixes broken tests from merge * remove unnecessary PointerEntry struct * removes error when Get returns nil value from boltdb * breaks boltdb client tests into smaller tests * renames AssertNoErr test helper to HandleErr * adds StartingKey and Limit parameters to redis list func, adds beginning of redis tests * adds helper func for mockdb List function * if no starting key provided for netstate List, the first value in storage will be used * adds basic pagination for redis List function, adds tests * adds list limit to call in overlay/server.go * streamlines/fixes some nits from review * removes use of obsolete EncryptedUnencryptedSize * uses MockKeyValueStore instead of redis instance in redis client test * changes test to expect nil returned for getting missing key * remove error from `KeyValueStore#Get` * fix bolt test * Merge pull request #1 from bryanchriswhite/nat-pagination remove error from `KeyValueStore#Get` * adds Get returning error back to KeyValueStore interface and affected clients * trying to appease travis: returns errors in Get calls in overlay/cache and cache_test * handles redis get error when no key found
2018-06-29 21:06:25 +01:00
}
}