forked from DiceDB/dice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtouch_test.go
62 lines (57 loc) · 1.73 KB
/
touch_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
package tests
import (
"testing"
"time"
"gotest.tools/v3/assert"
)
func TestTouch(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()
testCases := []struct {
name string
commands []string
expected []interface{}
assert_type []string
delay []time.Duration
}{
{
name: "Touch Simple Value",
commands: []string{"SET foo bar", "OBJECT IDLETIME foo", "TOUCH foo", "OBJECT IDLETIME foo"},
expected: []interface{}{"OK", int64(2), int64(1), int64(0)},
assert_type: []string{"equal", "assert", "equal", "assert"},
delay: []time.Duration{0, 2 * time.Second, 0, 0},
},
{
name: "Touch Multiple Existing Keys",
commands: []string{"SET foo bar", "SET foo1 bar", "TOUCH foo foo1"},
expected: []interface{}{"OK", "OK", int64(2)},
assert_type: []string{"equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0},
},
{
name: "Touch Multiple Existing and Non-Existing Keys",
commands: []string{"SET foo bar", "TOUCH foo foo1"},
expected: []interface{}{"OK", int64(1)},
assert_type: []string{"equal", "equal"},
delay: []time.Duration{0, 0},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// deleteTestKeys([]string{"foo", "foo1"}, store)
fireCommand(conn, "DEL foo")
fireCommand(conn, "DEL foo1")
for i, cmd := range tc.commands {
if tc.delay[i] != 0 {
time.Sleep(tc.delay[i])
}
result := fireCommand(conn, cmd)
if tc.assert_type[i] == "equal" {
assert.DeepEqual(t, tc.expected[i], result)
} else {
assert.Assert(t, result.(int64) >= tc.expected[i].(int64), "Expected %v to be less than or equal to %v", result, tc.expected[i])
}
}
})
}
}