mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-07 01:32:56 +08:00
added strlen and append commands
This commit is contained in:
@@ -315,3 +315,60 @@ func TestMSetNX(t *testing.T) {
|
||||
result = testDB.Exec(nil, utils.ToCmdLine2("MSETNX", args[0:4]...))
|
||||
asserts.AssertIntReply(t, result, 0)
|
||||
}
|
||||
|
||||
func TestStrLen(t *testing.T) {
|
||||
testDB.Flush()
|
||||
key := utils.RandString(10)
|
||||
testDB.Exec(nil, utils.ToCmdLine2("SET", key, key))
|
||||
|
||||
actual := testDB.Exec(nil, utils.ToCmdLine("StrLen", key))
|
||||
len, ok := actual.(*reply.IntReply)
|
||||
if !ok {
|
||||
t.Errorf("expect int bulk reply, get: %s", string(actual.ToBytes()))
|
||||
return
|
||||
}
|
||||
asserts.AssertIntReply(t, len, 10)
|
||||
}
|
||||
|
||||
func TestStrLen_KeyNotExist(t *testing.T) {
|
||||
testDB.Flush()
|
||||
key := utils.RandString(10)
|
||||
|
||||
actual := testDB.Exec(nil, utils.ToCmdLine("StrLen", key))
|
||||
result, ok := actual.(*reply.IntReply)
|
||||
if !ok {
|
||||
t.Errorf("expect null bulk reply, get: %s", string(actual.ToBytes()))
|
||||
return
|
||||
}
|
||||
|
||||
asserts.AssertIntReply(t, result, 0)
|
||||
}
|
||||
|
||||
func TestAppend_KeyExist(t *testing.T) {
|
||||
testDB.Flush()
|
||||
key := utils.RandString(10)
|
||||
key2 := utils.RandString(10)
|
||||
testDB.Exec(nil, utils.ToCmdLine2("SET", key, key))
|
||||
|
||||
actual := testDB.Exec(nil, utils.ToCmdLine("Append", key, key2))
|
||||
val, ok := actual.(*reply.IntReply)
|
||||
if !ok {
|
||||
t.Errorf("expect nil bulk reply, get: %s", string(actual.ToBytes()))
|
||||
return
|
||||
}
|
||||
asserts.AssertIntReply(t, val, len(key)*2)
|
||||
}
|
||||
|
||||
func TestAppend_KeyNotExist(t *testing.T) {
|
||||
testDB.Flush()
|
||||
key := utils.RandString(10)
|
||||
|
||||
actual := testDB.Exec(nil, utils.ToCmdLine("Append", key, key))
|
||||
val, ok := actual.(*reply.IntReply)
|
||||
if !ok {
|
||||
t.Errorf("expect nil bulk reply, get: %s", string(actual.ToBytes()))
|
||||
return
|
||||
}
|
||||
asserts.AssertIntReply(t, val, len(key))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user