added strlen and append commands

This commit is contained in:
Oleg
2021-06-25 11:48:52 +03:00
committed by finley
parent ae25076689
commit af0ffe6e83
2 changed files with 87 additions and 0 deletions

View File

@@ -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))
}