mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-21 15:59:26 +08:00
rename godis/redis/reply to godis/redis/protocol
This commit is contained in:
@@ -3,8 +3,8 @@ package database
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hdt3213/godis/lib/utils"
|
||||
"github.com/hdt3213/godis/redis/reply"
|
||||
"github.com/hdt3213/godis/redis/reply/asserts"
|
||||
"github.com/hdt3213/godis/redis/protocol"
|
||||
"github.com/hdt3213/godis/redis/protocol/asserts"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
@@ -20,12 +20,12 @@ func TestPush(t *testing.T) {
|
||||
value := utils.RandString(10)
|
||||
values[i] = []byte(value)
|
||||
result := testDB.Exec(nil, utils.ToCmdLine("rpush", key, value))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != int64(i+1) {
|
||||
if intResult, _ := result.(*protocol.IntReply); intResult.Code != int64(i+1) {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", i+1, intResult.Code))
|
||||
}
|
||||
}
|
||||
actual := testDB.Exec(nil, utils.ToCmdLine("lrange", key, "0", "-1"))
|
||||
expected := reply.MakeMultiBulkReply(values)
|
||||
expected := protocol.MakeMultiBulkReply(values)
|
||||
if !utils.BytesEquals(actual.ToBytes(), expected.ToBytes()) {
|
||||
t.Error("push error")
|
||||
}
|
||||
@@ -42,11 +42,11 @@ func TestPush(t *testing.T) {
|
||||
args[i+1] = value
|
||||
}
|
||||
result := testDB.Exec(nil, utils.ToCmdLine2("rpush", args...))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != int64(size) {
|
||||
if intResult, _ := result.(*protocol.IntReply); intResult.Code != int64(size) {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", size, intResult.Code))
|
||||
}
|
||||
actual = testDB.Exec(nil, utils.ToCmdLine("lrange", key, "0", "-1"))
|
||||
expected = reply.MakeMultiBulkReply(values)
|
||||
expected = protocol.MakeMultiBulkReply(values)
|
||||
if !utils.BytesEquals(actual.ToBytes(), expected.ToBytes()) {
|
||||
t.Error("push error")
|
||||
}
|
||||
@@ -59,12 +59,12 @@ func TestPush(t *testing.T) {
|
||||
value := utils.RandString(10)
|
||||
values[size-i-1] = []byte(value)
|
||||
result = testDB.Exec(nil, utils.ToCmdLine("lpush", key, value))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != int64(i+1) {
|
||||
if intResult, _ := result.(*protocol.IntReply); intResult.Code != int64(i+1) {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", i+1, intResult.Code))
|
||||
}
|
||||
}
|
||||
actual = testDB.Exec(nil, utils.ToCmdLine("lrange", key, "0", "-1"))
|
||||
expected = reply.MakeMultiBulkReply(values)
|
||||
expected = protocol.MakeMultiBulkReply(values)
|
||||
if !utils.BytesEquals(actual.ToBytes(), expected.ToBytes()) {
|
||||
t.Error("push error")
|
||||
}
|
||||
@@ -82,11 +82,11 @@ func TestPush(t *testing.T) {
|
||||
}
|
||||
result = execLPush(testDB, values)
|
||||
result = testDB.Exec(nil, utils.ToCmdLine2("lpush", args...))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != int64(size) {
|
||||
if intResult, _ := result.(*protocol.IntReply); intResult.Code != int64(size) {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", size, intResult.Code))
|
||||
}
|
||||
actual = testDB.Exec(nil, utils.ToCmdLine("lrange", key, "0", "-1"))
|
||||
expected = reply.MakeMultiBulkReply(expectedValues)
|
||||
expected = protocol.MakeMultiBulkReply(expectedValues)
|
||||
if !utils.BytesEquals(actual.ToBytes(), expected.ToBytes()) {
|
||||
t.Error("push error")
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func TestLRange(t *testing.T) {
|
||||
start := "0"
|
||||
end := "9"
|
||||
actual := testDB.Exec(nil, utils.ToCmdLine("lrange", key, start, end))
|
||||
expected := reply.MakeMultiBulkReply(values[0:10])
|
||||
expected := protocol.MakeMultiBulkReply(values[0:10])
|
||||
if !utils.BytesEquals(actual.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("range error [%s, %s]", start, end))
|
||||
}
|
||||
@@ -116,7 +116,7 @@ func TestLRange(t *testing.T) {
|
||||
start = "0"
|
||||
end = "200"
|
||||
actual = testDB.Exec(nil, utils.ToCmdLine("lrange", key, start, end))
|
||||
expected = reply.MakeMultiBulkReply(values)
|
||||
expected = protocol.MakeMultiBulkReply(values)
|
||||
if !utils.BytesEquals(actual.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("range error [%s, %s]", start, end))
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func TestLRange(t *testing.T) {
|
||||
start = "0"
|
||||
end = "-10"
|
||||
actual = testDB.Exec(nil, utils.ToCmdLine("lrange", key, start, end))
|
||||
expected = reply.MakeMultiBulkReply(values[0 : size-10+1])
|
||||
expected = protocol.MakeMultiBulkReply(values[0 : size-10+1])
|
||||
if !utils.BytesEquals(actual.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("range error [%s, %s]", start, end))
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func TestLRange(t *testing.T) {
|
||||
start = "0"
|
||||
end = "-200"
|
||||
actual = testDB.Exec(nil, utils.ToCmdLine("lrange", key, start, end))
|
||||
expected = reply.MakeMultiBulkReply(values[0:0])
|
||||
expected = protocol.MakeMultiBulkReply(values[0:0])
|
||||
if !utils.BytesEquals(actual.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("range error [%s, %s]", start, end))
|
||||
}
|
||||
@@ -140,7 +140,7 @@ func TestLRange(t *testing.T) {
|
||||
start = "-10"
|
||||
end = "-1"
|
||||
actual = testDB.Exec(nil, utils.ToCmdLine("lrange", key, start, end))
|
||||
expected = reply.MakeMultiBulkReply(values[90:])
|
||||
expected = protocol.MakeMultiBulkReply(values[90:])
|
||||
if !utils.BytesEquals(actual.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("range error [%s, %s]", start, end))
|
||||
}
|
||||
@@ -159,13 +159,13 @@ func TestLIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
result := testDB.Exec(nil, utils.ToCmdLine("llen", key))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != int64(size) {
|
||||
if intResult, _ := result.(*protocol.IntReply); intResult.Code != int64(size) {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", size, intResult.Code))
|
||||
}
|
||||
|
||||
for i := 0; i < size; i++ {
|
||||
result = testDB.Exec(nil, utils.ToCmdLine("lindex", key, strconv.Itoa(i)))
|
||||
expected := reply.MakeBulkReply(values[i])
|
||||
expected := protocol.MakeBulkReply(values[i])
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
@@ -173,7 +173,7 @@ func TestLIndex(t *testing.T) {
|
||||
|
||||
for i := 1; i <= size; i++ {
|
||||
result = testDB.Exec(nil, utils.ToCmdLine("lindex", key, strconv.Itoa(-i)))
|
||||
expected := reply.MakeBulkReply(values[size-i])
|
||||
expected := protocol.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())))
|
||||
}
|
||||
@@ -188,29 +188,29 @@ func TestLRem(t *testing.T) {
|
||||
testDB.Exec(nil, utils.ToCmdLine2("rpush", values...))
|
||||
|
||||
result := testDB.Exec(nil, utils.ToCmdLine("lrem", key, "1", "a"))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != 1 {
|
||||
if intResult, _ := result.(*protocol.IntReply); intResult.Code != 1 {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", 1, intResult.Code))
|
||||
}
|
||||
result = testDB.Exec(nil, utils.ToCmdLine("llen", key))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != 6 {
|
||||
if intResult, _ := result.(*protocol.IntReply); intResult.Code != 6 {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", 6, intResult.Code))
|
||||
}
|
||||
|
||||
result = testDB.Exec(nil, utils.ToCmdLine("lrem", key, "-2", "a"))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != 2 {
|
||||
if intResult, _ := result.(*protocol.IntReply); intResult.Code != 2 {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", 2, intResult.Code))
|
||||
}
|
||||
result = testDB.Exec(nil, utils.ToCmdLine("llen", key))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != 4 {
|
||||
if intResult, _ := result.(*protocol.IntReply); intResult.Code != 4 {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", 4, intResult.Code))
|
||||
}
|
||||
|
||||
result = testDB.Exec(nil, utils.ToCmdLine("lrem", key, "0", "a"))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != 2 {
|
||||
if intResult, _ := result.(*protocol.IntReply); intResult.Code != 2 {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", 2, intResult.Code))
|
||||
}
|
||||
result = testDB.Exec(nil, utils.ToCmdLine("llen", key))
|
||||
if intResult, _ := result.(*reply.IntReply); intResult.Code != 2 {
|
||||
if intResult, _ := result.(*protocol.IntReply); intResult.Code != 2 {
|
||||
t.Error(fmt.Sprintf("expected %d, actually %d", 2, intResult.Code))
|
||||
}
|
||||
}
|
||||
@@ -227,11 +227,11 @@ func TestLSet(t *testing.T) {
|
||||
indexStr := strconv.Itoa(i)
|
||||
value := utils.RandString(10)
|
||||
result := testDB.Exec(nil, utils.ToCmdLine("lset", key, indexStr, value))
|
||||
if _, ok := result.(*reply.OkReply); !ok {
|
||||
if _, ok := result.(*protocol.OkReply); !ok {
|
||||
t.Error(fmt.Sprintf("expected OK, actually %s", string(result.ToBytes())))
|
||||
}
|
||||
result = testDB.Exec(nil, utils.ToCmdLine("lindex", key, indexStr))
|
||||
expected := reply.MakeBulkReply([]byte(value))
|
||||
expected := protocol.MakeBulkReply([]byte(value))
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
@@ -240,11 +240,11 @@ func TestLSet(t *testing.T) {
|
||||
for i := 1; i <= size; i++ {
|
||||
value := utils.RandString(10)
|
||||
result := testDB.Exec(nil, utils.ToCmdLine("lset", key, strconv.Itoa(-i), value))
|
||||
if _, ok := result.(*reply.OkReply); !ok {
|
||||
if _, ok := result.(*protocol.OkReply); !ok {
|
||||
t.Error(fmt.Sprintf("expected OK, actually %s", string(result.ToBytes())))
|
||||
}
|
||||
result = testDB.Exec(nil, utils.ToCmdLine("lindex", key, strconv.Itoa(len(values)-i-1)))
|
||||
expected := reply.MakeBulkReply([]byte(value))
|
||||
expected := protocol.MakeBulkReply([]byte(value))
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
@@ -253,7 +253,7 @@ func TestLSet(t *testing.T) {
|
||||
// test illegal index
|
||||
value := utils.RandString(10)
|
||||
result := testDB.Exec(nil, utils.ToCmdLine("lset", key, strconv.Itoa(-len(values)-1), value))
|
||||
expected := reply.MakeErrReply("ERR index out of range")
|
||||
expected := protocol.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())))
|
||||
}
|
||||
@@ -262,7 +262,7 @@ func TestLSet(t *testing.T) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
result = testDB.Exec(nil, utils.ToCmdLine("lset", key, "a", value))
|
||||
expected = reply.MakeErrReply("ERR value is not an integer or out of range")
|
||||
expected = protocol.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())))
|
||||
}
|
||||
@@ -277,13 +277,13 @@ func TestLPop(t *testing.T) {
|
||||
|
||||
for i := 0; i < size; i++ {
|
||||
result := testDB.Exec(nil, utils.ToCmdLine("lpop", key))
|
||||
expected := reply.MakeBulkReply([]byte(values[i+1]))
|
||||
expected := protocol.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 := testDB.Exec(nil, utils.ToCmdLine("rpop", key))
|
||||
expected := &reply.NullBulkReply{}
|
||||
expected := &protocol.NullBulkReply{}
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
@@ -298,13 +298,13 @@ func TestRPop(t *testing.T) {
|
||||
|
||||
for i := 0; i < size; i++ {
|
||||
result := testDB.Exec(nil, utils.ToCmdLine("rpop", key))
|
||||
expected := reply.MakeBulkReply([]byte(values[len(values)-i-1]))
|
||||
expected := protocol.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 := testDB.Exec(nil, utils.ToCmdLine("rpop", key))
|
||||
expected := &reply.NullBulkReply{}
|
||||
expected := &protocol.NullBulkReply{}
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
@@ -320,7 +320,7 @@ func TestRPopLPush(t *testing.T) {
|
||||
|
||||
for i := 0; i < size; i++ {
|
||||
result := testDB.Exec(nil, utils.ToCmdLine("rpoplpush", key1, key2))
|
||||
expected := reply.MakeBulkReply([]byte(values[len(values)-i-1]))
|
||||
expected := protocol.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())))
|
||||
}
|
||||
@@ -330,7 +330,7 @@ func TestRPopLPush(t *testing.T) {
|
||||
}
|
||||
}
|
||||
result := testDB.Exec(nil, utils.ToCmdLine("rpop", key1))
|
||||
expected := &reply.NullBulkReply{}
|
||||
expected := &protocol.NullBulkReply{}
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
@@ -340,7 +340,7 @@ func TestRPushX(t *testing.T) {
|
||||
testDB.Flush()
|
||||
key := utils.RandString(10)
|
||||
result := testDB.Exec(nil, utils.ToCmdLine("rpushx", key, "1"))
|
||||
expected := reply.MakeIntReply(int64(0))
|
||||
expected := protocol.MakeIntReply(int64(0))
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
@@ -349,12 +349,12 @@ func TestRPushX(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
value := utils.RandString(10)
|
||||
result = testDB.Exec(nil, utils.ToCmdLine("rpushx", key, value))
|
||||
expected := reply.MakeIntReply(int64(i + 2))
|
||||
expected := protocol.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 = testDB.Exec(nil, utils.ToCmdLine("lindex", key, "-1"))
|
||||
expected2 := reply.MakeBulkReply([]byte(value))
|
||||
expected2 := protocol.MakeBulkReply([]byte(value))
|
||||
if !utils.BytesEquals(result.ToBytes(), expected2.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected2.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
@@ -365,7 +365,7 @@ func TestLPushX(t *testing.T) {
|
||||
testDB.Flush()
|
||||
key := utils.RandString(10)
|
||||
result := testDB.Exec(nil, utils.ToCmdLine("rpushx", key, "1"))
|
||||
expected := reply.MakeIntReply(int64(0))
|
||||
expected := protocol.MakeIntReply(int64(0))
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Error(fmt.Sprintf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes())))
|
||||
}
|
||||
@@ -374,12 +374,12 @@ func TestLPushX(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
value := utils.RandString(10)
|
||||
result = testDB.Exec(nil, utils.ToCmdLine("lpushx", key, value))
|
||||
expected := reply.MakeIntReply(int64(i + 2))
|
||||
expected := protocol.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 = testDB.Exec(nil, utils.ToCmdLine("lindex", key, "0"))
|
||||
expected2 := reply.MakeBulkReply([]byte(value))
|
||||
expected2 := protocol.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