github.com/hdt3213/godis@v1.2.9/database/systemcmd_test.go (about)

     1  package database
     2  
     3  import (
     4  	"github.com/hdt3213/godis/config"
     5  	"github.com/hdt3213/godis/lib/utils"
     6  	"github.com/hdt3213/godis/redis/connection"
     7  	"github.com/hdt3213/godis/redis/protocol/asserts"
     8  	"testing"
     9  )
    10  
    11  func TestPing(t *testing.T) {
    12  	c := connection.NewFakeConn()
    13  	actual := Ping(c, utils.ToCmdLine())
    14  	asserts.AssertStatusReply(t, actual, "PONG")
    15  	val := utils.RandString(5)
    16  	actual = Ping(c, utils.ToCmdLine(val))
    17  	asserts.AssertStatusReply(t, actual, val)
    18  	actual = Ping(c, utils.ToCmdLine(val, val))
    19  	asserts.AssertErrReply(t, actual, "ERR wrong number of arguments for 'ping' command")
    20  }
    21  
    22  func TestAuth(t *testing.T) {
    23  	passwd := utils.RandString(10)
    24  	c := connection.NewFakeConn()
    25  	ret := testServer.Exec(c, utils.ToCmdLine("AUTH"))
    26  	asserts.AssertErrReply(t, ret, "ERR wrong number of arguments for 'auth' command")
    27  	ret = testServer.Exec(c, utils.ToCmdLine("AUTH", passwd))
    28  	asserts.AssertErrReply(t, ret, "ERR Client sent AUTH, but no password is set")
    29  
    30  	config.Properties.RequirePass = passwd
    31  	defer func() {
    32  		config.Properties.RequirePass = ""
    33  	}()
    34  	ret = testServer.Exec(c, utils.ToCmdLine("AUTH", passwd+"wrong"))
    35  	asserts.AssertErrReply(t, ret, "ERR invalid password")
    36  	ret = testServer.Exec(c, utils.ToCmdLine("GET", "A"))
    37  	asserts.AssertErrReply(t, ret, "NOAUTH Authentication required")
    38  	ret = testServer.Exec(c, utils.ToCmdLine("AUTH", passwd))
    39  	asserts.AssertStatusReply(t, ret, "OK")
    40  
    41  }
    42  
    43  func TestInfo(t *testing.T) {
    44  	c := connection.NewFakeConn()
    45  	ret := testServer.Exec(c, utils.ToCmdLine("INFO"))
    46  	asserts.AssertNotError(t, ret)
    47  	ret = testServer.Exec(c, utils.ToCmdLine("INFO", "server"))
    48  	asserts.AssertNotError(t, ret)
    49  	ret = testServer.Exec(c, utils.ToCmdLine("INFO", "client"))
    50  	asserts.AssertNotError(t, ret)
    51  	ret = testServer.Exec(c, utils.ToCmdLine("INFO", "cluster"))
    52  	asserts.AssertNotError(t, ret)
    53  	ret = testServer.Exec(c, utils.ToCmdLine("iNFO", "SeRvEr"))
    54  	asserts.AssertNotError(t, ret)
    55  	ret = testServer.Exec(c, utils.ToCmdLine("INFO", "Keyspace"))
    56  	asserts.AssertNotError(t, ret)
    57  	ret = testServer.Exec(c, utils.ToCmdLine("iNFO", "abc", "bde"))
    58  	asserts.AssertErrReply(t, ret, "ERR wrong number of arguments for 'info' command")
    59  	ret = testServer.Exec(c, utils.ToCmdLine("INFO", "abc"))
    60  	asserts.AssertErrReply(t, ret, "Invalid section for 'info' command")
    61  }