refactor command table

This commit is contained in:
hdt3213
2021-05-24 23:17:55 +08:00
parent 68ae54f596
commit f1455534d4
24 changed files with 776 additions and 899 deletions

View File

@@ -21,18 +21,20 @@ func TestPing(t *testing.T) {
func TestAuth(t *testing.T) {
passwd := utils.RandString(10)
c := &connection.FakeConn{}
ret := Auth(testDB, c, utils.ToBytesList())
ret := testDB.Exec(c, utils.ToBytesList("AUTH"))
asserts.AssertErrReply(t, ret, "ERR wrong number of arguments for 'auth' command")
ret = Auth(testDB, c, utils.ToBytesList(passwd))
ret = testDB.Exec(c, utils.ToBytesList("AUTH", passwd))
asserts.AssertErrReply(t, ret, "ERR Client sent AUTH, but no password is set")
config.Properties.RequirePass = passwd
defer func() {
config.Properties.RequirePass = ""
}()
ret = Auth(testDB, c, utils.ToBytesList(passwd+passwd))
ret = testDB.Exec(c, utils.ToBytesList("AUTH", passwd+"wrong"))
asserts.AssertErrReply(t, ret, "ERR invalid password")
ret = Auth(testDB, c, utils.ToBytesList(passwd))
ret = testDB.Exec(c, utils.ToBytesList("PING"))
asserts.AssertErrReply(t, ret, "NOAUTH Authentication required")
ret = testDB.Exec(c, utils.ToBytesList("AUTH", passwd))
asserts.AssertStatusReply(t, ret, "OK")
}