mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-18 22:04:41 +08:00
added test for RENAME command
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1184,3 +1184,58 @@ func TestEchoVault_DECRBY(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEchoVault_Rename(t *testing.T) {
|
||||||
|
server := createEchoVault()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
oldKey string
|
||||||
|
newKey string
|
||||||
|
presetValues map[string]internal.KeyData
|
||||||
|
want string
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "1. Rename existing key",
|
||||||
|
oldKey: "oldKey1",
|
||||||
|
newKey: "newKey1",
|
||||||
|
presetValues: map[string]internal.KeyData{"oldKey1": {Value: "value1"}},
|
||||||
|
want: "OK",
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "2. Rename non-existent key",
|
||||||
|
oldKey: "oldKey2",
|
||||||
|
newKey: "newKey2",
|
||||||
|
presetValues: nil,
|
||||||
|
want: "",
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "3. Rename to existing key",
|
||||||
|
oldKey: "oldKey3",
|
||||||
|
newKey: "newKey4",
|
||||||
|
presetValues: map[string]internal.KeyData{"oldKey3": {Value: "value3"}, "newKey4": {Value: "value4"}},
|
||||||
|
want: "OK",
|
||||||
|
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.Rename(tt.oldKey, tt.newKey)
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("Rename() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if got != tt.want {
|
||||||
|
t.Errorf("Rename() got = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user