storj/storage/redis/client_test.go

337 lines
6.9 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 redis
import (
"fmt"
"os"
"os/exec"
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"
"time"
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
"github.com/go-redis/redis"
"github.com/stretchr/testify/assert"
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/internal/test"
"storj.io/storj/storage"
)
type RedisClientTest struct {
*testing.T
c storage.KeyValueStore
}
func NewRedisClientTest(t *testing.T) *RedisClientTest {
kv := make(test.KvStore)
c := test.NewMockKeyValueStore(kv)
return &RedisClientTest{
T: t,
c: c,
}
}
func (rt *RedisClientTest) Close() {
rt.c.Close()
}
func (rt *RedisClientTest) HandleErr(err error, msg string) {
rt.Error(msg)
if err != nil {
panic(err)
}
panic(msg)
}
func TestListWithoutStartKey(t *testing.T) {
rt := NewRedisClientTest(t)
defer rt.Close()
if err := rt.c.Put(storage.Key([]byte("path/1")), []byte("pointer1")); err != nil {
rt.HandleErr(err, "Failed to put")
}
if err := rt.c.Put(storage.Key([]byte("path/2")), []byte("pointer2")); err != nil {
rt.HandleErr(err, "Failed to put")
}
if err := rt.c.Put(storage.Key([]byte("path/3")), []byte("pointer3")); err != nil {
rt.HandleErr(err, "Failed to put")
}
_, err := rt.c.List(nil, storage.Limit(3))
if err != nil {
rt.HandleErr(err, "Failed to list")
}
}
func TestListWithStartKey(t *testing.T) {
rt := NewRedisClientTest(t)
defer rt.Close()
if err := rt.c.Put(storage.Key([]byte("path/1")), []byte("pointer1")); err != nil {
rt.HandleErr(err, "Failed to put")
}
if err := rt.c.Put(storage.Key([]byte("path/2")), []byte("pointer2")); err != nil {
rt.HandleErr(err, "Failed to put")
}
if err := rt.c.Put(storage.Key([]byte("path/3")), []byte("pointer3")); err != nil {
rt.HandleErr(err, "Failed to put")
}
if err := rt.c.Put(storage.Key([]byte("path/4")), []byte("pointer4")); err != nil {
rt.HandleErr(err, "Failed to put")
}
if err := rt.c.Put(storage.Key([]byte("path/5")), []byte("pointer5")); err != nil {
rt.HandleErr(err, "Failed to put")
}
_, err := rt.c.List([]byte("path/2"), storage.Limit(2))
if err != nil {
rt.HandleErr(err, "Failed to list")
}
}
var (
validConnection = "127.0.0.1:6379"
unexistingKey = "unexistingKey"
validKey = "validKey"
validValue = "validValue"
keysList = []string{"key1", "key2", "key3"}
dbTest = 1
)
type TestFunc func(t *testing.T, st storage.KeyValueStore)
func testWithRedis(t *testing.T, testFunc TestFunc) {
st, err := NewClient(validConnection, "", dbTest)
assert.NoError(t, err)
assert.NotNil(t, st)
defer func() {
st.Close()
}()
testFunc(t, st)
}
func testWithInvalidConnection(t *testing.T, testFunc TestFunc) {
st := &Client{
db: redis.NewClient(&redis.Options{
Addr: "",
Password: "",
DB: dbTest,
}),
TTL: defaultNodeExpiration,
}
testFunc(t, st)
}
func TestCloseRedis(t *testing.T) {
testWithRedis(t, func(t *testing.T, st storage.KeyValueStore) {
err := st.Close()
assert.NoError(t, err)
})
}
func TestNewClient(t *testing.T) {
cases := []struct {
testName, address string
testFunc func(storage.KeyValueStore, error)
}{
{
"NotValidConnection",
"",
func(st storage.KeyValueStore, err error) {
assert.Error(t, err)
assert.Nil(t, st)
},
},
{
"ValidConnection",
validConnection,
func(st storage.KeyValueStore, err error) {
assert.NoError(t, err)
assert.NotNil(t, st)
},
},
}
for _, c := range cases {
t.Run(c.testName, func(t *testing.T) {
storage, err := NewClient(c.address, "", dbTest)
defer func() {
if err == nil {
storage.Close()
}
}()
c.testFunc(storage, err)
})
}
}
func TestCrudValidConnection(t *testing.T) {
cases := []struct {
testName string
testFunc TestFunc
}{
{
"GetUnexistingKey",
func(t *testing.T, st storage.KeyValueStore) {
err := st.Delete(storage.Key(unexistingKey))
assert.NoError(t, err)
value, err := st.Get(storage.Key(unexistingKey))
assert.NoError(t, err)
assert.Nil(t, value)
},
},
{
"GetValidKey",
func(t *testing.T, st storage.KeyValueStore) {
key := storage.Key(validKey)
orgValue := storage.Value(validValue)
err := st.Put(key, orgValue)
assert.NoError(t, err)
value, err := st.Get(key)
assert.NoError(t, err)
assert.Equal(t, orgValue, value)
err = st.Delete(key)
assert.NoError(t, err)
},
},
{
"UpdateKey",
func(t *testing.T, st storage.KeyValueStore) {
key := storage.Key(validKey)
orgValue := storage.Value(validValue)
err := st.Put(key, orgValue)
assert.NoError(t, err)
err = st.Put(key, orgValue)
assert.NoError(t, err)
err = st.Delete(key)
assert.NoError(t, err)
},
},
{
"GetKeysList",
func(t *testing.T, st storage.KeyValueStore) {
orgValue := storage.Value(validValue)
list := storage.Keys{}
for _, key := range keysList {
list = append(list, storage.Key(key))
}
for _, key := range list {
err := st.Put(key, orgValue)
assert.NoError(t, err)
}
Testcoverage kademlia (#154) * Unit test covarege increased for kademlia pkg go style formatting added Removed DHT param from newTestKademlia method, added comments for Bucket methods that informs that these tests will need to be updated unnecessary comment deleted from newTestKademlia Adjust Segment Store to the updated interface (#160) * Adjust Segment Store to the updated interface * Move /pkg/storage/segment to /pkg/storage/segments * Fix overlay client tests * Revert changes in NewOverlayClient return value * Rename `rem` to `seg` * Implement Meta() captplanet (#159) * captplanet I kind of went overboard this weekend. The major goal of this changeset is to provide an environment for local development where all of the various services can be easily run together. Developing on Storj v3 should be as easy as running a setup command and a run command! To do this, this changeset introduces a new tool called captplanet, which combines the powers of the Overlay Cache, the PointerDB, the PieceStore, Kademlia, the Minio Gateway, etc. Running 40 farmers and a heavy client inside the same process forced a rethinking of the "services" that we had. To avoid confusion by reusing prior terms, this changeset introduces two new types: Providers and Responsibilities. I wanted to avoid as many merge conflicts as possible, so I left the existing Services and code for now, but if people like this route we can clean up the duplication. A Responsibility is a collection of gRPC methods and corresponding state. The following systems are examples of Responsibilities: * Kademlia * OverlayCache * PointerDB * StatDB * PieceStore * etc. A Provider is a collection of Responsibilities that share an Identity, such as: * The heavy client * The farmer * The gateway An Identity is a public/private key pair, a node id, etc. Farmers all need different Identities, so captplanet needs to support running multiple concurrent Providers with different Identities. Each Responsibility and Provider should allow for configuration of multiple copies on its own so creating Responsibilities and Providers use a new workflow. To make a Responsibility, one should create a "config" struct, such as: ``` type Config struct { RepairThreshold int `help:"If redundancy falls below this number of pieces, repair is triggered" default:"30"` SuccessThreshold int `help:"If redundancy is above this number then no additional uploads are needed" default:"40"` } ``` To use "config" structs, this changeset introduces another new library called 'cfgstruct', which allows for the configuration of arbitrary structs through flagsets, and thus through cobra and viper. cfgstruct relies on Go's "struct tags" feature to document help information and default values. Config structs can be configured via cfgstruct.Bind for binding the struct to a flagset. Because this configuration system makes setup and configuration easier *in general*, additional commands are provided that allow for easy standup of separate Providers. Please make sure to check out: * cmd/captplanet/farmer/main.go (a new farmer binary) * cmd/captplanet/hc/main.go (a new heavy client binary) * cmd/captplanet/gw/main.go (a new minio gateway binary) Usage: ``` $ go install -v storj.io/storj/cmd/captplanet $ captplanet setup $ captplanet run ``` Configuration is placed by default in `~/.storj/capt/` Other changes: * introduces new config structs for currently existing Responsibilities that conform to the new Responsibility interface. Please see the `pkg/*/config.go` files for examples. * integrates the PointerDB API key with other global configuration via flags, instead of through environment variables through viper like it's been doing. (ultimately this should also change to use the PointerDB config struct but this is an okay shortterm solution). * changes the Overlay cache to use a URL for database configuration instead of separate redis and bolt config settings. * stubs out some peer identity skeleton code (but not the meat). * Fixes the SegmentStore to use the overlay client and pointerdb clients instead of gRPC client code directly * Leaves a very clear spot where we need to tie the object to stream to segment store together. There's sort of a "golden spike" opportunity to connect all the train tracks together at the bottom of pkg/miniogw/config.go, labeled with a bunch of TODOs. Future stuff: * I now prefer this design over the original pkg/process.Service thing I had been pushing before (sorry!) * The experience of trying to have multiple farmers configurable concurrently led me to prefer config structs over global flags (I finally came around) or using viper directly. I think global flags are okay sometimes but in general going forward we should try and get all relevant config into config structs. * If you all like this direction, I think we can go delete my old Service interfaces and a bunch of flags and clean up a bunch of stuff. * If you don't like this direction, it's no sweat at all, and despite how much code there is here I'm not very tied to any of this! Considering a lot of this was written between midnight and 6 am, it might not be any good! * bind tests Add files for testing builds in docker (#161) * Add files for testing builds in docker * Make tests check for redis running before trying to start redis-server, which may not exist. * Clean redis server before any tests use it. * Add more debugging for travis * Explicitly requiring redis for travis pkg/provider: with pkg/provider merged, make a single heavy client binary, gateway binary, and deprecate old services (#165) * pkg/provider: with pkg/provider merged, make a single heavy client binary and deprecate old services * add setup to gw binary too * captplanet: output what addresses everything is listening on * revert peertls/io_util changes * define config flag across all commands * use trimsuffix fix docker makefile (#170) * fix makefile protos: update protobufs with go generate (#169) the import for timestamp and duration should use the path provided by a standard protocol buffer library installation Refactor List in PointerDB (#163) * Refactor List in Pointer DB * Fix pointerdb-client example * Fix issue in Path type related to empty paths * Test for the PointerDB service with some fixes * Fixed debug message in example: trancated --> more * GoDoc comments for unexported methods * TODO comment to check if Put is overwriting * Log warning if protobuf timestamp cannot be converted * TODO comment to make ListPageLimit configurable * Rename 'segment' package to 'segments' to reflect folder name Minio integration with Object store (#156) * initial WIP integration with Object store * List WIP * minio listobject function changes complete * Code review changes and work in progress for the mock objectstore unit testing cases * Warning fix redeclaration of err * Warning fix redeclaration of err * code review comments & unit testing inprogress * fix compilation bug * Fixed code review comments & added GetObject Mock test case * rearraged the mock test file and gateway storj test file in to the proper directory * added the missing file * code clean up * fix lint error on the mock generated code * modified per code review comments * added the PutObject mock test case * added the GetObjectInfo mock test case * added listobject mock test case * fixed package from storj to miniogw * resolved the gateway-storj.go initialization merge conflict update readme (#174) added assertion for unused errors (#152) merging this PR to avoid future issues updating github user to personal account (#171) Test coverage ranger (#168) * Fixed go panic for corner case * Initial test coverage for ranger pkg streamstore: add passthrough implementation (#176) this doesn't implement streamstore, this just allows us to try and get the june demo working again in the meantime StatDB (#144) * add statdb proto and example client * server logic * update readme * remove boltdb from service.go * sqlite3 * add statdb server executable file * create statdb node table if it does not exist already * get UpdateBatch working * update based on jt review * remove some commented lines * fix linting issues * reformat * apiKey -> APIKey * update statdb client apiKey->APIKey Update README.md Update README.md overlay: correct dockerfile db (#179) cmd/hc, cmd/gw, cmd/captplanet: simplify setup/run commands (#178) also allows much more customization of services within captain planet, such as reconfiguring the overlay service to use redis pkg/process: don't require json formatting (#177) Cleanup metadata across layers (#180) * Cleanup metadata across layers * Fix pointer db tests Kademlia Routing Table (#164) * adds comment * runs deps * creates boltdb kademlia routing table * protobuf updates * adds reverselist to mockkeyvaluestore interface * xor wip * xor wip * fixes xor sort * runs go fmt * fixes * goimports again * trying to fix travis tests * fixes mock tests Ranger refactoring (#158) * Fixed go panic for corner case * Cosmetic changes, and small error fixes miniogw: log all errors (#182) * miniogw: log all errors * tests added * doc comment to satisfy linter * fix test failure Jennifer added to CLA list * Temporary fix for storage/redis list method test
2018-08-02 19:36:57 +01:00
//Temporary fix
_, err := st.List(list[0], storage.Limit(len(keysList)))
assert.NoError(t, err)
Testcoverage kademlia (#154) * Unit test covarege increased for kademlia pkg go style formatting added Removed DHT param from newTestKademlia method, added comments for Bucket methods that informs that these tests will need to be updated unnecessary comment deleted from newTestKademlia Adjust Segment Store to the updated interface (#160) * Adjust Segment Store to the updated interface * Move /pkg/storage/segment to /pkg/storage/segments * Fix overlay client tests * Revert changes in NewOverlayClient return value * Rename `rem` to `seg` * Implement Meta() captplanet (#159) * captplanet I kind of went overboard this weekend. The major goal of this changeset is to provide an environment for local development where all of the various services can be easily run together. Developing on Storj v3 should be as easy as running a setup command and a run command! To do this, this changeset introduces a new tool called captplanet, which combines the powers of the Overlay Cache, the PointerDB, the PieceStore, Kademlia, the Minio Gateway, etc. Running 40 farmers and a heavy client inside the same process forced a rethinking of the "services" that we had. To avoid confusion by reusing prior terms, this changeset introduces two new types: Providers and Responsibilities. I wanted to avoid as many merge conflicts as possible, so I left the existing Services and code for now, but if people like this route we can clean up the duplication. A Responsibility is a collection of gRPC methods and corresponding state. The following systems are examples of Responsibilities: * Kademlia * OverlayCache * PointerDB * StatDB * PieceStore * etc. A Provider is a collection of Responsibilities that share an Identity, such as: * The heavy client * The farmer * The gateway An Identity is a public/private key pair, a node id, etc. Farmers all need different Identities, so captplanet needs to support running multiple concurrent Providers with different Identities. Each Responsibility and Provider should allow for configuration of multiple copies on its own so creating Responsibilities and Providers use a new workflow. To make a Responsibility, one should create a "config" struct, such as: ``` type Config struct { RepairThreshold int `help:"If redundancy falls below this number of pieces, repair is triggered" default:"30"` SuccessThreshold int `help:"If redundancy is above this number then no additional uploads are needed" default:"40"` } ``` To use "config" structs, this changeset introduces another new library called 'cfgstruct', which allows for the configuration of arbitrary structs through flagsets, and thus through cobra and viper. cfgstruct relies on Go's "struct tags" feature to document help information and default values. Config structs can be configured via cfgstruct.Bind for binding the struct to a flagset. Because this configuration system makes setup and configuration easier *in general*, additional commands are provided that allow for easy standup of separate Providers. Please make sure to check out: * cmd/captplanet/farmer/main.go (a new farmer binary) * cmd/captplanet/hc/main.go (a new heavy client binary) * cmd/captplanet/gw/main.go (a new minio gateway binary) Usage: ``` $ go install -v storj.io/storj/cmd/captplanet $ captplanet setup $ captplanet run ``` Configuration is placed by default in `~/.storj/capt/` Other changes: * introduces new config structs for currently existing Responsibilities that conform to the new Responsibility interface. Please see the `pkg/*/config.go` files for examples. * integrates the PointerDB API key with other global configuration via flags, instead of through environment variables through viper like it's been doing. (ultimately this should also change to use the PointerDB config struct but this is an okay shortterm solution). * changes the Overlay cache to use a URL for database configuration instead of separate redis and bolt config settings. * stubs out some peer identity skeleton code (but not the meat). * Fixes the SegmentStore to use the overlay client and pointerdb clients instead of gRPC client code directly * Leaves a very clear spot where we need to tie the object to stream to segment store together. There's sort of a "golden spike" opportunity to connect all the train tracks together at the bottom of pkg/miniogw/config.go, labeled with a bunch of TODOs. Future stuff: * I now prefer this design over the original pkg/process.Service thing I had been pushing before (sorry!) * The experience of trying to have multiple farmers configurable concurrently led me to prefer config structs over global flags (I finally came around) or using viper directly. I think global flags are okay sometimes but in general going forward we should try and get all relevant config into config structs. * If you all like this direction, I think we can go delete my old Service interfaces and a bunch of flags and clean up a bunch of stuff. * If you don't like this direction, it's no sweat at all, and despite how much code there is here I'm not very tied to any of this! Considering a lot of this was written between midnight and 6 am, it might not be any good! * bind tests Add files for testing builds in docker (#161) * Add files for testing builds in docker * Make tests check for redis running before trying to start redis-server, which may not exist. * Clean redis server before any tests use it. * Add more debugging for travis * Explicitly requiring redis for travis pkg/provider: with pkg/provider merged, make a single heavy client binary, gateway binary, and deprecate old services (#165) * pkg/provider: with pkg/provider merged, make a single heavy client binary and deprecate old services * add setup to gw binary too * captplanet: output what addresses everything is listening on * revert peertls/io_util changes * define config flag across all commands * use trimsuffix fix docker makefile (#170) * fix makefile protos: update protobufs with go generate (#169) the import for timestamp and duration should use the path provided by a standard protocol buffer library installation Refactor List in PointerDB (#163) * Refactor List in Pointer DB * Fix pointerdb-client example * Fix issue in Path type related to empty paths * Test for the PointerDB service with some fixes * Fixed debug message in example: trancated --> more * GoDoc comments for unexported methods * TODO comment to check if Put is overwriting * Log warning if protobuf timestamp cannot be converted * TODO comment to make ListPageLimit configurable * Rename 'segment' package to 'segments' to reflect folder name Minio integration with Object store (#156) * initial WIP integration with Object store * List WIP * minio listobject function changes complete * Code review changes and work in progress for the mock objectstore unit testing cases * Warning fix redeclaration of err * Warning fix redeclaration of err * code review comments & unit testing inprogress * fix compilation bug * Fixed code review comments & added GetObject Mock test case * rearraged the mock test file and gateway storj test file in to the proper directory * added the missing file * code clean up * fix lint error on the mock generated code * modified per code review comments * added the PutObject mock test case * added the GetObjectInfo mock test case * added listobject mock test case * fixed package from storj to miniogw * resolved the gateway-storj.go initialization merge conflict update readme (#174) added assertion for unused errors (#152) merging this PR to avoid future issues updating github user to personal account (#171) Test coverage ranger (#168) * Fixed go panic for corner case * Initial test coverage for ranger pkg streamstore: add passthrough implementation (#176) this doesn't implement streamstore, this just allows us to try and get the june demo working again in the meantime StatDB (#144) * add statdb proto and example client * server logic * update readme * remove boltdb from service.go * sqlite3 * add statdb server executable file * create statdb node table if it does not exist already * get UpdateBatch working * update based on jt review * remove some commented lines * fix linting issues * reformat * apiKey -> APIKey * update statdb client apiKey->APIKey Update README.md Update README.md overlay: correct dockerfile db (#179) cmd/hc, cmd/gw, cmd/captplanet: simplify setup/run commands (#178) also allows much more customization of services within captain planet, such as reconfiguring the overlay service to use redis pkg/process: don't require json formatting (#177) Cleanup metadata across layers (#180) * Cleanup metadata across layers * Fix pointer db tests Kademlia Routing Table (#164) * adds comment * runs deps * creates boltdb kademlia routing table * protobuf updates * adds reverselist to mockkeyvaluestore interface * xor wip * xor wip * fixes xor sort * runs go fmt * fixes * goimports again * trying to fix travis tests * fixes mock tests Ranger refactoring (#158) * Fixed go panic for corner case * Cosmetic changes, and small error fixes miniogw: log all errors (#182) * miniogw: log all errors * tests added * doc comment to satisfy linter * fix test failure Jennifer added to CLA list * Temporary fix for storage/redis list method test
2018-08-02 19:36:57 +01:00
// assert.ElementsMatch(t, list, keys)
// assert.Equal(t, len(list), len(keys))
for _, key := range list {
err := st.Delete(key)
assert.NoError(t, err)
}
},
},
{
"GetKeysListWithFirstArgNil",
func(t *testing.T, st storage.KeyValueStore) {
keys, err := st.List(nil, storage.Limit(len(keysList)))
assert.NoError(t, err)
assert.Equal(t, len(keys), 0)
},
},
}
for _, c := range cases {
t.Run(c.testName, func(t *testing.T) {
testWithRedis(t, c.testFunc)
})
}
}
func TestCrudInvalidConnection(t *testing.T) {
cases := []struct {
testName string
testFunc TestFunc
}{
{
"Get",
func(t *testing.T, st storage.KeyValueStore) {
_, err := st.Get(storage.Key(validKey))
assert.Error(t, err)
},
},
{
"Put",
func(t *testing.T, st storage.KeyValueStore) {
err := st.Put(storage.Key(validKey), storage.Value(validValue))
assert.Error(t, err)
},
},
{
"Delete",
func(t *testing.T, st storage.KeyValueStore) {
err := st.Delete(storage.Key(validKey))
assert.Error(t, err)
},
},
{
"ListArgValid",
func(t *testing.T, st storage.KeyValueStore) {
keys, err := st.List(storage.Key(validKey), 1)
assert.Error(t, err)
assert.Nil(t, keys)
},
},
{
"ListArgInvalid",
func(t *testing.T, st storage.KeyValueStore) {
keys, err := st.List(nil, 1)
assert.Error(t, err)
assert.Nil(t, keys)
},
},
}
for _, c := range cases {
t.Run(c.testName, func(t *testing.T) {
testWithInvalidConnection(t, c.testFunc)
})
}
}
func TestMain(m *testing.M) {
cmd := exec.Command("redis-server")
err := cmd.Start()
if err != nil {
fmt.Println(err)
return
}
//waiting for "redis-server command" to start
time.Sleep(time.Second)
retCode := m.Run()
err = cmd.Process.Kill()
if err != nil {
fmt.Print(err)
}
os.Exit(retCode)
}