forked from DiceDB/dice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_type_test.go
103 lines (98 loc) · 3.52 KB
/
check_type_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package tests
import (
"testing"
"time"
"gotest.tools/v3/assert"
)
// this file may contain test cases for checking error messages accross all commands
func TestErrorsForSetData(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()
setErrorMsg := "WRONGTYPE Operation against a key holding the wrong kind of value"
testCases := []struct {
name string
cmd []string
expected []interface{}
assert_type []string
delay []time.Duration
}{
{
name: "GET a key holding a set",
cmd: []string{"SADD foo bar", "GET foo"},
expected: []interface{}{int64(1), setErrorMsg},
assert_type: []string{"equal", "equal"},
delay: []time.Duration{0, 0},
},
{
name: "GETDEL a key holding a set",
cmd: []string{"SADD foo bar", "GETDEL foo"},
expected: []interface{}{int64(1), setErrorMsg},
assert_type: []string{"equal", "equal"},
delay: []time.Duration{0, 0},
},
{
name: "INCR a key holding a set",
cmd: []string{"SADD foo bar", "INCR foo"},
expected: []interface{}{int64(1), setErrorMsg},
assert_type: []string{"equal", "equal"},
delay: []time.Duration{0, 0},
},
{
name: "DECR a key holding a set",
cmd: []string{"SADD foo bar", "DECR foo"},
expected: []interface{}{int64(1), setErrorMsg},
assert_type: []string{"equal", "equal"},
delay: []time.Duration{0, 0},
},
{
name: "STACKINT{OP} a key holding a set",
cmd: []string{"SADD foo bar", "STACKINTPUSH foo 1", "STACKINTPOP foo", "STACKINTLEN foo", "STACKINTPEEK foo", "STACKREFPUSH foo 1", "STACKREFPOP foo", "STACKREFLEN foo", "STACKREFPEEK foo"},
expected: []interface{}{int64(1), setErrorMsg, setErrorMsg, setErrorMsg, setErrorMsg, setErrorMsg, setErrorMsg, setErrorMsg, setErrorMsg},
assert_type: []string{"equal", "equal", "equal", "equal", "equal", "equal", "equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0, 0, 0, 0, 0, 0, 0},
},
{
name: "BIT operations on a key holding a set",
cmd: []string{"SADD foo bar", "GETBIT foo 1", "BITCOUNT foo"},
expected: []interface{}{int64(1), setErrorMsg, setErrorMsg},
assert_type: []string{"equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0},
},
{
name: "GETEX a key holding a set",
cmd: []string{"SADD foo bar", "GETEX foo"},
expected: []interface{}{int64(1), setErrorMsg},
assert_type: []string{"equal", "equal"},
delay: []time.Duration{0, 0},
},
{
name: "GETSET a key holding a set",
cmd: []string{"SADD foo bar", "GETSET foo bar"},
expected: []interface{}{int64(1), setErrorMsg},
assert_type: []string{"equal", "equal"},
delay: []time.Duration{0, 0},
},
{
name: "LPUSH, LPOP, RPUSH, RPOP a key holding a set",
cmd: []string{"SADD foo bar", "LPUSH foo bar", "LPOP foo", "RPUSH foo bar", "RPOP foo"},
expected: []interface{}{int64(1), setErrorMsg, setErrorMsg, setErrorMsg, setErrorMsg},
assert_type: []string{"equal", "equal", "equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0, 0, 0},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// Delete the key before running the test
fireCommand(conn, "DEL foo")
for i, cmd := range tc.cmd {
if tc.delay[i] > 0 {
time.Sleep(tc.delay[i])
}
res := fireCommand(conn, cmd)
if tc.assert_type[i] == "equal" {
assert.Equal(t, res, tc.expected[i])
}
}
})
}
}