mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 08:46:56 +08:00
refactor command table
This commit is contained in:
130
list_test.go
130
list_test.go
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestPush(t *testing.T) {
|
||||
FlushAll(testDB, [][]byte{})
|
||||
execFlushAll(testDB, [][]byte{})
|
||||
size := 100
|
||||
|
||||
// rpush single
|
||||
@@ -19,17 +19,17 @@ func TestPush(t *testing.T) {
|
||||
for i := 0; i < size; i++ {
|
||||
value := utils2.RandString(10)
|
||||
values[i] = []byte(value)
|
||||
result := RPush(testDB, utils2.ToBytesList(key, value))
|
||||
result := execRPush(testDB, utils2.ToBytesList(key, value))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != int64(i+1) {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", i+1, intResult.Code))
|
||||
}
|
||||
}
|
||||
actual := LRange(testDB, utils2.ToBytesList(key, "0", "-1"))
|
||||
actual := execLRange(testDB, utils2.ToBytesList(key, "0", "-1"))
|
||||
expected := reply.MakeMultiBulkReply(values)
|
||||
if !utils.BytesEquals(actual.ToBytes(), expected.ToBytes()) {
|
||||
t.Error("push error")
|
||||
}
|
||||
Del(testDB, utils2.ToBytesList(key))
|
||||
testDB.Remove(key)
|
||||
|
||||
// rpush multi
|
||||
key = utils2.RandString(10)
|
||||
@@ -39,16 +39,16 @@ func TestPush(t *testing.T) {
|
||||
value := utils2.RandString(10)
|
||||
values[i+1] = []byte(value)
|
||||
}
|
||||
result := RPush(testDB, values)
|
||||
result := execRPush(testDB, values)
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != int64(size) {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", size, intResult.Code))
|
||||
}
|
||||
actual = LRange(testDB, utils2.ToBytesList(key, "0", "-1"))
|
||||
actual = execLRange(testDB, utils2.ToBytesList(key, "0", "-1"))
|
||||
expected = reply.MakeMultiBulkReply(values[1:])
|
||||
if !utils.BytesEquals(actual.ToBytes(), expected.ToBytes()) {
|
||||
t.Error("push error")
|
||||
}
|
||||
Del(testDB, utils2.ToBytesList(key))
|
||||
testDB.Remove(key)
|
||||
|
||||
// left push single
|
||||
key = utils2.RandString(10)
|
||||
@@ -56,17 +56,17 @@ func TestPush(t *testing.T) {
|
||||
for i := 0; i < size; i++ {
|
||||
value := utils2.RandString(10)
|
||||
values[size-i-1] = []byte(value)
|
||||
result = LPush(testDB, utils2.ToBytesList(key, value))
|
||||
result = execLPush(testDB, utils2.ToBytesList(key, value))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != int64(i+1) {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", i+1, intResult.Code))
|
||||
}
|
||||
}
|
||||
actual = LRange(testDB, utils2.ToBytesList(key, "0", "-1"))
|
||||
actual = execLRange(testDB, utils2.ToBytesList(key, "0", "-1"))
|
||||
expected = reply.MakeMultiBulkReply(values)
|
||||
if !utils.BytesEquals(actual.ToBytes(), expected.ToBytes()) {
|
||||
t.Error("push error")
|
||||
}
|
||||
Del(testDB, utils2.ToBytesList(key))
|
||||
testDB.Remove(key)
|
||||
|
||||
// left push multi
|
||||
key = utils2.RandString(10)
|
||||
@@ -78,33 +78,33 @@ func TestPush(t *testing.T) {
|
||||
values[i+1] = []byte(value)
|
||||
expectedValues[size-i-1] = []byte(value)
|
||||
}
|
||||
result = LPush(testDB, values)
|
||||
result = execLPush(testDB, values)
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != int64(size) {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", size, intResult.Code))
|
||||
}
|
||||
actual = LRange(testDB, utils2.ToBytesList(key, "0", "-1"))
|
||||
actual = execLRange(testDB, utils2.ToBytesList(key, "0", "-1"))
|
||||
expected = reply.MakeMultiBulkReply(expectedValues)
|
||||
if !utils.BytesEquals(actual.ToBytes(), expected.ToBytes()) {
|
||||
t.Error("push error")
|
||||
}
|
||||
Del(testDB, utils2.ToBytesList(key))
|
||||
testDB.Remove(key)
|
||||
}
|
||||
|
||||
func TestLRange(t *testing.T) {
|
||||
// prepare list
|
||||
FlushAll(testDB, [][]byte{})
|
||||
execFlushAll(testDB, [][]byte{})
|
||||
size := 100
|
||||
key := utils2.RandString(10)
|
||||
values := make([][]byte, size)
|
||||
for i := 0; i < size; i++ {
|
||||
value := utils2.RandString(10)
|
||||
RPush(testDB, utils2.ToBytesList(key, value))
|
||||
execRPush(testDB, utils2.ToBytesList(key, value))
|
||||
values[i] = []byte(value)
|
||||
}
|
||||
|
||||
start := "0"
|
||||
end := "9"
|
||||
actual := LRange(testDB, utils2.ToBytesList(key, start, end))
|
||||
actual := execLRange(testDB, utils2.ToBytesList(key, start, end))
|
||||
expected := reply.MakeMultiBulkReply(values[0:10])
|
||||
if !utils.BytesEquals(actual.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("range error [%s, %s]", start, end))
|
||||
@@ -112,7 +112,7 @@ func TestLRange(t *testing.T) {
|
||||
|
||||
start = "0"
|
||||
end = "200"
|
||||
actual = LRange(testDB, utils2.ToBytesList(key, start, end))
|
||||
actual = execLRange(testDB, utils2.ToBytesList(key, start, end))
|
||||
expected = reply.MakeMultiBulkReply(values)
|
||||
if !utils.BytesEquals(actual.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("range error [%s, %s]", start, end))
|
||||
@@ -120,7 +120,7 @@ func TestLRange(t *testing.T) {
|
||||
|
||||
start = "0"
|
||||
end = "-10"
|
||||
actual = LRange(testDB, utils2.ToBytesList(key, start, end))
|
||||
actual = execLRange(testDB, utils2.ToBytesList(key, start, end))
|
||||
expected = reply.MakeMultiBulkReply(values[0 : size-10+1])
|
||||
if !utils.BytesEquals(actual.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("range error [%s, %s]", start, end))
|
||||
@@ -128,7 +128,7 @@ func TestLRange(t *testing.T) {
|
||||
|
||||
start = "0"
|
||||
end = "-200"
|
||||
actual = LRange(testDB, utils2.ToBytesList(key, start, end))
|
||||
actual = execLRange(testDB, utils2.ToBytesList(key, start, end))
|
||||
expected = reply.MakeMultiBulkReply(values[0:0])
|
||||
if !utils.BytesEquals(actual.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("range error [%s, %s]", start, end))
|
||||
@@ -136,7 +136,7 @@ func TestLRange(t *testing.T) {
|
||||
|
||||
start = "-10"
|
||||
end = "-1"
|
||||
actual = LRange(testDB, utils2.ToBytesList(key, start, end))
|
||||
actual = execLRange(testDB, utils2.ToBytesList(key, start, end))
|
||||
expected = reply.MakeMultiBulkReply(values[90:])
|
||||
if !utils.BytesEquals(actual.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("range error [%s, %s]", start, end))
|
||||
@@ -145,23 +145,23 @@ func TestLRange(t *testing.T) {
|
||||
|
||||
func TestLIndex(t *testing.T) {
|
||||
// prepare list
|
||||
FlushAll(testDB, [][]byte{})
|
||||
execFlushAll(testDB, [][]byte{})
|
||||
size := 100
|
||||
key := utils2.RandString(10)
|
||||
values := make([][]byte, size)
|
||||
for i := 0; i < size; i++ {
|
||||
value := utils2.RandString(10)
|
||||
RPush(testDB, utils2.ToBytesList(key, value))
|
||||
execRPush(testDB, utils2.ToBytesList(key, value))
|
||||
values[i] = []byte(value)
|
||||
}
|
||||
|
||||
result := LLen(testDB, utils2.ToBytesList(key))
|
||||
result := execLLen(testDB, utils2.ToBytesList(key))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != int64(size) {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", size, intResult.Code))
|
||||
}
|
||||
|
||||
for i := 0; i < size; i++ {
|
||||
result = LIndex(testDB, utils2.ToBytesList(key, strconv.Itoa(i)))
|
||||
result = execLIndex(testDB, utils2.ToBytesList(key, strconv.Itoa(i)))
|
||||
expected := reply.MakeBulkReply(values[i])
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
@@ -169,7 +169,7 @@ func TestLIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
for i := 1; i <= size; i++ {
|
||||
result = LIndex(testDB, utils2.ToBytesList(key, strconv.Itoa(-i)))
|
||||
result = execLIndex(testDB, utils2.ToBytesList(key, strconv.Itoa(-i)))
|
||||
expected := reply.MakeBulkReply(values[size-i])
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
@@ -179,55 +179,55 @@ func TestLIndex(t *testing.T) {
|
||||
|
||||
func TestLRem(t *testing.T) {
|
||||
// prepare list
|
||||
FlushAll(testDB, [][]byte{})
|
||||
execFlushAll(testDB, [][]byte{})
|
||||
key := utils2.RandString(10)
|
||||
values := []string{key, "a", "b", "a", "a", "c", "a", "a"}
|
||||
RPush(testDB, utils2.ToBytesList(values...))
|
||||
execRPush(testDB, utils2.ToBytesList(values...))
|
||||
|
||||
result := LRem(testDB, utils2.ToBytesList(key, "1", "a"))
|
||||
result := execLRem(testDB, utils2.ToBytesList(key, "1", "a"))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != 1 {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", 1, intResult.Code))
|
||||
}
|
||||
result = LLen(testDB, utils2.ToBytesList(key))
|
||||
result = execLLen(testDB, utils2.ToBytesList(key))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != 6 {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", 6, intResult.Code))
|
||||
}
|
||||
|
||||
result = LRem(testDB, utils2.ToBytesList(key, "-2", "a"))
|
||||
result = execLRem(testDB, utils2.ToBytesList(key, "-2", "a"))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != 2 {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", 2, intResult.Code))
|
||||
}
|
||||
result = LLen(testDB, utils2.ToBytesList(key))
|
||||
result = execLLen(testDB, utils2.ToBytesList(key))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != 4 {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", 4, intResult.Code))
|
||||
}
|
||||
|
||||
result = LRem(testDB, utils2.ToBytesList(key, "0", "a"))
|
||||
result = execLRem(testDB, utils2.ToBytesList(key, "0", "a"))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != 2 {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", 2, intResult.Code))
|
||||
}
|
||||
result = LLen(testDB, utils2.ToBytesList(key))
|
||||
result = execLLen(testDB, utils2.ToBytesList(key))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != 2 {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", 2, intResult.Code))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLSet(t *testing.T) {
|
||||
FlushAll(testDB, [][]byte{})
|
||||
execFlushAll(testDB, [][]byte{})
|
||||
key := utils2.RandString(10)
|
||||
values := []string{key, "a", "b", "c", "d", "e", "f"}
|
||||
RPush(testDB, utils2.ToBytesList(values...))
|
||||
execRPush(testDB, utils2.ToBytesList(values...))
|
||||
|
||||
// test positive index
|
||||
size := len(values) - 1
|
||||
for i := 0; i < size; i++ {
|
||||
indexStr := strconv.Itoa(i)
|
||||
value := utils2.RandString(10)
|
||||
result := LSet(testDB, utils2.ToBytesList(key, indexStr, value))
|
||||
result := execLSet(testDB, utils2.ToBytesList(key, indexStr, value))
|
||||
if _, ok := result.(*reply.OkReply); !ok {
|
||||
t.Error(fmt.Sprintf("expected OK, actually %s", string(result.ToBytes())))
|
||||
}
|
||||
result = LIndex(testDB, utils2.ToBytesList(key, indexStr))
|
||||
result = execLIndex(testDB, utils2.ToBytesList(key, indexStr))
|
||||
expected := reply.MakeBulkReply([]byte(value))
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
@@ -236,11 +236,11 @@ func TestLSet(t *testing.T) {
|
||||
// test negative index
|
||||
for i := 1; i <= size; i++ {
|
||||
value := utils2.RandString(10)
|
||||
result := LSet(testDB, utils2.ToBytesList(key, strconv.Itoa(-i), value))
|
||||
result := execLSet(testDB, utils2.ToBytesList(key, strconv.Itoa(-i), value))
|
||||
if _, ok := result.(*reply.OkReply); !ok {
|
||||
t.Error(fmt.Sprintf("expected OK, actually %s", string(result.ToBytes())))
|
||||
}
|
||||
result = LIndex(testDB, utils2.ToBytesList(key, strconv.Itoa(len(values)-i-1)))
|
||||
result = execLIndex(testDB, utils2.ToBytesList(key, strconv.Itoa(len(values)-i-1)))
|
||||
expected := reply.MakeBulkReply([]byte(value))
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
@@ -249,16 +249,16 @@ func TestLSet(t *testing.T) {
|
||||
|
||||
// test illegal index
|
||||
value := utils2.RandString(10)
|
||||
result := LSet(testDB, utils2.ToBytesList(key, strconv.Itoa(-len(values)-1), value))
|
||||
result := execLSet(testDB, utils2.ToBytesList(key, strconv.Itoa(-len(values)-1), value))
|
||||
expected := reply.MakeErrReply("ERR index out of range")
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
result = LSet(testDB, utils2.ToBytesList(key, strconv.Itoa(len(values)), value))
|
||||
result = execLSet(testDB, utils2.ToBytesList(key, strconv.Itoa(len(values)), value))
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
result = LSet(testDB, utils2.ToBytesList(key, "a", value))
|
||||
result = execLSet(testDB, utils2.ToBytesList(key, "a", value))
|
||||
expected = reply.MakeErrReply("ERR value is not an integer or out of range")
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
@@ -266,20 +266,20 @@ func TestLSet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLPop(t *testing.T) {
|
||||
FlushAll(testDB, [][]byte{})
|
||||
execFlushAll(testDB, [][]byte{})
|
||||
key := utils2.RandString(10)
|
||||
values := []string{key, "a", "b", "c", "d", "e", "f"}
|
||||
RPush(testDB, utils2.ToBytesList(values...))
|
||||
execRPush(testDB, utils2.ToBytesList(values...))
|
||||
size := len(values) - 1
|
||||
|
||||
for i := 0; i < size; i++ {
|
||||
result := LPop(testDB, utils2.ToBytesList(key))
|
||||
result := execLPop(testDB, utils2.ToBytesList(key))
|
||||
expected := reply.MakeBulkReply([]byte(values[i+1]))
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
}
|
||||
result := RPop(testDB, utils2.ToBytesList(key))
|
||||
result := execRPop(testDB, utils2.ToBytesList(key))
|
||||
expected := &reply.NullBulkReply{}
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
@@ -287,20 +287,20 @@ func TestLPop(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRPop(t *testing.T) {
|
||||
FlushAll(testDB, [][]byte{})
|
||||
execFlushAll(testDB, [][]byte{})
|
||||
key := utils2.RandString(10)
|
||||
values := []string{key, "a", "b", "c", "d", "e", "f"}
|
||||
RPush(testDB, utils2.ToBytesList(values...))
|
||||
execRPush(testDB, utils2.ToBytesList(values...))
|
||||
size := len(values) - 1
|
||||
|
||||
for i := 0; i < size; i++ {
|
||||
result := RPop(testDB, utils2.ToBytesList(key))
|
||||
result := execRPop(testDB, utils2.ToBytesList(key))
|
||||
expected := reply.MakeBulkReply([]byte(values[len(values)-i-1]))
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
}
|
||||
result := RPop(testDB, utils2.ToBytesList(key))
|
||||
result := execRPop(testDB, utils2.ToBytesList(key))
|
||||
expected := &reply.NullBulkReply{}
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
@@ -308,25 +308,25 @@ func TestRPop(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRPopLPush(t *testing.T) {
|
||||
FlushAll(testDB, [][]byte{})
|
||||
execFlushAll(testDB, [][]byte{})
|
||||
key1 := utils2.RandString(10)
|
||||
key2 := utils2.RandString(10)
|
||||
values := []string{key1, "a", "b", "c", "d", "e", "f"}
|
||||
RPush(testDB, utils2.ToBytesList(values...))
|
||||
execRPush(testDB, utils2.ToBytesList(values...))
|
||||
size := len(values) - 1
|
||||
|
||||
for i := 0; i < size; i++ {
|
||||
result := RPopLPush(testDB, utils2.ToBytesList(key1, key2))
|
||||
result := execRPopLPush(testDB, utils2.ToBytesList(key1, key2))
|
||||
expected := reply.MakeBulkReply([]byte(values[len(values)-i-1]))
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
result = LIndex(testDB, utils2.ToBytesList(key2, "0"))
|
||||
result = execLIndex(testDB, utils2.ToBytesList(key2, "0"))
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
}
|
||||
result := RPop(testDB, utils2.ToBytesList(key1))
|
||||
result := execRPop(testDB, utils2.ToBytesList(key1))
|
||||
expected := &reply.NullBulkReply{}
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
@@ -334,23 +334,23 @@ func TestRPopLPush(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRPushX(t *testing.T) {
|
||||
FlushAll(testDB, [][]byte{})
|
||||
execFlushAll(testDB, [][]byte{})
|
||||
key := utils2.RandString(10)
|
||||
result := RPushX(testDB, utils2.ToBytesList(key, "1"))
|
||||
result := execRPushX(testDB, utils2.ToBytesList(key, "1"))
|
||||
expected := reply.MakeIntReply(int64(0))
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
|
||||
RPush(testDB, utils2.ToBytesList(key, "1"))
|
||||
execRPush(testDB, utils2.ToBytesList(key, "1"))
|
||||
for i := 0; i < 10; i++ {
|
||||
value := utils2.RandString(10)
|
||||
result := RPushX(testDB, utils2.ToBytesList(key, value))
|
||||
result := execRPushX(testDB, utils2.ToBytesList(key, value))
|
||||
expected := reply.MakeIntReply(int64(i + 2))
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
result = LIndex(testDB, utils2.ToBytesList(key, "-1"))
|
||||
result = execLIndex(testDB, utils2.ToBytesList(key, "-1"))
|
||||
expected2 := reply.MakeBulkReply([]byte(value))
|
||||
if !utils.BytesEquals(result.ToBytes(), expected2.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected2.ToBytes()), string(result.ToBytes())))
|
||||
@@ -359,23 +359,23 @@ func TestRPushX(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLPushX(t *testing.T) {
|
||||
FlushAll(testDB, [][]byte{})
|
||||
execFlushAll(testDB, [][]byte{})
|
||||
key := utils2.RandString(10)
|
||||
result := RPushX(testDB, utils2.ToBytesList(key, "1"))
|
||||
result := execRPushX(testDB, utils2.ToBytesList(key, "1"))
|
||||
expected := reply.MakeIntReply(int64(0))
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
|
||||
LPush(testDB, utils2.ToBytesList(key, "1"))
|
||||
execLPush(testDB, utils2.ToBytesList(key, "1"))
|
||||
for i := 0; i < 10; i++ {
|
||||
value := utils2.RandString(10)
|
||||
result := LPushX(testDB, utils2.ToBytesList(key, value))
|
||||
result := execLPushX(testDB, utils2.ToBytesList(key, value))
|
||||
expected := reply.MakeIntReply(int64(i + 2))
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
result = LIndex(testDB, utils2.ToBytesList(key, "0"))
|
||||
result = execLIndex(testDB, utils2.ToBytesList(key, "0"))
|
||||
expected2 := reply.MakeBulkReply([]byte(value))
|
||||
if !utils.BytesEquals(result.ToBytes(), expected2.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected2.ToBytes()), string(result.ToBytes())))
|
||||
|
Reference in New Issue
Block a user