refactor project structure

This commit is contained in:
hdt3213
2021-05-09 21:47:05 +08:00
parent 65fc1c3e62
commit 721d9c31a7
28 changed files with 126 additions and 110 deletions

38
server_test.go Normal file
View File

@@ -0,0 +1,38 @@
package godis
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.ToBytesList())
asserts.AssertStatusReply(t, actual, "PONG")
val := utils.RandString(5)
actual = Ping(testDB, utils.ToBytesList(val))
asserts.AssertStatusReply(t, actual, val)
actual = Ping(testDB, utils.ToBytesList(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 := Auth(testDB, c, utils.ToBytesList())
asserts.AssertErrReply(t, ret, "ERR wrong number of arguments for 'auth' command")
ret = Auth(testDB, c, utils.ToBytesList(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))
asserts.AssertErrReply(t, ret, "ERR invalid password")
ret = Auth(testDB, c, utils.ToBytesList(passwd))
asserts.AssertStatusReply(t, ret, "OK")
}