added test for RENAME command

This commit is contained in:
Sahil
2024-06-25 18:56:00 +05:30
committed by Kelvin Mwinuka
parent 60bfd8011f
commit db42cf6ed8
2 changed files with 7219 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -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)
}
})
}
}