-
Notifications
You must be signed in to change notification settings - Fork 0
/
sys_test.go
41 lines (35 loc) · 1.35 KB
/
sys_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package godis
import (
"testing"
"github.com/tigbox/godis/config"
"github.com/tigbox/godis/lib/utils"
"github.com/tigbox/godis/redis/connection"
"github.com/tigbox/godis/redis/reply/asserts"
)
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")
}