mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-06 00:16:53 +08:00
feat: added DECR command support
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1239,3 +1239,67 @@ func TestEchoVault_Rename(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEchoVault_DECR(t *testing.T) {
|
||||||
|
server := createEchoVault()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
key string
|
||||||
|
presetValues map[string]internal.KeyData
|
||||||
|
want int
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "1. Decrement non-existent key",
|
||||||
|
key: "DecrKey1",
|
||||||
|
presetValues: nil,
|
||||||
|
want: 0,
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "2. Decrement existing key with integer value",
|
||||||
|
key: "DecrKey2",
|
||||||
|
presetValues: map[string]internal.KeyData{
|
||||||
|
"DecrKey2": {Value: "5"},
|
||||||
|
},
|
||||||
|
want: 4,
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "3. Decrement existing key with non-integer value",
|
||||||
|
key: "DecrKey3",
|
||||||
|
presetValues: map[string]internal.KeyData{
|
||||||
|
"DecrKey3": {Value: "not_an_int"},
|
||||||
|
},
|
||||||
|
want: 0,
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "4. Decrement existing key with int64 value",
|
||||||
|
key: "DecrKey4",
|
||||||
|
presetValues: map[string]internal.KeyData{
|
||||||
|
"DecrKey4": {Value: int64(10)},
|
||||||
|
},
|
||||||
|
want: 9,
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if tt.presetValues != nil {
|
||||||
|
for k, d := range tt.presetValues {
|
||||||
|
presetKeyData(server, context.Background(), k, d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
got, err := server.Incr(tt.key)
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("TTL() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if got != tt.want {
|
||||||
|
t.Errorf("TTL() got = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -2020,7 +2020,6 @@ func Test_Generic(t *testing.T) {
|
|||||||
t.Run("Test_HandlerDECR", func(t *testing.T) {
|
t.Run("Test_HandlerDECR", func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
conn, err := internal.GetConnection("localhost", port)
|
conn, err := internal.GetConnection("localhost", port)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
@@ -2545,6 +2544,7 @@ func Test_Generic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Connect to the server
|
// Connect to the server
|
||||||
|
|
||||||
conn, err := internal.GetConnection("localhost", port)
|
conn, err := internal.GetConnection("localhost", port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
Reference in New Issue
Block a user