mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-08 18:20:49 +08:00
optimize project structure
This commit is contained in:
40
database/sys_test.go
Normal file
40
database/sys_test.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/hdt3213/godis/config"
|
||||
"github.com/hdt3213/godis/lib/utils"
|
||||
"github.com/hdt3213/godis/redis/connection"
|
||||
"github.com/hdt3213/godis/redis/reply/asserts"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPing(t *testing.T) {
|
||||
actual := Ping(testDB, utils.ToCmdLine())
|
||||
asserts.AssertStatusReply(t, actual, "PONG")
|
||||
val := utils.RandString(5)
|
||||
actual = Ping(testDB, utils.ToCmdLine(val))
|
||||
asserts.AssertStatusReply(t, actual, val)
|
||||
actual = Ping(testDB, utils.ToCmdLine(val, val))
|
||||
asserts.AssertErrReply(t, actual, "ERR wrong number of arguments for 'ping' command")
|
||||
}
|
||||
|
||||
func TestAuth(t *testing.T) {
|
||||
passwd := utils.RandString(10)
|
||||
c := &connection.FakeConn{}
|
||||
ret := testServer.Exec(c, utils.ToCmdLine("AUTH"))
|
||||
asserts.AssertErrReply(t, ret, "ERR wrong number of arguments for 'auth' command")
|
||||
ret = testServer.Exec(c, utils.ToCmdLine("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 = testServer.Exec(c, utils.ToCmdLine("AUTH", passwd+"wrong"))
|
||||
asserts.AssertErrReply(t, ret, "ERR invalid password")
|
||||
ret = testServer.Exec(c, utils.ToCmdLine("PING"))
|
||||
asserts.AssertErrReply(t, ret, "NOAUTH Authentication required")
|
||||
ret = testServer.Exec(c, utils.ToCmdLine("AUTH", passwd))
|
||||
asserts.AssertStatusReply(t, ret, "OK")
|
||||
|
||||
}
|
Reference in New Issue
Block a user