Removed test folder and moved all commands tests to their respective internal modules. Moved api tests into echovault package. This change has been made because the speratate test folder is not idiomatic and caused test coverage report to not be generated.

This commit is contained in:
Kelvin Clement Mwinuka
2024-05-04 17:45:10 +08:00
parent eb386d5b8f
commit 193871ec72
22 changed files with 4035 additions and 318 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -12,4 +12,4 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package acl package echovault

View File

@@ -12,32 +12,21 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package admin package echovault
import ( import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"github.com/echovault/echovault/echovault"
"github.com/echovault/echovault/internal/config"
"github.com/echovault/echovault/internal/constants" "github.com/echovault/echovault/internal/constants"
"github.com/tidwall/resp" "github.com/tidwall/resp"
"strconv" "strconv"
"testing" "testing"
) )
func createEchoVault() *echovault.EchoVault {
ev, _ := echovault.NewEchoVault(
echovault.WithConfig(config.Config{
DataDir: "",
}),
)
return ev
}
func TestEchoVault_AddCommand(t *testing.T) { func TestEchoVault_AddCommand(t *testing.T) {
type args struct { type args struct {
command echovault.CommandOptions command CommandOptions
} }
type scenarios struct { type scenarios struct {
name string name string
@@ -55,7 +44,7 @@ func TestEchoVault_AddCommand(t *testing.T) {
name: "1 Add command without subcommands", name: "1 Add command without subcommands",
wantErr: false, wantErr: false,
args: args{ args: args{
command: echovault.CommandOptions{ command: CommandOptions{
Command: "CommandOne", Command: "CommandOne",
Module: "test-module", Module: "test-module",
Description: `(CommandOne write-key read-key <value>) Description: `(CommandOne write-key read-key <value>)
@@ -63,16 +52,16 @@ Test command to handle successful addition of a single command without subcomman
The value passed must be an integer.`, The value passed must be an integer.`,
Categories: []string{}, Categories: []string{},
Sync: false, Sync: false,
KeyExtractionFunc: func(cmd []string) (echovault.CommandKeyExtractionFuncResult, error) { KeyExtractionFunc: func(cmd []string) (CommandKeyExtractionFuncResult, error) {
if len(cmd) != 4 { if len(cmd) != 4 {
return echovault.CommandKeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse) return CommandKeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
} }
return echovault.CommandKeyExtractionFuncResult{ return CommandKeyExtractionFuncResult{
WriteKeys: cmd[1:2], WriteKeys: cmd[1:2],
ReadKeys: cmd[2:3], ReadKeys: cmd[2:3],
}, nil }, nil
}, },
HandlerFunc: func(params echovault.CommandHandlerFuncParams) ([]byte, error) { HandlerFunc: func(params CommandHandlerFuncParams) ([]byte, error) {
if len(params.Command) != 4 { if len(params.Command) != 4 {
return nil, errors.New(constants.WrongArgsResponse) return nil, errors.New(constants.WrongArgsResponse)
} }
@@ -116,9 +105,9 @@ The value passed must be an integer.`,
name: "2 Add command with subcommands", name: "2 Add command with subcommands",
wantErr: false, wantErr: false,
args: args{ args: args{
command: echovault.CommandOptions{ command: CommandOptions{
Command: "CommandTwo", Command: "CommandTwo",
SubCommand: []echovault.SubCommandOptions{ SubCommand: []SubCommandOptions{
{ {
Command: "SubCommandOne", Command: "SubCommandOne",
Module: "test-module", Module: "test-module",
@@ -127,16 +116,16 @@ Test command to handle successful addition of a single command with subcommands.
The value passed must be an integer.`, The value passed must be an integer.`,
Categories: []string{}, Categories: []string{},
Sync: false, Sync: false,
KeyExtractionFunc: func(cmd []string) (echovault.CommandKeyExtractionFuncResult, error) { KeyExtractionFunc: func(cmd []string) (CommandKeyExtractionFuncResult, error) {
if len(cmd) != 5 { if len(cmd) != 5 {
return echovault.CommandKeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse) return CommandKeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
} }
return echovault.CommandKeyExtractionFuncResult{ return CommandKeyExtractionFuncResult{
WriteKeys: cmd[2:3], WriteKeys: cmd[2:3],
ReadKeys: cmd[3:4], ReadKeys: cmd[3:4],
}, nil }, nil
}, },
HandlerFunc: func(params echovault.CommandHandlerFuncParams) ([]byte, error) { HandlerFunc: func(params CommandHandlerFuncParams) ([]byte, error) {
if len(params.Command) != 5 { if len(params.Command) != 5 {
return nil, errors.New(constants.WrongArgsResponse) return nil, errors.New(constants.WrongArgsResponse)
} }

View File

@@ -12,4 +12,4 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package pubsub package echovault

View File

@@ -12,14 +12,12 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package generic package echovault
import ( import (
"context" "context"
"github.com/echovault/echovault/echovault"
"github.com/echovault/echovault/internal" "github.com/echovault/echovault/internal"
"github.com/echovault/echovault/internal/clock" "github.com/echovault/echovault/internal/clock"
"github.com/echovault/echovault/internal/config"
"reflect" "reflect"
"slices" "slices"
"strings" "strings"
@@ -27,33 +25,6 @@ import (
"time" "time"
) )
func createEchoVault() *echovault.EchoVault {
ev, _ := echovault.NewEchoVault(
echovault.WithConfig(config.Config{
DataDir: "",
}),
)
return ev
}
func presetValue(server *echovault.EchoVault, ctx context.Context, key string, value interface{}) error {
if _, err := server.CreateKeyAndLock(ctx, key); err != nil {
return err
}
if err := server.SetValue(ctx, key, value); err != nil {
return err
}
server.KeyUnlock(ctx, key)
return nil
}
func presetKeyData(server *echovault.EchoVault, ctx context.Context, key string, data internal.KeyData) {
_, _ = server.CreateKeyAndLock(ctx, key)
defer server.KeyUnlock(ctx, key)
_ = server.SetValue(ctx, key, data.Value)
server.SetExpiry(ctx, key, data.ExpireAt, false)
}
func TestEchoVault_DEL(t *testing.T) { func TestEchoVault_DEL(t *testing.T) {
server := createEchoVault() server := createEchoVault()
@@ -107,8 +78,8 @@ func TestEchoVault_EXPIRE(t *testing.T) {
cmd string cmd string
key string key string
time int time int
expireOpts echovault.ExpireOptions expireOpts ExpireOptions
pexpireOpts echovault.PExpireOptions pexpireOpts PExpireOptions
want int want int
wantErr bool wantErr bool
}{ }{
@@ -117,7 +88,7 @@ func TestEchoVault_EXPIRE(t *testing.T) {
cmd: "EXPIRE", cmd: "EXPIRE",
key: "key1", key: "key1",
time: 100, time: 100,
expireOpts: echovault.ExpireOptions{}, expireOpts: ExpireOptions{},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key1": {Value: "value1", ExpireAt: time.Time{}}, "key1": {Value: "value1", ExpireAt: time.Time{}},
}, },
@@ -129,7 +100,7 @@ func TestEchoVault_EXPIRE(t *testing.T) {
cmd: "PEXPIRE", cmd: "PEXPIRE",
key: "key2", key: "key2",
time: 1000, time: 1000,
pexpireOpts: echovault.PExpireOptions{}, pexpireOpts: PExpireOptions{},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key2": {Value: "value2", ExpireAt: time.Time{}}, "key2": {Value: "value2", ExpireAt: time.Time{}},
}, },
@@ -141,7 +112,7 @@ func TestEchoVault_EXPIRE(t *testing.T) {
cmd: "EXPIRE", cmd: "EXPIRE",
key: "key3", key: "key3",
time: 1000, time: 1000,
expireOpts: echovault.ExpireOptions{NX: true}, expireOpts: ExpireOptions{NX: true},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key3": {Value: "value3", ExpireAt: time.Time{}}, "key3": {Value: "value3", ExpireAt: time.Time{}},
}, },
@@ -153,7 +124,7 @@ func TestEchoVault_EXPIRE(t *testing.T) {
cmd: "EXPIRE", cmd: "EXPIRE",
key: "key4", key: "key4",
time: 1000, time: 1000,
expireOpts: echovault.ExpireOptions{NX: true}, expireOpts: ExpireOptions{NX: true},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key4": {Value: "value4", ExpireAt: mockClock.Now().Add(1000 * time.Second)}, "key4": {Value: "value4", ExpireAt: mockClock.Now().Add(1000 * time.Second)},
}, },
@@ -165,7 +136,7 @@ func TestEchoVault_EXPIRE(t *testing.T) {
cmd: "EXPIRE", cmd: "EXPIRE",
key: "key5", key: "key5",
time: 1000, time: 1000,
expireOpts: echovault.ExpireOptions{XX: true}, expireOpts: ExpireOptions{XX: true},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key5": {Value: "value5", ExpireAt: mockClock.Now().Add(30 * time.Second)}, "key5": {Value: "value5", ExpireAt: mockClock.Now().Add(30 * time.Second)},
}, },
@@ -176,7 +147,7 @@ func TestEchoVault_EXPIRE(t *testing.T) {
name: "Return 0 when key does not have an expiry and the XX flag is provided", name: "Return 0 when key does not have an expiry and the XX flag is provided",
cmd: "EXPIRE", cmd: "EXPIRE",
time: 1000, time: 1000,
expireOpts: echovault.ExpireOptions{XX: true}, expireOpts: ExpireOptions{XX: true},
key: "key6", key: "key6",
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key6": {Value: "value6", ExpireAt: time.Time{}}, "key6": {Value: "value6", ExpireAt: time.Time{}},
@@ -189,7 +160,7 @@ func TestEchoVault_EXPIRE(t *testing.T) {
cmd: "EXPIRE", cmd: "EXPIRE",
key: "key7", key: "key7",
time: 100000, time: 100000,
expireOpts: echovault.ExpireOptions{GT: true}, expireOpts: ExpireOptions{GT: true},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key7": {Value: "value7", ExpireAt: mockClock.Now().Add(30 * time.Second)}, "key7": {Value: "value7", ExpireAt: mockClock.Now().Add(30 * time.Second)},
}, },
@@ -201,7 +172,7 @@ func TestEchoVault_EXPIRE(t *testing.T) {
cmd: "EXPIRE", cmd: "EXPIRE",
key: "key8", key: "key8",
time: 1000, time: 1000,
expireOpts: echovault.ExpireOptions{GT: true}, expireOpts: ExpireOptions{GT: true},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key8": {Value: "value8", ExpireAt: mockClock.Now().Add(3000 * time.Second)}, "key8": {Value: "value8", ExpireAt: mockClock.Now().Add(3000 * time.Second)},
}, },
@@ -213,7 +184,7 @@ func TestEchoVault_EXPIRE(t *testing.T) {
cmd: "EXPIRE", cmd: "EXPIRE",
key: "key9", key: "key9",
time: 1000, time: 1000,
expireOpts: echovault.ExpireOptions{GT: true}, expireOpts: ExpireOptions{GT: true},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key9": {Value: "value9", ExpireAt: time.Time{}}, "key9": {Value: "value9", ExpireAt: time.Time{}},
}, },
@@ -225,7 +196,7 @@ func TestEchoVault_EXPIRE(t *testing.T) {
cmd: "EXPIRE", cmd: "EXPIRE",
key: "key10", key: "key10",
time: 1000, time: 1000,
expireOpts: echovault.ExpireOptions{LT: true}, expireOpts: ExpireOptions{LT: true},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key10": {Value: "value10", ExpireAt: mockClock.Now().Add(3000 * time.Second)}, "key10": {Value: "value10", ExpireAt: mockClock.Now().Add(3000 * time.Second)},
}, },
@@ -237,7 +208,7 @@ func TestEchoVault_EXPIRE(t *testing.T) {
cmd: "EXPIRE", cmd: "EXPIRE",
key: "key11", key: "key11",
time: 50000, time: 50000,
expireOpts: echovault.ExpireOptions{LT: true}, expireOpts: ExpireOptions{LT: true},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key11": {Value: "value11", ExpireAt: mockClock.Now().Add(30 * time.Second)}, "key11": {Value: "value11", ExpireAt: mockClock.Now().Add(30 * time.Second)},
}, },
@@ -281,8 +252,8 @@ func TestEchoVault_EXPIREAT(t *testing.T) {
cmd string cmd string
key string key string
time int time int
expireAtOpts echovault.ExpireAtOptions expireAtOpts ExpireAtOptions
pexpireAtOpts echovault.PExpireAtOptions pexpireAtOpts PExpireAtOptions
want int want int
wantErr bool wantErr bool
}{ }{
@@ -290,7 +261,7 @@ func TestEchoVault_EXPIREAT(t *testing.T) {
name: "Set new expire by unix seconds", name: "Set new expire by unix seconds",
cmd: "EXPIREAT", cmd: "EXPIREAT",
key: "key1", key: "key1",
expireAtOpts: echovault.ExpireAtOptions{}, expireAtOpts: ExpireAtOptions{},
time: int(mockClock.Now().Add(1000 * time.Second).Unix()), time: int(mockClock.Now().Add(1000 * time.Second).Unix()),
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key1": {Value: "value1", ExpireAt: time.Time{}}, "key1": {Value: "value1", ExpireAt: time.Time{}},
@@ -302,7 +273,7 @@ func TestEchoVault_EXPIREAT(t *testing.T) {
name: "Set new expire by milliseconds", name: "Set new expire by milliseconds",
cmd: "PEXPIREAT", cmd: "PEXPIREAT",
key: "key2", key: "key2",
pexpireAtOpts: echovault.PExpireAtOptions{}, pexpireAtOpts: PExpireAtOptions{},
time: int(mockClock.Now().Add(1000 * time.Second).UnixMilli()), time: int(mockClock.Now().Add(1000 * time.Second).UnixMilli()),
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key2": {Value: "value2", ExpireAt: time.Time{}}, "key2": {Value: "value2", ExpireAt: time.Time{}},
@@ -315,7 +286,7 @@ func TestEchoVault_EXPIREAT(t *testing.T) {
cmd: "EXPIREAT", cmd: "EXPIREAT",
key: "key3", key: "key3",
time: int(mockClock.Now().Add(1000 * time.Second).Unix()), time: int(mockClock.Now().Add(1000 * time.Second).Unix()),
expireAtOpts: echovault.ExpireAtOptions{NX: true}, expireAtOpts: ExpireAtOptions{NX: true},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key3": {Value: "value3", ExpireAt: time.Time{}}, "key3": {Value: "value3", ExpireAt: time.Time{}},
}, },
@@ -326,7 +297,7 @@ func TestEchoVault_EXPIREAT(t *testing.T) {
name: "Return 0, when NX flag is provided and key already has an expiry time", name: "Return 0, when NX flag is provided and key already has an expiry time",
cmd: "EXPIREAT", cmd: "EXPIREAT",
time: int(mockClock.Now().Add(1000 * time.Second).Unix()), time: int(mockClock.Now().Add(1000 * time.Second).Unix()),
expireAtOpts: echovault.ExpireAtOptions{NX: true}, expireAtOpts: ExpireAtOptions{NX: true},
key: "key4", key: "key4",
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key4": {Value: "value4", ExpireAt: mockClock.Now().Add(1000 * time.Second)}, "key4": {Value: "value4", ExpireAt: mockClock.Now().Add(1000 * time.Second)},
@@ -339,7 +310,7 @@ func TestEchoVault_EXPIREAT(t *testing.T) {
cmd: "EXPIREAT", cmd: "EXPIREAT",
time: int(mockClock.Now().Add(1000 * time.Second).Unix()), time: int(mockClock.Now().Add(1000 * time.Second).Unix()),
key: "key5", key: "key5",
expireAtOpts: echovault.ExpireAtOptions{XX: true}, expireAtOpts: ExpireAtOptions{XX: true},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key5": {Value: "value5", ExpireAt: mockClock.Now().Add(30 * time.Second)}, "key5": {Value: "value5", ExpireAt: mockClock.Now().Add(30 * time.Second)},
}, },
@@ -351,7 +322,7 @@ func TestEchoVault_EXPIREAT(t *testing.T) {
cmd: "EXPIREAT", cmd: "EXPIREAT",
key: "key6", key: "key6",
time: int(mockClock.Now().Add(1000 * time.Second).Unix()), time: int(mockClock.Now().Add(1000 * time.Second).Unix()),
expireAtOpts: echovault.ExpireAtOptions{XX: true}, expireAtOpts: ExpireAtOptions{XX: true},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key6": {Value: "value6", ExpireAt: time.Time{}}, "key6": {Value: "value6", ExpireAt: time.Time{}},
}, },
@@ -363,7 +334,7 @@ func TestEchoVault_EXPIREAT(t *testing.T) {
cmd: "EXPIREAT", cmd: "EXPIREAT",
key: "key7", key: "key7",
time: int(mockClock.Now().Add(1000 * time.Second).Unix()), time: int(mockClock.Now().Add(1000 * time.Second).Unix()),
expireAtOpts: echovault.ExpireAtOptions{GT: true}, expireAtOpts: ExpireAtOptions{GT: true},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key7": {Value: "value7", ExpireAt: mockClock.Now().Add(30 * time.Second)}, "key7": {Value: "value7", ExpireAt: mockClock.Now().Add(30 * time.Second)},
}, },
@@ -375,7 +346,7 @@ func TestEchoVault_EXPIREAT(t *testing.T) {
cmd: "EXPIREAT", cmd: "EXPIREAT",
key: "key8", key: "key8",
time: int(mockClock.Now().Add(1000 * time.Second).Unix()), time: int(mockClock.Now().Add(1000 * time.Second).Unix()),
expireAtOpts: echovault.ExpireAtOptions{GT: true}, expireAtOpts: ExpireAtOptions{GT: true},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key8": {Value: "value8", ExpireAt: mockClock.Now().Add(3000 * time.Second)}, "key8": {Value: "value8", ExpireAt: mockClock.Now().Add(3000 * time.Second)},
}, },
@@ -387,7 +358,7 @@ func TestEchoVault_EXPIREAT(t *testing.T) {
cmd: "EXPIREAT", cmd: "EXPIREAT",
key: "key9", key: "key9",
time: int(mockClock.Now().Add(1000 * time.Second).Unix()), time: int(mockClock.Now().Add(1000 * time.Second).Unix()),
expireAtOpts: echovault.ExpireAtOptions{GT: true}, expireAtOpts: ExpireAtOptions{GT: true},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key9": {Value: "value9", ExpireAt: time.Time{}}, "key9": {Value: "value9", ExpireAt: time.Time{}},
}, },
@@ -398,7 +369,7 @@ func TestEchoVault_EXPIREAT(t *testing.T) {
cmd: "EXPIREAT", cmd: "EXPIREAT",
key: "key10", key: "key10",
time: int(mockClock.Now().Add(1000 * time.Second).Unix()), time: int(mockClock.Now().Add(1000 * time.Second).Unix()),
expireAtOpts: echovault.ExpireAtOptions{LT: true}, expireAtOpts: ExpireAtOptions{LT: true},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key10": {Value: "value10", ExpireAt: mockClock.Now().Add(3000 * time.Second)}, "key10": {Value: "value10", ExpireAt: mockClock.Now().Add(3000 * time.Second)},
}, },
@@ -410,7 +381,7 @@ func TestEchoVault_EXPIREAT(t *testing.T) {
cmd: "EXPIREAT", cmd: "EXPIREAT",
key: "key11", key: "key11",
time: int(mockClock.Now().Add(3000 * time.Second).Unix()), time: int(mockClock.Now().Add(3000 * time.Second).Unix()),
expireAtOpts: echovault.ExpireAtOptions{LT: true}, expireAtOpts: ExpireAtOptions{LT: true},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key11": {Value: "value11", ExpireAt: mockClock.Now().Add(1000 * time.Second)}, "key11": {Value: "value11", ExpireAt: mockClock.Now().Add(1000 * time.Second)},
}, },
@@ -422,7 +393,7 @@ func TestEchoVault_EXPIREAT(t *testing.T) {
cmd: "EXPIREAT", cmd: "EXPIREAT",
key: "key12", key: "key12",
time: int(mockClock.Now().Add(1000 * time.Second).Unix()), time: int(mockClock.Now().Add(1000 * time.Second).Unix()),
expireAtOpts: echovault.ExpireAtOptions{LT: true}, expireAtOpts: ExpireAtOptions{LT: true},
presetValues: map[string]internal.KeyData{ presetValues: map[string]internal.KeyData{
"key12": {Value: "value12", ExpireAt: time.Time{}}, "key12": {Value: "value12", ExpireAt: time.Time{}},
}, },
@@ -637,7 +608,7 @@ func TestEchoVault_SET(t *testing.T) {
presetValues map[string]internal.KeyData presetValues map[string]internal.KeyData
key string key string
value string value string
options echovault.SetOptions options SetOptions
want string want string
wantErr bool wantErr bool
}{ }{
@@ -646,7 +617,7 @@ func TestEchoVault_SET(t *testing.T) {
presetValues: nil, presetValues: nil,
key: "key1", key: "key1",
value: "value1", value: "value1",
options: echovault.SetOptions{}, options: SetOptions{},
want: "OK", want: "OK",
wantErr: false, wantErr: false,
}, },
@@ -655,7 +626,7 @@ func TestEchoVault_SET(t *testing.T) {
presetValues: nil, presetValues: nil,
key: "key2", key: "key2",
value: "value2", value: "value2",
options: echovault.SetOptions{NX: true}, options: SetOptions{NX: true},
want: "OK", want: "OK",
wantErr: false, wantErr: false,
}, },
@@ -669,7 +640,7 @@ func TestEchoVault_SET(t *testing.T) {
}, },
key: "key3", key: "key3",
value: "value3", value: "value3",
options: echovault.SetOptions{NX: true}, options: SetOptions{NX: true},
want: "", want: "",
wantErr: true, wantErr: true,
}, },
@@ -683,7 +654,7 @@ func TestEchoVault_SET(t *testing.T) {
}, },
key: "key4", key: "key4",
value: "value4", value: "value4",
options: echovault.SetOptions{XX: true}, options: SetOptions{XX: true},
want: "OK", want: "OK",
wantErr: false, wantErr: false,
}, },
@@ -692,7 +663,7 @@ func TestEchoVault_SET(t *testing.T) {
presetValues: nil, presetValues: nil,
key: "key5", key: "key5",
value: "value5", value: "value5",
options: echovault.SetOptions{XX: true}, options: SetOptions{XX: true},
want: "", want: "",
wantErr: true, wantErr: true,
}, },
@@ -701,7 +672,7 @@ func TestEchoVault_SET(t *testing.T) {
presetValues: nil, presetValues: nil,
key: "key6", key: "key6",
value: "value6", value: "value6",
options: echovault.SetOptions{EX: 100}, options: SetOptions{EX: 100},
want: "OK", want: "OK",
wantErr: false, wantErr: false,
}, },
@@ -710,7 +681,7 @@ func TestEchoVault_SET(t *testing.T) {
presetValues: nil, presetValues: nil,
key: "key7", key: "key7",
value: "value7", value: "value7",
options: echovault.SetOptions{PX: 4096}, options: SetOptions{PX: 4096},
want: "OK", want: "OK",
wantErr: false, wantErr: false,
}, },
@@ -719,7 +690,7 @@ func TestEchoVault_SET(t *testing.T) {
presetValues: nil, presetValues: nil,
key: "key8", key: "key8",
value: "value8", value: "value8",
options: echovault.SetOptions{EXAT: int(mockClock.Now().Add(200 * time.Second).Unix())}, options: SetOptions{EXAT: int(mockClock.Now().Add(200 * time.Second).Unix())},
want: "OK", want: "OK",
wantErr: false, wantErr: false,
}, },
@@ -727,7 +698,7 @@ func TestEchoVault_SET(t *testing.T) {
name: "Set exact expiry time in milliseconds from unix epoch", name: "Set exact expiry time in milliseconds from unix epoch",
key: "key9", key: "key9",
value: "value9", value: "value9",
options: echovault.SetOptions{PXAT: int(mockClock.Now().Add(4096 * time.Millisecond).UnixMilli())}, options: SetOptions{PXAT: int(mockClock.Now().Add(4096 * time.Millisecond).UnixMilli())},
presetValues: nil, presetValues: nil,
want: "OK", want: "OK",
wantErr: false, wantErr: false,
@@ -742,7 +713,7 @@ func TestEchoVault_SET(t *testing.T) {
}, },
key: "key10", key: "key10",
value: "value10", value: "value10",
options: echovault.SetOptions{GET: true, EX: 1000}, options: SetOptions{GET: true, EX: 1000},
want: "previous-value", want: "previous-value",
wantErr: false, wantErr: false,
}, },
@@ -751,7 +722,7 @@ func TestEchoVault_SET(t *testing.T) {
presetValues: nil, presetValues: nil,
key: "key11", key: "key11",
value: "value11", value: "value11",
options: echovault.SetOptions{GET: true, EX: 1000}, options: SetOptions{GET: true, EX: 1000},
want: "", want: "",
wantErr: false, wantErr: false,
}, },

View File

@@ -12,37 +12,15 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package hash package echovault
import ( import (
"context" "context"
"github.com/echovault/echovault/echovault"
"github.com/echovault/echovault/internal/config"
"reflect" "reflect"
"slices" "slices"
"testing" "testing"
) )
func createEchoVault() *echovault.EchoVault {
ev, _ := echovault.NewEchoVault(
echovault.WithConfig(config.Config{
DataDir: "",
}),
)
return ev
}
func presetValue(server *echovault.EchoVault, ctx context.Context, key string, value interface{}) error {
if _, err := server.CreateKeyAndLock(ctx, key); err != nil {
return err
}
if err := server.SetValue(ctx, key, value); err != nil {
return err
}
server.KeyUnlock(ctx, key)
return nil
}
func TestEchoVault_HDEL(t *testing.T) { func TestEchoVault_HDEL(t *testing.T) {
server := createEchoVault() server := createEchoVault()
@@ -455,7 +433,7 @@ func TestEchoVault_HRANDFIELD(t *testing.T) {
name string name string
presetValue interface{} presetValue interface{}
key string key string
options echovault.HRandFieldOptions options HRandFieldOptions
wantCount int wantCount int
want []string want []string
wantErr bool wantErr bool
@@ -464,7 +442,7 @@ func TestEchoVault_HRANDFIELD(t *testing.T) {
name: "Get a random field", name: "Get a random field",
presetValue: map[string]interface{}{"field1": "value1", "field2": 123456789, "field3": 3.142}, presetValue: map[string]interface{}{"field1": "value1", "field2": 123456789, "field3": 3.142},
key: "key1", key: "key1",
options: echovault.HRandFieldOptions{Count: 1}, options: HRandFieldOptions{Count: 1},
wantCount: 1, wantCount: 1,
want: []string{"field1", "field2", "field3"}, want: []string{"field1", "field2", "field3"},
wantErr: false, wantErr: false,
@@ -473,7 +451,7 @@ func TestEchoVault_HRANDFIELD(t *testing.T) {
name: "Get a random field with a value", name: "Get a random field with a value",
presetValue: map[string]interface{}{"field1": "value1", "field2": 123456789, "field3": 3.142}, presetValue: map[string]interface{}{"field1": "value1", "field2": 123456789, "field3": 3.142},
key: "key2", key: "key2",
options: echovault.HRandFieldOptions{WithValues: true, Count: 1}, options: HRandFieldOptions{WithValues: true, Count: 1},
wantCount: 2, wantCount: 2,
want: []string{"field1", "value1", "field2", "123456789", "field3", "3.142"}, want: []string{"field1", "value1", "field2", "123456789", "field3", "3.142"},
wantErr: false, wantErr: false,
@@ -488,7 +466,7 @@ func TestEchoVault_HRANDFIELD(t *testing.T) {
"field5": "value5", "field5": "value5",
}, },
key: "key3", key: "key3",
options: echovault.HRandFieldOptions{Count: 3}, options: HRandFieldOptions{Count: 3},
wantCount: 3, wantCount: 3,
want: []string{"field1", "field2", "field3", "field4", "field5"}, want: []string{"field1", "field2", "field3", "field4", "field5"},
wantErr: false, wantErr: false,
@@ -503,7 +481,7 @@ func TestEchoVault_HRANDFIELD(t *testing.T) {
"field5": "value5", "field5": "value5",
}, },
key: "key4", key: "key4",
options: echovault.HRandFieldOptions{WithValues: true, Count: 3}, options: HRandFieldOptions{WithValues: true, Count: 3},
wantCount: 6, wantCount: 6,
want: []string{ want: []string{
"field1", "value1", "field2", "123456789", "field3", "field1", "value1", "field2", "123456789", "field3",
@@ -521,7 +499,7 @@ func TestEchoVault_HRANDFIELD(t *testing.T) {
"field5": "value5", "field5": "value5",
}, },
key: "key5", key: "key5",
options: echovault.HRandFieldOptions{Count: 5}, options: HRandFieldOptions{Count: 5},
wantCount: 5, wantCount: 5,
want: []string{"field1", "field2", "field3", "field4", "field5"}, want: []string{"field1", "field2", "field3", "field4", "field5"},
wantErr: false, wantErr: false,
@@ -536,7 +514,7 @@ func TestEchoVault_HRANDFIELD(t *testing.T) {
"field5": "value5", "field5": "value5",
}, },
key: "key5", key: "key5",
options: echovault.HRandFieldOptions{WithValues: true, Count: 5}, options: HRandFieldOptions{WithValues: true, Count: 5},
wantCount: 10, wantCount: 10,
want: []string{ want: []string{
"field1", "value1", "field2", "123456789", "field3", "field1", "value1", "field2", "123456789", "field3",
@@ -548,7 +526,7 @@ func TestEchoVault_HRANDFIELD(t *testing.T) {
name: "Trying to get random field on a non hash map returns error", name: "Trying to get random field on a non hash map returns error",
presetValue: "Default value", presetValue: "Default value",
key: "key12", key: "key12",
options: echovault.HRandFieldOptions{}, options: HRandFieldOptions{},
wantCount: 0, wantCount: 0,
want: nil, want: nil,
wantErr: true, wantErr: true,

View File

@@ -12,36 +12,14 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package list package echovault
import ( import (
"context" "context"
"github.com/echovault/echovault/echovault"
"github.com/echovault/echovault/internal/config"
"reflect" "reflect"
"testing" "testing"
) )
func createEchoVault() *echovault.EchoVault {
ev, _ := echovault.NewEchoVault(
echovault.WithConfig(config.Config{
DataDir: "",
}),
)
return ev
}
func presetValue(server *echovault.EchoVault, ctx context.Context, key string, value interface{}) error {
if _, err := server.CreateKeyAndLock(ctx, key); err != nil {
return err
}
if err := server.SetValue(ctx, key, value); err != nil {
return err
}
server.KeyUnlock(ctx, key)
return nil
}
func TestEchoVault_LLEN(t *testing.T) { func TestEchoVault_LLEN(t *testing.T) {
server := createEchoVault() server := createEchoVault()

View File

@@ -12,4 +12,4 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package connection package echovault

View File

@@ -12,38 +12,16 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package set package echovault
import ( import (
"context" "context"
"github.com/echovault/echovault/echovault"
"github.com/echovault/echovault/internal/config"
"github.com/echovault/echovault/internal/modules/set" "github.com/echovault/echovault/internal/modules/set"
"reflect" "reflect"
"slices" "slices"
"testing" "testing"
) )
func createEchoVault() *echovault.EchoVault {
ev, _ := echovault.NewEchoVault(
echovault.WithConfig(config.Config{
DataDir: "",
}),
)
return ev
}
func presetValue(server *echovault.EchoVault, ctx context.Context, key string, value interface{}) error {
if _, err := server.CreateKeyAndLock(ctx, key); err != nil {
return err
}
if err := server.SetValue(ctx, key, value); err != nil {
return err
}
server.KeyUnlock(ctx, key)
return nil
}
func TestEchoVault_SADD(t *testing.T) { func TestEchoVault_SADD(t *testing.T) {
server := createEchoVault() server := createEchoVault()

View File

@@ -12,13 +12,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package sorted_set package echovault
import ( import (
"context" "context"
"github.com/echovault/echovault/echovault"
"github.com/echovault/echovault/internal" "github.com/echovault/echovault/internal"
"github.com/echovault/echovault/internal/config"
ss "github.com/echovault/echovault/internal/modules/sorted_set" ss "github.com/echovault/echovault/internal/modules/sorted_set"
"math" "math"
"reflect" "reflect"
@@ -26,26 +24,6 @@ import (
"testing" "testing"
) )
func createEchoVault() *echovault.EchoVault {
ev, _ := echovault.NewEchoVault(
echovault.WithConfig(config.Config{
DataDir: "",
}),
)
return ev
}
func presetValue(server *echovault.EchoVault, ctx context.Context, key string, value interface{}) error {
if _, err := server.CreateKeyAndLock(ctx, key); err != nil {
return err
}
if err := server.SetValue(ctx, key, value); err != nil {
return err
}
server.KeyUnlock(ctx, key)
return nil
}
func TestEchoVault_ZADD(t *testing.T) { func TestEchoVault_ZADD(t *testing.T) {
server := createEchoVault() server := createEchoVault()
@@ -55,7 +33,7 @@ func TestEchoVault_ZADD(t *testing.T) {
presetValue *ss.SortedSet presetValue *ss.SortedSet
key string key string
entries map[string]float64 entries map[string]float64
options echovault.ZAddOptions options ZAddOptions
want int want int
wantErr bool wantErr bool
}{ }{
@@ -71,7 +49,7 @@ func TestEchoVault_ZADD(t *testing.T) {
"member4": math.Inf(-1), "member4": math.Inf(-1),
"member5": math.Inf(1), "member5": math.Inf(1),
}, },
options: echovault.ZAddOptions{}, options: ZAddOptions{},
want: 5, want: 5,
wantErr: false, wantErr: false,
}, },
@@ -89,7 +67,7 @@ func TestEchoVault_ZADD(t *testing.T) {
"member4": 67.77, "member4": 67.77,
"member5": 10, "member5": 10,
}, },
options: echovault.ZAddOptions{NX: true}, options: ZAddOptions{NX: true},
want: 2, want: 2,
wantErr: false, wantErr: false,
}, },
@@ -107,7 +85,7 @@ func TestEchoVault_ZADD(t *testing.T) {
"member2": 67.77, "member2": 67.77,
"member3": 10, "member3": 10,
}, },
options: echovault.ZAddOptions{NX: true}, options: ZAddOptions{NX: true},
want: 0, want: 0,
wantErr: false, wantErr: false,
}, },
@@ -126,7 +104,7 @@ func TestEchoVault_ZADD(t *testing.T) {
"member3": 15, "member3": 15,
"member4": 99.75, "member4": 99.75,
}, },
options: echovault.ZAddOptions{XX: true, CH: true}, options: ZAddOptions{XX: true, CH: true},
want: 3, want: 3,
wantErr: false, wantErr: false,
}, },
@@ -144,7 +122,7 @@ func TestEchoVault_ZADD(t *testing.T) {
"member5": 100.5, "member5": 100.5,
"member6": 15, "member6": 15,
}, },
options: echovault.ZAddOptions{XX: true}, options: ZAddOptions{XX: true},
want: 0, want: 0,
wantErr: false, wantErr: false,
}, },
@@ -164,7 +142,7 @@ func TestEchoVault_ZADD(t *testing.T) {
"member4": 100.5, "member4": 100.5,
"member5": 15, "member5": 15,
}, },
options: echovault.ZAddOptions{XX: true, CH: true, GT: true}, options: ZAddOptions{XX: true, CH: true, GT: true},
want: 1, want: 1,
wantErr: false, wantErr: false,
}, },
@@ -184,7 +162,7 @@ func TestEchoVault_ZADD(t *testing.T) {
"member4": 100.5, "member4": 100.5,
"member5": 15, "member5": 15,
}, },
options: echovault.ZAddOptions{XX: true, LT: true}, options: ZAddOptions{XX: true, LT: true},
want: 0, want: 0,
wantErr: false, wantErr: false,
}, },
@@ -202,7 +180,7 @@ func TestEchoVault_ZADD(t *testing.T) {
"member4": 100.5, "member4": 100.5,
"member5": 15, "member5": 15,
}, },
options: echovault.ZAddOptions{XX: true, LT: true, CH: true}, options: ZAddOptions{XX: true, LT: true, CH: true},
want: 1, want: 1,
wantErr: false, wantErr: false,
}, },
@@ -218,7 +196,7 @@ func TestEchoVault_ZADD(t *testing.T) {
entries: map[string]float64{ entries: map[string]float64{
"member3": 5.5, "member3": 5.5,
}, },
options: echovault.ZAddOptions{INCR: true}, options: ZAddOptions{INCR: true},
want: 0, want: 0,
wantErr: false, wantErr: false,
}, },
@@ -231,7 +209,7 @@ func TestEchoVault_ZADD(t *testing.T) {
"member1": 3.5, "member1": 3.5,
"member5": 15, "member5": 15,
}, },
options: echovault.ZAddOptions{NX: true, LT: true, CH: true}, options: ZAddOptions{NX: true, LT: true, CH: true},
want: 0, want: 0,
wantErr: true, wantErr: true,
}, },
@@ -244,7 +222,7 @@ func TestEchoVault_ZADD(t *testing.T) {
"member1": 10.5, "member1": 10.5,
"member2": 12.5, "member2": 12.5,
}, },
options: echovault.ZAddOptions{INCR: true}, options: ZAddOptions{INCR: true},
want: 0, want: 0,
wantErr: true, wantErr: true,
}, },
@@ -855,7 +833,7 @@ func TestEchoVault_ZINTER(t *testing.T) {
preset bool preset bool
presetValues map[string]interface{} presetValues map[string]interface{}
keys []string keys []string
options echovault.ZInterOptions options ZInterOptions
want map[string]float64 want map[string]float64
wantErr bool wantErr bool
}{ }{
@@ -875,7 +853,7 @@ func TestEchoVault_ZINTER(t *testing.T) {
}), }),
}, },
keys: []string{"key1", "key2"}, keys: []string{"key1", "key2"},
options: echovault.ZInterOptions{}, options: ZInterOptions{},
want: map[string]float64{"three": 0, "four": 0, "five": 0}, want: map[string]float64{"three": 0, "four": 0, "five": 0},
wantErr: false, wantErr: false,
}, },
@@ -903,7 +881,7 @@ func TestEchoVault_ZINTER(t *testing.T) {
}), }),
}, },
keys: []string{"key3", "key4", "key5"}, keys: []string{"key3", "key4", "key5"},
options: echovault.ZInterOptions{WithScores: true}, options: ZInterOptions{WithScores: true},
want: map[string]float64{"one": 3, "eight": 24}, want: map[string]float64{"one": 3, "eight": 24},
wantErr: false, wantErr: false,
}, },
@@ -931,7 +909,7 @@ func TestEchoVault_ZINTER(t *testing.T) {
}), }),
}, },
keys: []string{"key6", "key7", "key8"}, keys: []string{"key6", "key7", "key8"},
options: echovault.ZInterOptions{Aggregate: "MIN", WithScores: true}, options: ZInterOptions{Aggregate: "MIN", WithScores: true},
want: map[string]float64{"one": 1, "eight": 8}, want: map[string]float64{"one": 1, "eight": 8},
wantErr: false, wantErr: false,
}, },
@@ -958,7 +936,7 @@ func TestEchoVault_ZINTER(t *testing.T) {
}), }),
}, },
keys: []string{"key9", "key10", "key11"}, keys: []string{"key9", "key10", "key11"},
options: echovault.ZInterOptions{WithScores: true, Aggregate: "MAX"}, options: ZInterOptions{WithScores: true, Aggregate: "MAX"},
want: map[string]float64{"one": 1000, "eight": 800}, want: map[string]float64{"one": 1000, "eight": 800},
wantErr: false, wantErr: false,
}, },
@@ -986,7 +964,7 @@ func TestEchoVault_ZINTER(t *testing.T) {
}), }),
}, },
keys: []string{"key12", "key13", "key14"}, keys: []string{"key12", "key13", "key14"},
options: echovault.ZInterOptions{WithScores: true, Aggregate: "SUM", Weights: []float64{1, 5, 3}}, options: ZInterOptions{WithScores: true, Aggregate: "SUM", Weights: []float64{1, 5, 3}},
want: map[string]float64{"one": 3105, "eight": 2808}, want: map[string]float64{"one": 3105, "eight": 2808},
wantErr: false, wantErr: false,
}, },
@@ -1014,7 +992,7 @@ func TestEchoVault_ZINTER(t *testing.T) {
}), }),
}, },
keys: []string{"key15", "key16", "key17"}, keys: []string{"key15", "key16", "key17"},
options: echovault.ZInterOptions{WithScores: true, Aggregate: "MAX", Weights: []float64{1, 5, 3}}, options: ZInterOptions{WithScores: true, Aggregate: "MAX", Weights: []float64{1, 5, 3}},
want: map[string]float64{"one": 3000, "eight": 2400}, want: map[string]float64{"one": 3000, "eight": 2400},
wantErr: false, wantErr: false,
}, },
@@ -1042,7 +1020,7 @@ func TestEchoVault_ZINTER(t *testing.T) {
}), }),
}, },
keys: []string{"key18", "key19", "key20"}, keys: []string{"key18", "key19", "key20"},
options: echovault.ZInterOptions{WithScores: true, Aggregate: "MIN", Weights: []float64{1, 5, 3}}, options: ZInterOptions{WithScores: true, Aggregate: "MIN", Weights: []float64{1, 5, 3}},
want: map[string]float64{"one": 5, "eight": 8}, want: map[string]float64{"one": 5, "eight": 8},
wantErr: false, wantErr: false,
}, },
@@ -1059,7 +1037,7 @@ func TestEchoVault_ZINTER(t *testing.T) {
"key22": ss.NewSortedSet([]ss.MemberParam{{Value: "one", Score: 1}}), "key22": ss.NewSortedSet([]ss.MemberParam{{Value: "one", Score: 1}}),
}, },
keys: []string{"key21", "key22"}, keys: []string{"key21", "key22"},
options: echovault.ZInterOptions{Weights: []float64{1, 2, 3}}, options: ZInterOptions{Weights: []float64{1, 2, 3}},
want: nil, want: nil,
wantErr: true, wantErr: true,
}, },
@@ -1079,7 +1057,7 @@ func TestEchoVault_ZINTER(t *testing.T) {
"key25": ss.NewSortedSet([]ss.MemberParam{{Value: "one", Score: 1}}), "key25": ss.NewSortedSet([]ss.MemberParam{{Value: "one", Score: 1}}),
}, },
keys: []string{"key23", "key24", "key25"}, keys: []string{"key23", "key24", "key25"},
options: echovault.ZInterOptions{Weights: []float64{5, 4}}, options: ZInterOptions{Weights: []float64{5, 4}},
want: nil, want: nil,
wantErr: true, wantErr: true,
}, },
@@ -1092,7 +1070,7 @@ func TestEchoVault_ZINTER(t *testing.T) {
"key28": ss.NewSortedSet([]ss.MemberParam{{Value: "one", Score: 1}}), "key28": ss.NewSortedSet([]ss.MemberParam{{Value: "one", Score: 1}}),
}, },
keys: []string{}, keys: []string{},
options: echovault.ZInterOptions{}, options: ZInterOptions{},
want: nil, want: nil,
wantErr: true, wantErr: true,
}, },
@@ -1110,7 +1088,7 @@ func TestEchoVault_ZINTER(t *testing.T) {
"key31": ss.NewSortedSet([]ss.MemberParam{{Value: "one", Score: 1}}), "key31": ss.NewSortedSet([]ss.MemberParam{{Value: "one", Score: 1}}),
}, },
keys: []string{"key29", "key30", "key31"}, keys: []string{"key29", "key30", "key31"},
options: echovault.ZInterOptions{}, options: ZInterOptions{},
want: nil, want: nil,
wantErr: true, wantErr: true,
}, },
@@ -1130,7 +1108,7 @@ func TestEchoVault_ZINTER(t *testing.T) {
}), }),
}, },
keys: []string{"non-existent", "key32", "key33"}, keys: []string{"non-existent", "key32", "key33"},
options: echovault.ZInterOptions{}, options: ZInterOptions{},
want: map[string]float64{}, want: map[string]float64{},
wantErr: false, wantErr: false,
}, },
@@ -1167,7 +1145,7 @@ func TestEchoVault_ZINTERSTORE(t *testing.T) {
presetValues map[string]interface{} presetValues map[string]interface{}
destination string destination string
keys []string keys []string
options echovault.ZInterStoreOptions options ZInterStoreOptions
want int want int
wantErr bool wantErr bool
}{ }{
@@ -1188,7 +1166,7 @@ func TestEchoVault_ZINTERSTORE(t *testing.T) {
}, },
destination: "destination1", destination: "destination1",
keys: []string{"key1", "key2"}, keys: []string{"key1", "key2"},
options: echovault.ZInterStoreOptions{}, options: ZInterStoreOptions{},
want: 3, want: 3,
wantErr: false, wantErr: false,
}, },
@@ -1217,7 +1195,7 @@ func TestEchoVault_ZINTERSTORE(t *testing.T) {
}, },
destination: "destination2", destination: "destination2",
keys: []string{"key3", "key4", "key5"}, keys: []string{"key3", "key4", "key5"},
options: echovault.ZInterStoreOptions{WithScores: true}, options: ZInterStoreOptions{WithScores: true},
want: 2, want: 2,
wantErr: false, wantErr: false,
}, },
@@ -1246,7 +1224,7 @@ func TestEchoVault_ZINTERSTORE(t *testing.T) {
}, },
destination: "destination3", destination: "destination3",
keys: []string{"key6", "key7", "key8"}, keys: []string{"key6", "key7", "key8"},
options: echovault.ZInterStoreOptions{WithScores: true, Aggregate: "MIN"}, options: ZInterStoreOptions{WithScores: true, Aggregate: "MIN"},
want: 2, want: 2,
wantErr: false, wantErr: false,
}, },
@@ -1275,7 +1253,7 @@ func TestEchoVault_ZINTERSTORE(t *testing.T) {
}, },
destination: "destination4", destination: "destination4",
keys: []string{"key9", "key10", "key11"}, keys: []string{"key9", "key10", "key11"},
options: echovault.ZInterStoreOptions{WithScores: true, Aggregate: "MAX"}, options: ZInterStoreOptions{WithScores: true, Aggregate: "MAX"},
want: 2, want: 2,
wantErr: false, wantErr: false,
}, },
@@ -1304,7 +1282,7 @@ func TestEchoVault_ZINTERSTORE(t *testing.T) {
}, },
destination: "destination5", destination: "destination5",
keys: []string{"key12", "key13", "key14"}, keys: []string{"key12", "key13", "key14"},
options: echovault.ZInterStoreOptions{WithScores: true, Aggregate: "SUM", Weights: []float64{1, 5, 3}}, options: ZInterStoreOptions{WithScores: true, Aggregate: "SUM", Weights: []float64{1, 5, 3}},
want: 2, want: 2,
wantErr: false, wantErr: false,
}, },
@@ -1333,7 +1311,7 @@ func TestEchoVault_ZINTERSTORE(t *testing.T) {
}, },
destination: "destination6", destination: "destination6",
keys: []string{"key15", "key16", "key17"}, keys: []string{"key15", "key16", "key17"},
options: echovault.ZInterStoreOptions{WithScores: true, Aggregate: "MAX", Weights: []float64{1, 5, 3}}, options: ZInterStoreOptions{WithScores: true, Aggregate: "MAX", Weights: []float64{1, 5, 3}},
want: 2, want: 2,
wantErr: false, wantErr: false,
}, },
@@ -1362,7 +1340,7 @@ func TestEchoVault_ZINTERSTORE(t *testing.T) {
}, },
destination: "destination7", destination: "destination7",
keys: []string{"key18", "key19", "key20"}, keys: []string{"key18", "key19", "key20"},
options: echovault.ZInterStoreOptions{WithScores: true, Aggregate: "MIN", Weights: []float64{1, 5, 3}}, options: ZInterStoreOptions{WithScores: true, Aggregate: "MIN", Weights: []float64{1, 5, 3}},
want: 2, want: 2,
wantErr: false, wantErr: false,
}, },
@@ -1380,7 +1358,7 @@ func TestEchoVault_ZINTERSTORE(t *testing.T) {
}, },
destination: "destination8", destination: "destination8",
keys: []string{"key21", "key22"}, keys: []string{"key21", "key22"},
options: echovault.ZInterStoreOptions{Weights: []float64{1, 2, 3}}, options: ZInterStoreOptions{Weights: []float64{1, 2, 3}},
want: 0, want: 0,
wantErr: true, wantErr: true,
}, },
@@ -1401,7 +1379,7 @@ func TestEchoVault_ZINTERSTORE(t *testing.T) {
}, },
destination: "destination9", destination: "destination9",
keys: []string{"key23", "key24"}, keys: []string{"key23", "key24"},
options: echovault.ZInterStoreOptions{Weights: []float64{5}}, options: ZInterStoreOptions{Weights: []float64{5}},
want: 0, want: 0,
wantErr: true, wantErr: true,
}, },
@@ -1415,7 +1393,7 @@ func TestEchoVault_ZINTERSTORE(t *testing.T) {
}, },
destination: "destination10", destination: "destination10",
keys: []string{}, keys: []string{},
options: echovault.ZInterStoreOptions{Weights: []float64{5, 4}}, options: ZInterStoreOptions{Weights: []float64{5, 4}},
want: 0, want: 0,
wantErr: true, wantErr: true,
}, },
@@ -1434,7 +1412,7 @@ func TestEchoVault_ZINTERSTORE(t *testing.T) {
}, },
destination: "destination11", destination: "destination11",
keys: []string{"key29", "key30", "key31"}, keys: []string{"key29", "key30", "key31"},
options: echovault.ZInterStoreOptions{}, options: ZInterStoreOptions{},
want: 0, want: 0,
wantErr: true, wantErr: true,
}, },
@@ -1455,7 +1433,7 @@ func TestEchoVault_ZINTERSTORE(t *testing.T) {
}, },
destination: "destination12", destination: "destination12",
keys: []string{"non-existent", "key32", "key33"}, keys: []string{"non-existent", "key32", "key33"},
options: echovault.ZInterStoreOptions{}, options: ZInterStoreOptions{},
want: 0, want: 0,
wantErr: false, wantErr: false,
}, },
@@ -1582,7 +1560,7 @@ func TestEchoVault_ZMPOP(t *testing.T) {
preset bool preset bool
presetValues map[string]interface{} presetValues map[string]interface{}
keys []string keys []string
options echovault.ZMPopOptions options ZMPopOptions
want [][]string want [][]string
wantErr bool wantErr bool
}{ }{
@@ -1597,7 +1575,7 @@ func TestEchoVault_ZMPOP(t *testing.T) {
}), }),
}, },
keys: []string{"key1"}, keys: []string{"key1"},
options: echovault.ZMPopOptions{}, options: ZMPopOptions{},
want: [][]string{ want: [][]string{
{"one", "1"}, {"one", "1"},
}, },
@@ -1614,7 +1592,7 @@ func TestEchoVault_ZMPOP(t *testing.T) {
}), }),
}, },
keys: []string{"key2"}, keys: []string{"key2"},
options: echovault.ZMPopOptions{Min: true}, options: ZMPopOptions{Min: true},
want: [][]string{ want: [][]string{
{"one", "1"}, {"one", "1"},
}, },
@@ -1631,7 +1609,7 @@ func TestEchoVault_ZMPOP(t *testing.T) {
}), }),
}, },
keys: []string{"key3"}, keys: []string{"key3"},
options: echovault.ZMPopOptions{Max: true}, options: ZMPopOptions{Max: true},
want: [][]string{ want: [][]string{
{"five", "5"}, {"five", "5"},
}, },
@@ -1648,7 +1626,7 @@ func TestEchoVault_ZMPOP(t *testing.T) {
}), }),
}, },
keys: []string{"key4"}, keys: []string{"key4"},
options: echovault.ZMPopOptions{Min: true, Count: 5}, options: ZMPopOptions{Min: true, Count: 5},
want: [][]string{ want: [][]string{
{"one", "1"}, {"two", "2"}, {"three", "3"}, {"one", "1"}, {"two", "2"}, {"three", "3"},
{"four", "4"}, {"five", "5"}, {"four", "4"}, {"five", "5"},
@@ -1666,7 +1644,7 @@ func TestEchoVault_ZMPOP(t *testing.T) {
}), }),
}, },
keys: []string{"key5"}, keys: []string{"key5"},
options: echovault.ZMPopOptions{Max: true, Count: 5}, options: ZMPopOptions{Max: true, Count: 5},
want: [][]string{{"two", "2"}, {"three", "3"}, {"four", "4"}, {"five", "5"}, {"six", "6"}}, want: [][]string{{"two", "2"}, {"three", "3"}, {"four", "4"}, {"five", "5"}, {"six", "6"}},
wantErr: false, wantErr: false,
}, },
@@ -1682,7 +1660,7 @@ func TestEchoVault_ZMPOP(t *testing.T) {
}), }),
}, },
keys: []string{"key6", "key7"}, keys: []string{"key6", "key7"},
options: echovault.ZMPopOptions{Max: true, Count: 5}, options: ZMPopOptions{Max: true, Count: 5},
want: [][]string{{"two", "2"}, {"three", "3"}, {"four", "4"}, {"five", "5"}, {"six", "6"}}, want: [][]string{{"two", "2"}, {"three", "3"}, {"four", "4"}, {"five", "5"}, {"six", "6"}},
wantErr: false, wantErr: false,
}, },
@@ -1700,7 +1678,7 @@ func TestEchoVault_ZMPOP(t *testing.T) {
}), }),
}, },
keys: []string{"key8", "key9", "key10", "key11"}, keys: []string{"key8", "key9", "key10", "key11"},
options: echovault.ZMPopOptions{Min: true, Count: 5}, options: ZMPopOptions{Min: true, Count: 5},
want: [][]string{{"one", "1"}, {"two", "2"}, {"three", "3"}, {"four", "4"}, {"five", "5"}}, want: [][]string{{"one", "1"}, {"two", "2"}, {"three", "3"}, {"four", "4"}, {"five", "5"}},
wantErr: false, wantErr: false,
}, },
@@ -1997,7 +1975,7 @@ func TestEchoVault_ZRANGE(t *testing.T) {
key string key string
start string start string
stop string stop string
options echovault.ZRangeOptions options ZRangeOptions
want map[string]float64 want map[string]float64
wantErr bool wantErr bool
}{ }{
@@ -2013,7 +1991,7 @@ func TestEchoVault_ZRANGE(t *testing.T) {
key: "key1", key: "key1",
start: "3", start: "3",
stop: "7", stop: "7",
options: echovault.ZRangeOptions{ByScore: true}, options: ZRangeOptions{ByScore: true},
want: map[string]float64{"three": 0, "four": 0, "five": 0, "six": 0, "seven": 0}, want: map[string]float64{"three": 0, "four": 0, "five": 0, "six": 0, "seven": 0},
wantErr: false, wantErr: false,
}, },
@@ -2029,7 +2007,7 @@ func TestEchoVault_ZRANGE(t *testing.T) {
key: "key2", key: "key2",
start: "3", start: "3",
stop: "7", stop: "7",
options: echovault.ZRangeOptions{ByScore: true, WithScores: true}, options: ZRangeOptions{ByScore: true, WithScores: true},
want: map[string]float64{"three": 3, "four": 4, "five": 5, "six": 6, "seven": 7}, want: map[string]float64{"three": 3, "four": 4, "five": 5, "six": 6, "seven": 7},
wantErr: false, wantErr: false,
}, },
@@ -2047,7 +2025,7 @@ func TestEchoVault_ZRANGE(t *testing.T) {
key: "key3", key: "key3",
start: "3", start: "3",
stop: "7", stop: "7",
options: echovault.ZRangeOptions{WithScores: true, ByScore: true, Offset: 2, Count: 4}, options: ZRangeOptions{WithScores: true, ByScore: true, Offset: 2, Count: 4},
want: map[string]float64{"three": 3, "four": 4, "five": 5}, want: map[string]float64{"three": 3, "four": 4, "five": 5},
wantErr: false, wantErr: false,
}, },
@@ -2063,7 +2041,7 @@ func TestEchoVault_ZRANGE(t *testing.T) {
key: "key4", key: "key4",
start: "c", start: "c",
stop: "g", stop: "g",
options: echovault.ZRangeOptions{ByLex: true}, options: ZRangeOptions{ByLex: true},
want: map[string]float64{"c": 0, "d": 0, "e": 0, "f": 0, "g": 0}, want: map[string]float64{"c": 0, "d": 0, "e": 0, "f": 0, "g": 0},
wantErr: false, wantErr: false,
}, },
@@ -2079,7 +2057,7 @@ func TestEchoVault_ZRANGE(t *testing.T) {
key: "key5", key: "key5",
start: "a", start: "a",
stop: "f", stop: "f",
options: echovault.ZRangeOptions{ByLex: true, WithScores: true}, options: ZRangeOptions{ByLex: true, WithScores: true},
want: map[string]float64{"a": 1, "b": 1, "c": 1, "d": 1, "e": 1, "f": 1}, want: map[string]float64{"a": 1, "b": 1, "c": 1, "d": 1, "e": 1, "f": 1},
wantErr: false, wantErr: false,
}, },
@@ -2097,7 +2075,7 @@ func TestEchoVault_ZRANGE(t *testing.T) {
key: "key6", key: "key6",
start: "a", start: "a",
stop: "h", stop: "h",
options: echovault.ZRangeOptions{WithScores: true, ByLex: true, Offset: 2, Count: 4}, options: ZRangeOptions{WithScores: true, ByLex: true, Offset: 2, Count: 4},
want: map[string]float64{"c": 1, "d": 1, "e": 1}, want: map[string]float64{"c": 1, "d": 1, "e": 1},
wantErr: false, wantErr: false,
}, },
@@ -2113,7 +2091,7 @@ func TestEchoVault_ZRANGE(t *testing.T) {
key: "key7", key: "key7",
start: "a", start: "a",
stop: "h", stop: "h",
options: echovault.ZRangeOptions{WithScores: true, ByLex: true, Offset: 2, Count: 4}, options: ZRangeOptions{WithScores: true, ByLex: true, Offset: 2, Count: 4},
want: map[string]float64{}, want: map[string]float64{},
wantErr: false, wantErr: false,
}, },
@@ -2124,7 +2102,7 @@ func TestEchoVault_ZRANGE(t *testing.T) {
key: "key10", key: "key10",
start: "a", start: "a",
stop: "h", stop: "h",
options: echovault.ZRangeOptions{WithScores: true, ByLex: true, Offset: 2, Count: 4}, options: ZRangeOptions{WithScores: true, ByLex: true, Offset: 2, Count: 4},
want: nil, want: nil,
wantErr: true, wantErr: true,
}, },
@@ -2161,7 +2139,7 @@ func TestEchoVault_ZRANGESTORE(t *testing.T) {
source string source string
start string start string
stop string stop string
options echovault.ZRangeStoreOptions options ZRangeStoreOptions
want int want int
wantErr bool wantErr bool
}{ }{
@@ -2180,7 +2158,7 @@ func TestEchoVault_ZRANGESTORE(t *testing.T) {
source: "key1", source: "key1",
start: "3", start: "3",
stop: "7", stop: "7",
options: echovault.ZRangeStoreOptions{ByScore: true}, options: ZRangeStoreOptions{ByScore: true},
want: 5, want: 5,
wantErr: false, wantErr: false,
}, },
@@ -2199,7 +2177,7 @@ func TestEchoVault_ZRANGESTORE(t *testing.T) {
source: "key2", source: "key2",
start: "3", start: "3",
stop: "7", stop: "7",
options: echovault.ZRangeStoreOptions{WithScores: true, ByScore: true}, options: ZRangeStoreOptions{WithScores: true, ByScore: true},
want: 5, want: 5,
wantErr: false, wantErr: false,
}, },
@@ -2220,7 +2198,7 @@ func TestEchoVault_ZRANGESTORE(t *testing.T) {
source: "key3", source: "key3",
start: "3", start: "3",
stop: "7", stop: "7",
options: echovault.ZRangeStoreOptions{ByScore: true, WithScores: true, Offset: 2, Count: 4}, options: ZRangeStoreOptions{ByScore: true, WithScores: true, Offset: 2, Count: 4},
want: 3, want: 3,
wantErr: false, wantErr: false,
}, },
@@ -2239,7 +2217,7 @@ func TestEchoVault_ZRANGESTORE(t *testing.T) {
source: "key4", source: "key4",
start: "c", start: "c",
stop: "g", stop: "g",
options: echovault.ZRangeStoreOptions{ByLex: true}, options: ZRangeStoreOptions{ByLex: true},
want: 5, want: 5,
wantErr: false, wantErr: false,
}, },
@@ -2258,7 +2236,7 @@ func TestEchoVault_ZRANGESTORE(t *testing.T) {
source: "key5", source: "key5",
start: "a", start: "a",
stop: "f", stop: "f",
options: echovault.ZRangeStoreOptions{ByLex: true, WithScores: true}, options: ZRangeStoreOptions{ByLex: true, WithScores: true},
want: 6, want: 6,
wantErr: false, wantErr: false,
}, },
@@ -2279,7 +2257,7 @@ func TestEchoVault_ZRANGESTORE(t *testing.T) {
source: "key6", source: "key6",
start: "a", start: "a",
stop: "h", stop: "h",
options: echovault.ZRangeStoreOptions{WithScores: true, ByLex: true, Offset: 2, Count: 4}, options: ZRangeStoreOptions{WithScores: true, ByLex: true, Offset: 2, Count: 4},
want: 3, want: 3,
wantErr: false, wantErr: false,
}, },
@@ -2301,7 +2279,7 @@ func TestEchoVault_ZRANGESTORE(t *testing.T) {
source: "key7", source: "key7",
start: "a", start: "a",
stop: "h", stop: "h",
options: echovault.ZRangeStoreOptions{WithScores: true, ByLex: true, Offset: 2, Count: 4}, options: ZRangeStoreOptions{WithScores: true, ByLex: true, Offset: 2, Count: 4},
want: 3, want: 3,
wantErr: false, wantErr: false,
}, },
@@ -2320,7 +2298,7 @@ func TestEchoVault_ZRANGESTORE(t *testing.T) {
source: "key8", source: "key8",
start: "a", start: "a",
stop: "h", stop: "h",
options: echovault.ZRangeStoreOptions{WithScores: true, ByLex: true, Offset: 2, Count: 4}, options: ZRangeStoreOptions{WithScores: true, ByLex: true, Offset: 2, Count: 4},
want: 0, want: 0,
wantErr: false, wantErr: false,
}, },
@@ -2334,7 +2312,7 @@ func TestEchoVault_ZRANGESTORE(t *testing.T) {
source: "key9", source: "key9",
start: "a", start: "a",
stop: "h", stop: "h",
options: echovault.ZRangeStoreOptions{WithScores: true, ByLex: true, Offset: 2, Count: 4}, options: ZRangeStoreOptions{WithScores: true, ByLex: true, Offset: 2, Count: 4},
want: 0, want: 0,
wantErr: true, wantErr: true,
}, },
@@ -2684,7 +2662,7 @@ func TestEchoVault_ZUNION(t *testing.T) {
preset bool preset bool
presetValues map[string]interface{} presetValues map[string]interface{}
keys []string keys []string
options echovault.ZUnionOptions options ZUnionOptions
want map[string]float64 want map[string]float64
wantErr bool wantErr bool
}{ }{
@@ -2704,7 +2682,7 @@ func TestEchoVault_ZUNION(t *testing.T) {
}), }),
}, },
keys: []string{"key1", "key2"}, keys: []string{"key1", "key2"},
options: echovault.ZUnionOptions{}, options: ZUnionOptions{},
want: map[string]float64{ want: map[string]float64{
"one": 0, "two": 0, "three": 0, "four": 0, "one": 0, "two": 0, "three": 0, "four": 0,
"five": 0, "six": 0, "seven": 0, "eight": 0, "five": 0, "six": 0, "seven": 0, "eight": 0,
@@ -2735,7 +2713,7 @@ func TestEchoVault_ZUNION(t *testing.T) {
}), }),
}, },
keys: []string{"key3", "key4", "key5"}, keys: []string{"key3", "key4", "key5"},
options: echovault.ZUnionOptions{WithScores: true}, options: ZUnionOptions{WithScores: true},
want: map[string]float64{ want: map[string]float64{
"one": 3, "two": 4, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 24, "nine": 9, "one": 3, "two": 4, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 24, "nine": 9,
"ten": 10, "eleven": 11, "twelve": 24, "thirty-six": 72, "ten": 10, "eleven": 11, "twelve": 24, "thirty-six": 72,
@@ -2766,7 +2744,7 @@ func TestEchoVault_ZUNION(t *testing.T) {
}), }),
}, },
keys: []string{"key6", "key7", "key8"}, keys: []string{"key6", "key7", "key8"},
options: echovault.ZUnionOptions{WithScores: true, Aggregate: "MIN"}, options: ZUnionOptions{WithScores: true, Aggregate: "MIN"},
want: map[string]float64{ want: map[string]float64{
"one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9, "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9,
"ten": 10, "eleven": 11, "twelve": 12, "thirty-six": 36, "ten": 10, "eleven": 11, "twelve": 12, "thirty-six": 36,
@@ -2797,7 +2775,7 @@ func TestEchoVault_ZUNION(t *testing.T) {
}), }),
}, },
keys: []string{"key9", "key10", "key11"}, keys: []string{"key9", "key10", "key11"},
options: echovault.ZUnionOptions{WithScores: true, Aggregate: "MAX"}, options: ZUnionOptions{WithScores: true, Aggregate: "MAX"},
want: map[string]float64{ want: map[string]float64{
"one": 1000, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 800, "nine": 9, "one": 1000, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 800, "nine": 9,
"ten": 10, "eleven": 11, "twelve": 12, "thirty-six": 72, "ten": 10, "eleven": 11, "twelve": 12, "thirty-six": 72,
@@ -2828,7 +2806,7 @@ func TestEchoVault_ZUNION(t *testing.T) {
}), }),
}, },
keys: []string{"key12", "key13", "key14"}, keys: []string{"key12", "key13", "key14"},
options: echovault.ZUnionOptions{WithScores: true, Aggregate: "SUM", Weights: []float64{1, 2, 3}}, options: ZUnionOptions{WithScores: true, Aggregate: "SUM", Weights: []float64{1, 2, 3}},
want: map[string]float64{ want: map[string]float64{
"one": 3102, "two": 6, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 2568, "one": 3102, "two": 6, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 2568,
"nine": 27, "ten": 30, "eleven": 22, "twelve": 60, "thirty-six": 72, "nine": 27, "ten": 30, "eleven": 22, "twelve": 60, "thirty-six": 72,
@@ -2859,7 +2837,7 @@ func TestEchoVault_ZUNION(t *testing.T) {
}), }),
}, },
keys: []string{"key15", "key16", "key17"}, keys: []string{"key15", "key16", "key17"},
options: echovault.ZUnionOptions{WithScores: true, Aggregate: "MAX", Weights: []float64{1, 2, 3}}, options: ZUnionOptions{WithScores: true, Aggregate: "MAX", Weights: []float64{1, 2, 3}},
want: map[string]float64{ want: map[string]float64{
"one": 3000, "two": 4, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 2400, "one": 3000, "two": 4, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 2400,
"nine": 27, "ten": 30, "eleven": 22, "twelve": 36, "thirty-six": 72, "nine": 27, "ten": 30, "eleven": 22, "twelve": 36, "thirty-six": 72,
@@ -2890,7 +2868,7 @@ func TestEchoVault_ZUNION(t *testing.T) {
}), }),
}, },
keys: []string{"key18", "key19", "key20"}, keys: []string{"key18", "key19", "key20"},
options: echovault.ZUnionOptions{WithScores: true, Aggregate: "MIN", Weights: []float64{1, 2, 3}}, options: ZUnionOptions{WithScores: true, Aggregate: "MIN", Weights: []float64{1, 2, 3}},
want: map[string]float64{ want: map[string]float64{
"one": 2, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 27, "one": 2, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 27,
"ten": 30, "eleven": 22, "twelve": 24, "thirty-six": 72, "ten": 30, "eleven": 22, "twelve": 24, "thirty-six": 72,
@@ -2910,7 +2888,7 @@ func TestEchoVault_ZUNION(t *testing.T) {
"key22": ss.NewSortedSet([]ss.MemberParam{{Value: "one", Score: 1}}), "key22": ss.NewSortedSet([]ss.MemberParam{{Value: "one", Score: 1}}),
}, },
keys: []string{"key21", "key22"}, keys: []string{"key21", "key22"},
options: echovault.ZUnionOptions{Weights: []float64{1, 2, 3}}, options: ZUnionOptions{Weights: []float64{1, 2, 3}},
want: nil, want: nil,
wantErr: true, wantErr: true,
}, },
@@ -2930,7 +2908,7 @@ func TestEchoVault_ZUNION(t *testing.T) {
"key25": ss.NewSortedSet([]ss.MemberParam{{Value: "one", Score: 1}}), "key25": ss.NewSortedSet([]ss.MemberParam{{Value: "one", Score: 1}}),
}, },
keys: []string{"key23", "key24", "key25"}, keys: []string{"key23", "key24", "key25"},
options: echovault.ZUnionOptions{Weights: []float64{5, 4}}, options: ZUnionOptions{Weights: []float64{5, 4}},
want: nil, want: nil,
wantErr: true, wantErr: true,
}, },
@@ -2943,7 +2921,7 @@ func TestEchoVault_ZUNION(t *testing.T) {
"key28": ss.NewSortedSet([]ss.MemberParam{{Value: "one", Score: 1}}), "key28": ss.NewSortedSet([]ss.MemberParam{{Value: "one", Score: 1}}),
}, },
keys: []string{}, keys: []string{},
options: echovault.ZUnionOptions{Weights: []float64{5, 4}}, options: ZUnionOptions{Weights: []float64{5, 4}},
want: nil, want: nil,
wantErr: true, wantErr: true,
}, },
@@ -2961,7 +2939,7 @@ func TestEchoVault_ZUNION(t *testing.T) {
"key31": ss.NewSortedSet([]ss.MemberParam{{Value: "one", Score: 1}}), "key31": ss.NewSortedSet([]ss.MemberParam{{Value: "one", Score: 1}}),
}, },
keys: []string{"key29", "key30", "key31"}, keys: []string{"key29", "key30", "key31"},
options: echovault.ZUnionOptions{}, options: ZUnionOptions{},
want: nil, want: nil,
wantErr: true, wantErr: true,
}, },
@@ -2981,7 +2959,7 @@ func TestEchoVault_ZUNION(t *testing.T) {
}), }),
}, },
keys: []string{"non-existent", "key32", "key33"}, keys: []string{"non-existent", "key32", "key33"},
options: echovault.ZUnionOptions{}, options: ZUnionOptions{},
want: map[string]float64{ want: map[string]float64{
"one": 0, "two": 0, "thirty-six": 0, "twelve": 0, "eleven": 0, "one": 0, "two": 0, "thirty-six": 0, "twelve": 0, "eleven": 0,
"seven": 0, "eight": 0, "nine": 0, "ten": 0, "seven": 0, "eight": 0, "nine": 0, "ten": 0,
@@ -3021,7 +2999,7 @@ func TestEchoVault_ZUNIONSTORE(t *testing.T) {
presetValues map[string]interface{} presetValues map[string]interface{}
destination string destination string
keys []string keys []string
options echovault.ZUnionStoreOptions options ZUnionStoreOptions
want int want int
wantErr bool wantErr bool
}{ }{
@@ -3042,7 +3020,7 @@ func TestEchoVault_ZUNIONSTORE(t *testing.T) {
}, },
destination: "destination1", destination: "destination1",
keys: []string{"key1", "key2"}, keys: []string{"key1", "key2"},
options: echovault.ZUnionStoreOptions{}, options: ZUnionStoreOptions{},
want: 8, want: 8,
wantErr: false, wantErr: false,
}, },
@@ -3071,7 +3049,7 @@ func TestEchoVault_ZUNIONSTORE(t *testing.T) {
}, },
destination: "destination2", destination: "destination2",
keys: []string{"key3", "key4", "key5"}, keys: []string{"key3", "key4", "key5"},
options: echovault.ZUnionStoreOptions{WithScores: true}, options: ZUnionStoreOptions{WithScores: true},
want: 13, want: 13,
wantErr: false, wantErr: false,
}, },
@@ -3100,7 +3078,7 @@ func TestEchoVault_ZUNIONSTORE(t *testing.T) {
}, },
destination: "destination3", destination: "destination3",
keys: []string{"key6", "key7", "key8"}, keys: []string{"key6", "key7", "key8"},
options: echovault.ZUnionStoreOptions{WithScores: true, Aggregate: "MIN"}, options: ZUnionStoreOptions{WithScores: true, Aggregate: "MIN"},
want: 13, want: 13,
wantErr: false, wantErr: false,
}, },
@@ -3129,7 +3107,7 @@ func TestEchoVault_ZUNIONSTORE(t *testing.T) {
}, },
destination: "destination4", destination: "destination4",
keys: []string{"key9", "key10", "key11"}, keys: []string{"key9", "key10", "key11"},
options: echovault.ZUnionStoreOptions{WithScores: true, Aggregate: "MAX"}, options: ZUnionStoreOptions{WithScores: true, Aggregate: "MAX"},
want: 13, want: 13,
wantErr: false, wantErr: false,
}, },
@@ -3158,7 +3136,7 @@ func TestEchoVault_ZUNIONSTORE(t *testing.T) {
}, },
destination: "destination5", destination: "destination5",
keys: []string{"key12", "key13", "key14"}, keys: []string{"key12", "key13", "key14"},
options: echovault.ZUnionStoreOptions{WithScores: true, Aggregate: "SUM", Weights: []float64{1, 2, 3}}, options: ZUnionStoreOptions{WithScores: true, Aggregate: "SUM", Weights: []float64{1, 2, 3}},
want: 13, want: 13,
wantErr: false, wantErr: false,
}, },
@@ -3187,7 +3165,7 @@ func TestEchoVault_ZUNIONSTORE(t *testing.T) {
}, },
destination: "destination6", destination: "destination6",
keys: []string{"key15", "key16", "key17"}, keys: []string{"key15", "key16", "key17"},
options: echovault.ZUnionStoreOptions{WithScores: true, Aggregate: "MAX", Weights: []float64{1, 2, 3}}, options: ZUnionStoreOptions{WithScores: true, Aggregate: "MAX", Weights: []float64{1, 2, 3}},
want: 13, want: 13,
wantErr: false, wantErr: false,
}, },
@@ -3216,7 +3194,7 @@ func TestEchoVault_ZUNIONSTORE(t *testing.T) {
}, },
destination: "destination7", destination: "destination7",
keys: []string{"destination7", "key18", "key19", "key20"}, keys: []string{"destination7", "key18", "key19", "key20"},
options: echovault.ZUnionStoreOptions{WithScores: true, Aggregate: "MIN", Weights: []float64{1, 2, 3}}, options: ZUnionStoreOptions{WithScores: true, Aggregate: "MIN", Weights: []float64{1, 2, 3}},
want: 13, want: 13,
wantErr: false, wantErr: false,
}, },
@@ -3234,7 +3212,7 @@ func TestEchoVault_ZUNIONSTORE(t *testing.T) {
}, },
destination: "destination8", destination: "destination8",
keys: []string{"key21", "key22"}, keys: []string{"key21", "key22"},
options: echovault.ZUnionStoreOptions{Weights: []float64{1, 2, 3}}, options: ZUnionStoreOptions{Weights: []float64{1, 2, 3}},
want: 0, want: 0,
wantErr: true, wantErr: true,
}, },
@@ -3255,7 +3233,7 @@ func TestEchoVault_ZUNIONSTORE(t *testing.T) {
}, },
destination: "destination9", destination: "destination9",
keys: []string{"key23", "key24", "key25"}, keys: []string{"key23", "key24", "key25"},
options: echovault.ZUnionStoreOptions{Weights: []float64{5, 4}}, options: ZUnionStoreOptions{Weights: []float64{5, 4}},
want: 0, want: 0,
wantErr: true, wantErr: true,
}, },
@@ -3274,7 +3252,7 @@ func TestEchoVault_ZUNIONSTORE(t *testing.T) {
}, },
destination: "destination11", destination: "destination11",
keys: []string{"key29", "key30", "key31"}, keys: []string{"key29", "key30", "key31"},
options: echovault.ZUnionStoreOptions{}, options: ZUnionStoreOptions{},
want: 0, want: 0,
wantErr: true, wantErr: true,
}, },

View File

@@ -12,35 +12,13 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package str package echovault
import ( import (
"context" "context"
"github.com/echovault/echovault/echovault"
"github.com/echovault/echovault/internal/config"
"testing" "testing"
) )
func createEchoVault() *echovault.EchoVault {
ev, _ := echovault.NewEchoVault(
echovault.WithConfig(config.Config{
DataDir: "",
}),
)
return ev
}
func presetValue(server *echovault.EchoVault, ctx context.Context, key string, value interface{}) error {
if _, err := server.CreateKeyAndLock(ctx, key); err != nil {
return err
}
if err := server.SetValue(ctx, key, value); err != nil {
return err
}
server.KeyUnlock(ctx, key)
return nil
}
func TestEchoVault_SUBSTR(t *testing.T) { func TestEchoVault_SUBSTR(t *testing.T) {
server := createEchoVault() server := createEchoVault()

34
echovault/test_helpers.go Normal file
View File

@@ -0,0 +1,34 @@
package echovault
import (
"context"
"github.com/echovault/echovault/internal"
"github.com/echovault/echovault/internal/config"
)
func createEchoVault() *EchoVault {
ev, _ := NewEchoVault(
WithConfig(config.Config{
DataDir: "",
}),
)
return ev
}
func presetValue(server *EchoVault, ctx context.Context, key string, value interface{}) error {
if _, err := server.CreateKeyAndLock(ctx, key); err != nil {
return err
}
if err := server.SetValue(ctx, key, value); err != nil {
return err
}
server.KeyUnlock(ctx, key)
return nil
}
func presetKeyData(server *EchoVault, ctx context.Context, key string, data internal.KeyData) {
_, _ = server.CreateKeyAndLock(ctx, key)
defer server.KeyUnlock(ctx, key)
_ = server.SetValue(ctx, key, data.Value)
server.SetExpiry(ctx, key, data.ExpireAt, false)
}

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package acl package acl_test
import ( import (
"crypto/sha256" "crypto/sha256"

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package admin package admin_test
import ( import (
"bytes" "bytes"

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package connection package connection_test
import ( import (
"bytes" "bytes"

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package generic package generic_test
import ( import (
"bytes" "bytes"

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package hash package hash_test
import ( import (
"bytes" "bytes"

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package list package list_test
import ( import (
"bytes" "bytes"

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package pubsub package pubsub_test
import ( import (
"bytes" "bytes"

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package set package set_test
import ( import (
"bytes" "bytes"

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package sorted_set package sorted_set_test
import ( import (
"bytes" "bytes"

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package str package str_test
import ( import (
"bytes" "bytes"