forked from DiceDB/dice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmget_test.go
56 lines (51 loc) · 1.36 KB
/
mget_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
package tests
import (
"testing"
"github.com/dicedb/dice/testutils"
"gotest.tools/v3/assert"
)
func TestMGET(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()
testCases := []struct {
name string
commands []string
expected []interface{}
}{
{
name: "MGET With non-existing keys",
commands: []string{"MGET k1 k2"},
expected: []interface{}{[]interface{}{"(nil)", "(nil)"}},
},
{
name: "MGET With existing keys",
commands: []string{"MSET k1 v1 k2 v2", "MGET k1 k2"},
expected: []interface{}{"OK", []interface{}{"v1", "v2"}},
},
{
name: "MGET with existing and non existing keys",
commands: []string{"set k1 v1", "MGET k1 k2"},
expected: []interface{}{"OK", []interface{}{"v1", "(nil)"}},
},
{
name: "MGET without any keys",
commands: []string{"MGET"},
expected: []interface{}{"ERR wrong number of arguments for 'mget' command"},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// deleteTestKeys([]string{"k1", "k2"}, store)
fireCommand(conn, "DEL k1")
fireCommand(conn, "DEL k2")
for i, cmd := range tc.commands {
result := fireCommand(conn, cmd)
if slice, ok := tc.expected[i].([]interface{}); ok {
assert.Assert(t, testutils.UnorderedEqual(slice, result))
} else {
assert.DeepEqual(t, tc.expected[i], result)
}
}
})
}
}