forked from DiceDB/dice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_rename_test.go
57 lines (52 loc) · 1.61 KB
/
command_rename_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package tests
import (
"testing"
"gotest.tools/v3/assert"
)
var renameKeysTestCases = []struct {
name string
inCmd []string
expected []interface{}
}{
{
name: "Set key and Rename key",
inCmd: []string{"set sourceKey hello", "get sourceKey", "rename sourceKey destKey", "get destKey", "get sourceKey"},
expected: []interface{}{"OK", "hello", "OK", "hello", "(nil)"},
},
{
name: "same key for source and destination on Rename",
inCmd: []string{"set Key hello", "get Key", "rename Key Key", "get Key"},
expected: []interface{}{"OK", "hello", "OK", "hello"},
},
{
name: "If source key doesn't exists",
inCmd: []string{"rename unknownKey Key"},
expected: []interface{}{"ERR no such key"},
},
{
name: "If source key doesn't exists and renaming the same key to the same key",
inCmd: []string{"rename unknownKey unknownKey"},
expected: []interface{}{"ERR no such key"},
},
{
name: "If destination Key already presents",
inCmd: []string{"set destinationKey world", "set newKey hello", "rename newKey destinationKey", "get newKey", "get destinationKey"},
expected: []interface{}{"OK", "OK", "OK", "(nil)", "hello"},
},
}
func TestCommandRename(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()
for _, tc := range renameKeysTestCases {
t.Run(tc.name, func(t *testing.T) {
// deleteTestKeys([]string{"k", "k1", "k2"}, store)
fireCommand(conn, "DEL k1")
fireCommand(conn, "DEL k2")
fireCommand(conn, "DEL 3")
for i, cmd := range tc.inCmd {
result := fireCommand(conn, cmd)
assert.Equal(t, tc.expected[i], result)
}
})
}
}