github.com/hdt3213/godis@v1.2.9/cluster/com_test.go (about) 1 package cluster 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 TestExec(t *testing.T) { 12 testCluster2 := MakeTestCluster([]string{"127.0.0.1:6379"}) 13 conn := connection.NewFakeConn() 14 for i := 0; i < 1000; i++ { 15 key := RandString(4) 16 value := RandString(4) 17 testCluster2.Exec(conn, toArgs("SET", key, value)) 18 ret := testCluster2.Exec(conn, toArgs("GET", key)) 19 asserts.AssertBulkReply(t, ret, value) 20 } 21 } 22 23 func TestAuth(t *testing.T) { 24 passwd := utils.RandString(10) 25 config.Properties.RequirePass = passwd 26 defer func() { 27 config.Properties.RequirePass = "" 28 }() 29 conn := connection.NewFakeConn() 30 ret := testNodeA.Exec(conn, toArgs("GET", "a")) 31 asserts.AssertErrReply(t, ret, "NOAUTH Authentication required") 32 ret = testNodeA.Exec(conn, toArgs("AUTH", passwd)) 33 asserts.AssertStatusReply(t, ret, "OK") 34 ret = testNodeA.Exec(conn, toArgs("GET", "a")) 35 asserts.AssertNotError(t, ret) 36 } 37 38 func TestRelay(t *testing.T) { 39 testCluster2 := MakeTestCluster([]string{"127.0.0.1:6379"}) 40 key := RandString(4) 41 value := RandString(4) 42 conn := connection.NewFakeConn() 43 ret := testCluster2.relay("127.0.0.1:6379", conn, toArgs("SET", key, value)) 44 asserts.AssertNotError(t, ret) 45 ret = testCluster2.relay("127.0.0.1:6379", conn, toArgs("GET", key)) 46 asserts.AssertBulkReply(t, ret, value) 47 } 48 49 func TestBroadcast(t *testing.T) { 50 testCluster2 := MakeTestCluster([]string{"127.0.0.1:6379"}) 51 key := RandString(4) 52 value := RandString(4) 53 rets := testCluster2.broadcast(connection.NewFakeConn(), toArgs("SET", key, value)) 54 for _, v := range rets { 55 asserts.AssertNotError(t, v) 56 } 57 }