-
Notifications
You must be signed in to change notification settings - Fork 1
/
commands_test.go
157 lines (149 loc) · 16.2 KB
/
commands_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package main
import (
"strings"
"testing"
"github.com/idugan100/GoKV/handlers"
)
type TableTest struct {
Commands []string
ExpectedOutput string
}
var CommandTableTests = []TableTest{
{[]string{"*1\r\n$4\r\nPING\r\n"}, "PONG"},
{[]string{"*1\r\n$6\r\nLOLWUT\r\n"}, "GoKV 0.1 :):):)"},
{[]string{"*8\r\n$4\r\nhset\r\n$6\r\nmyinfo\r\n$4\r\nname\r\n$5\r\nisaac\r\n$3\r\nage\r\n$2\r\n20\r\n$3\r\njob\r\n$3\r\nswe\r\n"}, ":3"},
{[]string{"*8\r\n$4\r\nhset\r\n$6\r\nmyinfo\r\n$4\r\nname\r\n$5\r\nisaac\r\n$3\r\nage\r\n$2\r\n20\r\n$3\r\njob\r\n$3\r\nswe\r\n", "*6\r\n$4\r\nhget\r\n$6\r\nmyinfo\r\n$4\r\nname\r\n$3\r\nage\r\n$3\r\njob\r\n$3\r\nlol\r\n"}, "isaac"},
{[]string{"*3\r\n$4\r\nhset\r\n$6\r\nmyinfo\r\n$4\r\nname\r\n"}, handlers.InvalidArgsNumberError{Command: "HSET"}.Error()},
{[]string{"*2\r\n$4\r\nhget\r\n$6\r\nmyinfo\r\n"}, handlers.InvalidArgsNumberError{Command: "HGET"}.Error()},
{[]string{"*2\r\n$7\r\nhexists\r\n$6\r\nmyinfo\r\n"}, handlers.InvalidArgsNumberError{Command: "HEXISTS"}.Error()},
{[]string{"*3\r\n$7\r\nhexists\r\n$6\r\nkey\r\n$5\r\nvalue\r\n"}, ":0"},
{[]string{"*4\r\n$4\r\nhset\r\n$6\r\nlength\r\n$3\r\nkey\r\n$3\r\nval\r\n", "*3\r\n$7\r\nhstrlen\r\n$6\r\nlength\r\n$3\r\nkey\r\n"}, ":3"},
{[]string{"*2\r\n$7\r\nhstrlen\r\n$6\r\nlength\r\n"}, handlers.InvalidArgsNumberError{Command: "HSTRLEN"}.Error()},
{[]string{"*1\r\n$4\r\nHLEN\r\n"}, handlers.InvalidArgsNumberError{Command: "HLEN"}.Error()},
{[]string{"*2\r\n$4\r\nHLEN\r\n$6\r\nmissing\r\n"}, ":0"},
{[]string{"*8\r\n$4\r\nhset\r\n$4\r\ndata\r\n$4\r\nname\r\n$5\r\nisaac\r\n$3\r\nage\r\n$2\r\n20\r\n$3\r\njob\r\n$3\r\nswe\r\n", "*2\r\n$4\r\nHLEN\r\n$4\r\ndata\r\n"}, ":3"},
{[]string{"*1\r\n$7\r\nhgetall\r\n"}, handlers.InvalidArgsNumberError{Command: "HGETALL"}.Error()},
{[]string{"*2\r\n$7\r\nhgetall\r\n$7\r\nmissing\r\n"}, "*0"},
{[]string{"*8\r\n$4\r\nhset\r\n$4\r\ndata\r\n$4\r\nname\r\n$5\r\nisaac\r\n$3\r\nage\r\n$2\r\n20\r\n$3\r\njob\r\n$3\r\nswe\r\n", "*2\r\n$7\r\nhgetall\r\n$4\r\ndata\r\n"}, "swe"},
{[]string{"*2\r\n$6\r\nHSETNX\r\n$3\r\nkey\r\n"}, handlers.InvalidArgsNumberError{Command: "HSETNX"}.Error()},
{[]string{"*8\r\n$4\r\nhset\r\n$6\r\nmyinfo\r\n$4\r\nname\r\n$5\r\nisaac\r\n$3\r\nage\r\n$2\r\n20\r\n$3\r\njob\r\n$3\r\nswe\r\n", "*4\r\n$6\r\nHSETNX\r\n$6\r\nmyinfo\r\n$4\r\nname\r\n$3\r\nbob\r\n"}, ":0"},
{[]string{"*8\r\n$4\r\nhset\r\n$6\r\nmyinfo\r\n$4\r\nname\r\n$5\r\nisaac\r\n$3\r\nage\r\n$2\r\n20\r\n$3\r\njob\r\n$3\r\nswe\r\n", "*4\r\n$6\r\nHSETNX\r\n$6\r\nmyinfo\r\n$8\r\nfavcolor\r\n$4\r\nblue\r\n"}, ":1"},
{[]string{"*2\r\n$4\r\nHDEL\r\ndata\r\n"}, handlers.InvalidArgsNumberError{Command: "HDEL"}.Error()},
{[]string{"*8\r\n$4\r\nhset\r\n$6\r\nmyinfo\r\n$4\r\nname\r\n$5\r\nisaac\r\n$3\r\nage\r\n$2\r\n20\r\n$3\r\njob\r\n$3\r\nswe\r\n", "*5\r\n$4\r\nHDEL\r\n$6\r\nmyinfo\r\n$8\r\nfavcolor\r\n$4\r\nname\r\n$3\r\nage\r\n"}, ":2"},
{[]string{"*1\r\n$3\r\n123\r\n"}, "command not found"},
{[]string{"*1\r\n$3\r\nset\r\n"}, handlers.InvalidArgsNumberError{Command: "SET"}.Error()},
{[]string{"*1\r\n$3\r\nget\r\n"}, handlers.InvalidArgsNumberError{Command: "GET"}.Error()},
{[]string{"*2\r\n$3\r\nget\r\n$3\r\nmissing\r\n"}, "$-1\r\n"},
{[]string{"*3\r\n$3\r\nset\r\n$5\r\nhello\r\n$5\r\nworld\r\n"}, "OK"},
{[]string{"*3\r\n$5\r\nsetnx\r\n$3\r\nkey\r\n$6\r\nnewval\r\n"}, ":1"},
{[]string{"*1\r\n$4\r\nINCR\r\b"}, handlers.InvalidArgsNumberError{Command: "INCR"}.Error()},
{[]string{"*2\r\n$4\r\nINCR\r\n$3\r\nnum\r\n"}, ":1"},
{[]string{"*2\r\n$4\r\nDECR\r\n$3\r\nnum\r\n"}, ":-1"},
{[]string{"*1\r\n$4\r\nDECR\r\b"}, handlers.InvalidArgsNumberError{Command: "DECR"}.Error()},
{[]string{"*1\r\n$6\r\nDECRBY\r\b"}, handlers.InvalidArgsNumberError{Command: "DECRBY"}.Error()},
{[]string{"*3\r\n$6\r\nDECRBY\r\n$3\r\nkey\r\n$3\r\nval\r\n"}, handlers.InvalidDataTypeError{Command: "DECRBY"}.Error()},
{[]string{"*3\r\n$6\r\nDECRBY\r\n$3\r\nnum\r\n$1\r\n2\r\n"}, ":-2"},
{[]string{"*3\r\n$3\r\nSET\r\n$3\r\nnum\r\n$1\r\n5\r\n", "*3\r\n$6\r\nDECRBY\r\n$3\r\nnum\r\n$1\r\n2\r\n"}, ":3"},
{[]string{"*1\r\n$6\r\nINCRBY\r\b"}, handlers.InvalidArgsNumberError{Command: "INCRBY"}.Error()},
{[]string{"*3\r\n$6\r\nINCRBY\r\n$3\r\nkey\r\n$3\r\nval\r\n"}, handlers.InvalidDataTypeError{Command: "INCRBY"}.Error()},
{[]string{"*3\r\n$6\r\nINCRBY\r\n$3\r\nnum\r\n$1\r\n2\r\n"}, ":2"},
{[]string{"*3\r\n$3\r\nSET\r\n$3\r\nnum\r\n$1\r\n5\r\n", "*3\r\n$6\r\nINCRBY\r\n$3\r\nnum\r\n$1\r\n2\r\n"}, ":7"},
{[]string{"*2\r\n$6\r\nRENAME\r\n$3\r\nkey\r\n"}, handlers.InvalidArgsNumberError{Command: "RENAME"}.Error()},
{[]string{"*3\r\n$6\r\nRENAME\r\n$3\r\nkey\r\n$6\r\nnewkey\r\n"}, "key to be renamed not found"},
{[]string{"*3\r\n$3\r\nset\r\n$5\r\nhello\r\n$5\r\nworld\r\n", "*2\r\n$3\r\nget\r\n$5\r\nhello\r\n"}, "world"},
{[]string{"*3\r\n$3\r\nSET\r\n$10\r\ndeletedkey\r\n$13\r\ndeletedvalue\r\n", "*2\r\n$3\r\nDEL\r\n$10\r\ndeletedkey\r\n"}, ":1"},
{[]string{"*2\r\n$6\r\nEXISTS\r\n$7\r\nmissing\r\n"}, ":0"},
{[]string{"*3\r\n$3\r\nset\r\n$6\r\nthekey\r\n$5\r\nfound\r\n", "*2\r\n$6\r\nexists\r\n$6\r\nthekey\r\n"}, ":1"},
{[]string{"*3\r\n$3\r\nset\r\n$6\r\nlength\r\n$4\r\nfour\r\n", "*2\r\n$6\r\nstrlen\r\n$6\r\nlength\r\n"}, ":4"},
{[]string{"*3\r\n$3\r\nset\r\n$3\r\nkey\r\n$3\r\nval\r\n", "*3\r\n$5\r\nsetnx\r\n$3\r\nkey\r\n$6\r\nnewval\r\n"}, ":0"},
{[]string{"*3\r\n$3\r\nset\r\n$3\r\nnum\r\n$1\r\n1\r\n", "*2\r\n$4\r\nINCR\r\n$3\r\nnum\r\n"}, ":2"},
{[]string{"*3\r\n$3\r\nset\r\n$3\r\nnum\r\n$3\r\none\r\n", "*2\r\n$4\r\nINCR\r\n$3\r\nnum\r\n"}, handlers.InvalidDataTypeError{Command: "INCR"}.Error()},
{[]string{"*3\r\n$3\r\nset\r\n$3\r\nnum\r\n$1\r\n1\r\n", "*2\r\n$4\r\nDECR\r\n$3\r\nnum\r\n"}, ":0"},
{[]string{"*3\r\n$3\r\nset\r\n$3\r\nnum\r\n$3\r\none\r\n", "*2\r\n$4\r\nDECR\r\n$3\r\nnum\r\n"}, handlers.InvalidDataTypeError{Command: "DECR"}.Error()},
{[]string{"*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$3\r\nval\r\n", "*3\r\n$6\r\nRENAME\r\n$3\r\nkey\r\n$6\r\nnewkey\r\n", "*2\r\n$3\r\nGET\r\n$6\r\nnewkey\r\n"}, "val"},
{[]string{"*2\r\n$5\r\nsetnx\r\n$3\r\nkey\r\n"}, handlers.InvalidArgsNumberError{Command: "SETNX"}.Error()},
{[]string{"*2\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n"}, handlers.InvalidArgsNumberError{Command: "LPUSH"}.Error()},
{[]string{"*3\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$5\r\nvalue\r\n"}, ":1"},
{[]string{"*3\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$5\r\nvalue\r\n", "*4\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$6\r\nvalue2\r\n$6\r\nvalue3\r\n"}, ":3"},
{[]string{"*4\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$2\r\nb\r\n", "*2\r\n$4\r\nLPOP\r\n$3\r\nkey\r\n"}, "b"},
{[]string{"*1\r\n$4\r\nLPOP\r\n"}, handlers.InvalidArgsNumberError{Command: "LPOP"}.Error()},
{[]string{"*2\r\n$4\r\nLPOP\r\n$3\r\nkey\r\n"}, "$-1\r\n"},
{[]string{"*4\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n", "*2\r\n$4\r\nLPOP\r\n$3\r\nkey\r\n"}, "$1\r\nb\r\n"},
{[]string{"*4\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n", "*3\r\n$4\r\nLPOP\r\n$3\r\nkey\r\n$1\r\n2\r\n"}, "*2\r\n$1\r\nb\r\n$1\r\na\r\n"},
{[]string{"*4\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n", "*3\r\n$4\r\nLPOP\r\n$3\r\nkey\r\n$1\r\n3\r\n"}, "*2\r\n$1\r\nb\r\n$1\r\na\r\n"},
{[]string{"*4\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n", "*3\r\n$4\r\nLPOP\r\n$3\r\nkey\r\n$1\r\na\r\n"}, handlers.InvalidDataTypeError{Command: "LPOP"}.Error()},
{[]string{"*4\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n", "*2\r\n$4\r\nLLEN\r\n$3\r\nkey\r\n"}, ":2"},
{[]string{"*2\r\n$4\r\nLLEN\r\n$3\r\nkey\r\n"}, ":0"},
{[]string{"*3\r\n$4\r\nLLEN\r\n$3\r\nkey\r\n$5\r\nvalue\r\n"}, handlers.InvalidArgsNumberError{Command: "LLEN"}.Error()},
{[]string{"*4\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n", "*3\r\n$4\r\nLPOP\r\n$3\r\nkey\r\n$1\r\n2\r\n"}, "*2\r\n$1\r\na\r\n$1\r\nb\r\n"},
{[]string{"*4\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n", "*3\r\n$4\r\nLPOP\r\n$3\r\nkey\r\n$1\r\n3\r\n"}, "*2\r\n$1\r\na\r\n$1\r\nb\r\n"},
{[]string{"*4\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n", "*2\r\n$4\r\nLLEN\r\n$3\r\nkey\r\n"}, ":2"},
{[]string{"*2\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n"}, handlers.InvalidArgsNumberError{Command: "RPUSH"}.Error()},
{[]string{"*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n$1\r\nc\r\n", "*2\r\n$6\r\nLINDEX\r\n$3\r\nkey\r\n"}, handlers.InvalidArgsNumberError{Command: "LINDEX"}.Error()},
{[]string{"*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n$1\r\nc\r\n", "*3\r\n$6\r\nLINDEX\r\n$3\r\nkey\r\n$1\r\n3\r\n"}, "$-1\r\n"},
{[]string{"*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n$1\r\nc\r\n", "*3\r\n$6\r\nLINDEX\r\n$3\r\nkey\r\n$2\r\n-4\r\n"}, "$-1\r\n"},
{[]string{"*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n$1\r\nc\r\n", "*3\r\n$6\r\nLINDEX\r\n$3\r\nkey\r\n$1\r\n1\r\n"}, "$1\r\nb\r\n"},
{[]string{"*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n$1\r\nc\r\n", "*3\r\n$6\r\nLINDEX\r\n$3\r\nkey\r\n$2\r\n-3\r\n"}, "$1\r\na\r\n"},
{[]string{"*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n$1\r\nc\r\n", "*3\r\n$6\r\nLINDEX\r\n$3\r\nkey\r\n$1\r\na\r\n"}, handlers.InvalidDataTypeError{Command: "LINDEX"}.Error()},
{[]string{"*3\r\n$6\r\nLINDEX\r\n$3\r\nkey\r\n$2\r\n-3\r\n"}, "key not found"},
{[]string{"*3\r\n$5\r\nLTRIM\r\n$3\r\nkey\r\n$1\r\n1\r\n"}, handlers.InvalidArgsNumberError{Command: "LTRIM"}.Error()},
{[]string{"*4\r\n$5\r\nLTRIM\r\n$3\r\nkey\r\n$1\r\n1\r\n$2\r\n-1\r\n"}, "key not found"},
{[]string{"*3\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\b$1\r\na\r\n", "*4\r\n$5\r\nLTRIM\r\n$3\r\nkey\r\n$1\r\n1\r\n$1\r\na\r\n"}, handlers.InvalidDataTypeError{Command: "LTRIM"}.Error()},
{[]string{"*3\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\b$1\r\na\r\n", "*4\r\n$5\r\nLTRIM\r\n$3\r\nkey\r\n$1\r\na\r\n$2\r\n-1\r\n"}, handlers.InvalidDataTypeError{Command: "LTRIM"}.Error()},
{[]string{"*5\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\b$1\r\nc\r\n$1\r\nb\r\n$1\r\na\r\n", "*4\r\n$5\r\nLTRIM\r\n$3\r\nkey\r\n$1\r\n1\r\n$2\r\n-1\r\n", "*3\r\n$6\r\nLINDEX\r\n$3\r\nkey\r\n$1\r\n0\r\n"}, "$1\r\nb\r\n"},
{[]string{"*5\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\b$1\r\nc\r\n$1\r\nb\r\n$1\r\na\r\n", "*4\r\n$5\r\nLTRIM\r\n$3\r\nkey\r\n$1\r\n0\r\n$2\r\n-1\r\n", "*3\r\n$6\r\nLINDEX\r\n$3\r\nkey\r\n$1\r\n0\r\n"}, "$1\r\na\r\n"},
{[]string{"*5\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\b$1\r\nc\r\n$1\r\nb\r\n$1\r\na\r\n", "*4\r\n$5\r\nLTRIM\r\n$3\r\nkey\r\n$1\r\n1\r\n$2\r\n-2\r\n", "*3\r\n$6\r\nLINDEX\r\n$3\r\nkey\r\n$1\r\n0\r\n"}, "$1\r\nb\r\n"},
{[]string{"*5\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\b$1\r\nc\r\n$1\r\nb\r\n$1\r\na\r\n", "*4\r\n$5\r\nLTRIM\r\n$3\r\nkey\r\n$1\r\n2\r\n$2\r\n-1\r\n", "*3\r\n$6\r\nLINDEX\r\n$3\r\nkey\r\n$1\r\n0\r\n"}, "$1\r\nc\r\n"},
{[]string{"*5\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\b$1\r\nc\r\n$1\r\nb\r\n$1\r\na\r\n", "*4\r\n$5\r\nLTRIM\r\n$3\r\nkey\r\n$2\r\n10\r\n$2\r\n-2\r\n", "*3\r\n$6\r\nLINDEX\r\n$3\r\nkey\r\n$1\r\n0\r\n"}, "key not found"},
{[]string{"*1\r\n$4\r\nRPOP\r\n"}, handlers.InvalidArgsNumberError{Command: "RPOP"}.Error()},
{[]string{"*2\r\n$4\r\nRPOP\r\n$3\r\nkey\r\n"}, "$-1\r\n"},
{[]string{"*4\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n", "*2\r\n$4\r\nRPOP\r\n$3\r\nkey\r\n"}, "$1\r\na\r\n"},
{[]string{"*4\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n", "*3\r\n$4\r\nRPOP\r\n$3\r\nkey\r\n$1\r\n2\r\n"}, "*2\r\n$1\r\na\r\n$1\r\nb\r\n"},
{[]string{"*4\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n", "*3\r\n$4\r\nRPOP\r\n$3\r\nkey\r\n$1\r\n3\r\n"}, "*2\r\n$1\r\na\r\n$1\r\nb\r\n"},
{[]string{"*4\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n", "*3\r\n$4\r\nRPOP\r\n$3\r\nkey\r\n$1\r\na\r\n"}, handlers.InvalidDataTypeError{Command: "RPOP"}.Error()},
{[]string{"*4\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n", "*4\r\n$6\r\nLRANGE\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\n1\r\n"}, handlers.InvalidDataTypeError{Command: "LRANGE"}.Error()},
{[]string{"*4\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n", "*4\r\n$6\r\nLRANGE\r\n$3\r\nkey\r\n$1\r\n1\r\n$1\r\na\r\n"}, handlers.InvalidDataTypeError{Command: "LRANGE"}.Error()},
{[]string{"*4\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n", "*3\r\n$6\r\nLRANGE\r\n$3\r\nkey\r\n$1\r\n1\r\n"}, handlers.InvalidArgsNumberError{Command: "LRANGE"}.Error()},
{[]string{"*4\r\n$6\r\nLRANGE\r\n$3\r\nkey\r\n$1\r\n0\r\n$1\r\n1\r\n"}, "*0\r\n"},
{[]string{"*5\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$1\r\nc\r\n$1\r\nb\r\n$1\r\na\r\n", "*4\r\n$6\r\nLRANGE\r\n$3\r\nkey\r\n$1\r\n0\r\n$2\r\n-1\r\n"}, "*3\r\n$1\r\na\r\n$1\r\nb\r\n$1\r\nc\r\n"},
{[]string{"*5\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$1\r\nc\r\n$1\r\nb\r\n$1\r\na\r\n", "*4\r\n$6\r\nLRANGE\r\n$3\r\nkey\r\n$2\r\n10\r\n$1\r\n0\r\n"}, "*0\r\n"},
{[]string{"*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n$1\r\nc\r\n", "*3\r\n$4\r\nLSET\r\n$3\r\nkey\r\n$1\r\n1\r\n"}, handlers.InvalidArgsNumberError{Command: "LSET"}.Error()},
{[]string{"*4\r\n$4\r\nLSET\r\n$3\r\nkey\r\n$1\r\n1\r\n$3\r\nval\r\n"}, "key not found"},
{[]string{"*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n$1\r\nc\r\n", "*4\r\n$4\r\nLSET\r\n$3\r\nkey\r\n$3\r\n100\r\n$3\r\nval\r\n"}, "index out of bounds"},
{[]string{"*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n$1\r\nc\r\n", "*4\r\n$4\r\nLSET\r\n$3\r\nkey\r\n$4\r\n-100\r\n$3\r\nval\r\n"}, "index out of bounds"},
{[]string{"*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n$1\r\nc\r\n", "*4\r\n$4\r\nLSET\r\n$3\r\nkey\r\n$1\r\na\r\n$3\r\nval\r\n"}, handlers.InvalidDataTypeError{Command: "LSET"}.Error()},
{[]string{"*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n$1\r\nc\r\n", "*4\r\n$4\r\nLSET\r\n$3\r\nkey\r\n$1\r\n1\r\n$3\r\nval\r\n", "*3\r\n$6\r\nLINDEX\r\n$3\r\nkey\r\n$1\r\n1\r\n"}, "val"},
{[]string{"*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n$1\r\nc\r\n", "*4\r\n$4\r\nLSET\r\n$3\r\nkey\r\n$1\r\n1\r\n$3\r\nval\r\n", "*3\r\n$6\r\nLINDEX\r\n$3\r\nkey\r\n$1\r\n1\r\n"}, "val"},
{[]string{"*3\r\n$3\r\nset\r\n$5\r\nhello\r\n$5\r\nworld\r\n", "*1\r\n$6\r\nDBSIZE\r\n"}, "1"},
{[]string{"*3\r\n$3\r\nset\r\n$5\r\nhello\r\n$5\r\nworld\r\n", "*4\r\n$4\r\nhset\r\n$6\r\nlength\r\n$3\r\nkey\r\n$3\r\nval\r\n", "*1\r\n$6\r\nDBSIZE\r\n"}, "2"},
{[]string{"*3\r\n$3\r\nset\r\n$5\r\nhello\r\n$5\r\nworld\r\n", "*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\nb\r\n$1\r\nc\r\n", "*1\r\n$6\r\nDBSIZE\r\n"}, "2"},
{[]string{"*1\r\n$4\r\nMGET\r\n"}, handlers.InvalidArgsNumberError{Command: "MGET"}.Error()},
{[]string{"*3\r\n$3\r\nset\r\n$5\r\nhello\r\n$5\r\nworld\r\n", "*3\r\n$4\r\nMGET\r\n$5\r\nhello\r\n$3\r\nkey\r\n"}, "*2\r\n$5\r\nworld\r\n$-1\r\n"},
{[]string{"*3\r\n$3\r\nset\r\n$5\r\nhello\r\n$5\r\nworld\r\n", "*1\r\n$9\r\nRANDOMKEY\r\n"}, "$5\r\nhello\r\n"},
{[]string{"*3\r\n$3\r\nset\r\n$5\r\nhello\r\n$5\r\nworld\r\n", "*3\r\n$8\r\nRENAMENX\r\n$5\r\nhello\r\n$3\r\nbye\r\n"}, "1"},
{[]string{"*3\r\n$8\r\nRENAMENX\r\n$5\r\nhello\r\n$3\r\nbye\r\n"}, "key to be renamed not found"},
{[]string{"*2\r\n$8\r\nRENAMENX\r\n$5\r\nhello\r\n"}, handlers.InvalidArgsNumberError{Command: "RENAMENX"}.Error()},
{[]string{"*3\r\n$3\r\nset\r\n$5\r\nhello\r\n$5\r\nworld\r\n", "*3\r\n$3\r\nset\r\n$3\r\nbye\r\n$5\r\nworld\r\n", "*3\r\n$8\r\nRENAMENX\r\n$5\r\nhello\r\n$3\r\nbye\r\n"}, "0"},
{[]string{"*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\na\r\n$1\r\nc\r\n", "*4\r\n$4\r\nLREM\r\n$3\r\nkey\r\n$1\r\n0\r\n$1\r\na\r\n"}, "2"},
{[]string{"*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\na\r\n$1\r\nc\r\n", "*4\r\n$4\r\nLREM\r\n$3\r\nkey\r\n$2\r\n-1\r\n$1\r\nc\r\n"}, "1"},
{[]string{"*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\na\r\n$1\r\nc\r\n", "*4\r\n$4\r\nLREM\r\n$3\r\nkey\r\n$1\r\n2\r\n$1\r\na\r\n"}, "2"},
{[]string{"*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\na\r\n$1\r\na\r\n", "*4\r\n$4\r\nLREM\r\n$3\r\nkey\r\n$1\r\n0\r\n$1\r\na\r\n", "*4\r\n$6\r\nLRANGE\r\n$3\r\nkey\r\n$1\r\n0\r\n$2\r\n-1\r\n"}, "*0"},
{[]string{"*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\na\r\n$1\r\nc\r\n", "*4\r\n$4\r\nLREM\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\na\r\n"}, handlers.InvalidDataTypeError{Command: "LREM"}.Error()},
{[]string{"*5\r\n$5\r\nRPUSH\r\n$3\r\nkey\r\n$1\r\na\r\n$1\r\na\r\n$1\r\nc\r\n", "*3\r\n$4\r\nLREM\r\n$3\r\nkey\r\n$1\r\n2\r\n$1\r\n"}, handlers.InvalidArgsNumberError{Command: "LREM"}.Error()},
}
func TestCommands(t *testing.T) {
for _, test := range CommandTableTests {
var conn ConnectionMock
for _, command := range test.Commands {
conn = GetConnectionMock(command)
HandleConnection(conn)
}
if !strings.Contains(conn.String(), test.ExpectedOutput) {
t.Errorf("expected result '%s' got response of '%s'", test.ExpectedOutput, conn.String())
for _, command := range test.Commands {
t.Log(command)
}
}
handlers.ClearData()
}
}