forked from DiceDB/dice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexists_test.go
63 lines (58 loc) · 1.89 KB
/
exists_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
58
59
60
61
62
63
package tests
import (
"testing"
"time"
"gotest.tools/v3/assert"
)
func TestExists(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()
testCases := []struct {
name string
command []string
expected []interface{}
delay []time.Duration
}{
{
name: "Test EXISTS command",
command: []string{"SET key value", "EXISTS key", "EXISTS key2"},
expected: []interface{}{"OK", int64(1), int64(0)},
delay: []time.Duration{0, 0, 0},
},
{
name: "Test EXISTS command with multiple keys",
command: []string{"SET key value", "SET key2 value2", "EXISTS key key2 key3", "EXISTS key key2 key3 key4", "DEL key", "EXISTS key key2 key3 key4"},
expected: []interface{}{"OK", "OK", int64(2), int64(2), int64(1), int64(1)},
delay: []time.Duration{0, 0, 0, 0, 0, 0},
},
{
name: "Test EXISTS an expired key",
command: []string{"SET key value ex 1", "EXISTS key", "EXISTS key"},
expected: []interface{}{"OK", int64(1), int64(0)},
delay: []time.Duration{0, 0, 2 * time.Second},
},
{
name: "Test EXISTS with multiple keys and expired key",
command: []string{"SET key value ex 2", "SET key2 value2", "SET key3 value3", "EXISTS key key2 key3", "EXISTS key key2 key3"},
expected: []interface{}{"OK", "OK", "OK", int64(3), int64(2)},
delay: []time.Duration{0, 0, 0, 0, 2 * time.Second},
},
}
for _, tcase := range testCases {
t.Run(tcase.name, func(t *testing.T) {
// deleteTestKeys([]string{"key", "key2", "key3", "key4"}, store)
fireCommand(conn, "DEL key")
fireCommand(conn, "DEL key2")
fireCommand(conn, "DEL key3")
fireCommand(conn, "DEL key4")
for i := 0; i < len(tcase.command); i++ {
if tcase.delay[i] > 0 {
time.Sleep(tcase.delay[i])
}
cmd := tcase.command[i]
out := tcase.expected[i]
assert.Equal(t, out, fireCommand(conn, cmd), "Value mismatch for cmd %s\n.", cmd)
}
})
}
}