fix test suite

This commit is contained in:
hdt3213
2022-04-30 19:23:49 +08:00
parent 0da9c96a3b
commit 24faeb3c56
2 changed files with 21 additions and 16 deletions

19
database/doc.go Normal file
View File

@@ -0,0 +1,19 @@
package database
/*
[MultiDB](https://github.com/HDT3213/godis/blob/master/database/database.go) is an implemention of interface [DB](https://github.com/HDT3213/godis/blob/master/interface/database/db.go).
[server.Handler](https://github.com/HDT3213/godis/blob/master/redis/server/server.go) holds an instance of MultiDB as storage engine, and pass command line to MultiDB through db.Exec method.
MultiDB is a multi-database engine which supports `SELECT` command. Besides multiple database instance, it holds pubsub.Hub and aof.Handler for publish-subscription and AOF persistence.
MultiDB.Exec is the main entry for MultiDB, it handles authentication, publish-subscription, aof as well as system commands itself, and invoke Exec function of selected db for other commands.
[godis.DB.Exec](https://github.com/HDT3213/godis/blob/master/database/single_db.go) handles transaction control command (such as watch, multi, exec) itself, and invokes DB.execNormalCommand to handle normal commands. The word, normal command, is commands which read or write limited keys, can execute within transaction, and supports rollback. For example, get, set, lpush are normal commands, while flushdb, keys are not.
[RegisterCommand](https://github.com/HDT3213/godis/blob/master/database/router.go) is used for registering normal command. A normal command requires three functions
- ExecFunc: The function that actually executes the command, such as [execHSet](https://github.com/HDT3213/godis/blob/master/database/hash.go)
- PrepareFunc executes before ExecFunc, it analysises command line and returns read/written keys for lock
- UndoFunc invoked in transaction only, it generates undo log in case need rollback in transaction
*/

View File

@@ -622,14 +622,7 @@ func TestGetRange_StringExist_StartIdxIncorrectFormat(t *testing.T) {
incorrectValue := "incorrect"
actual := testDB.Exec(nil, utils.ToCmdLine("GetRange", key, incorrectValue, fmt.Sprint(0)))
val, ok := actual.(*protocol.StandardErrReply)
if !ok {
t.Errorf("expect standart bulk protocol, get: %s", string(actual.ToBytes()))
return
}
errorMsg := fmt.Sprintf("strconv.ParseInt: parsing \"%s\": invalid syntax", incorrectValue)
asserts.AssertErrReply(t, val, errorMsg)
asserts.AssertErrReply(t, actual, "-ERR value is not an integer or out of range")
}
func TestGetRange_StringExist_EndIdxIncorrectFormat(t *testing.T) {
@@ -639,14 +632,7 @@ func TestGetRange_StringExist_EndIdxIncorrectFormat(t *testing.T) {
incorrectValue := "incorrect"
actual := testDB.Exec(nil, utils.ToCmdLine("GetRange", key, fmt.Sprint(0), incorrectValue))
val, ok := actual.(*protocol.StandardErrReply)
if !ok {
t.Errorf("expect standart bulk protocol, get: %s", string(actual.ToBytes()))
return
}
errorMsg := fmt.Sprintf("strconv.ParseInt: parsing \"%s\": invalid syntax", incorrectValue)
asserts.AssertErrReply(t, val, errorMsg)
asserts.AssertErrReply(t, actual, "ERR value is not an integer or out of range")
}
func TestSetBit(t *testing.T) {