1- package redis_test
1+ package redis
22
33import (
4- rediscli "github.com/go-redis/redis"
5- "github.com/ucloud/redis-operator/pkg/client/redis"
64 "strings"
75 "testing"
6+
7+ rediscli "github.com/go-redis/redis"
88)
99
1010func newClient () * rediscli.Client {
@@ -18,7 +18,7 @@ func newClient() *rediscli.Client {
1818func TestGetAllRedisConfig (t * testing.T ) {
1919 cli := newClient ()
2020 //var client redis.Client
21- client := redis . New ()
21+ client := New ()
2222 result , err := client .GetAllRedisConfig (cli )
2323 if err != nil {
2424 t .Fatal (err )
@@ -33,3 +33,59 @@ func TestGetAllRedisConfig(t *testing.T) {
3333 }
3434
3535}
36+
37+ func Test_slaveInfoFieldByName (t * testing.T ) {
38+ slaveInfoBlobA := []interface {}{"name" , "[xxxxA]:6379" , "ip" , "xxxxA" , "port" , "6379" , "runid" , "6f792839ab551e8dbec58e0eb3b3838d14f19a37" , "flags" , "slave" , "link-pending-commands" , "1" , "link-refcount" , "1" , "last-ping-sent" , "0" , "last-ok-ping-reply" , "1055" , "last-ping-reply" , "1055" , "down-after-milliseconds" , "5000" , "info-refresh" , "2074" , "role-reported" , "slave" , "role-reported-time" , "2983115" , "master-link-down-time" , "0" , "master-link-status" , "ok" , "master-host" , "xxxxA" , "master-port" , "6379" , "slave-priority" , "1" , "slave-repl-offset" , "124614695" }
39+ slaveInfoBlobB := []interface {}{"name" , "[xxxxB]:6371" , "ip" , "xxxxB" , "port" , "6371" , "runid" , "fake_slave_8bb90711-8f37-44e8-b3b2-589af" , "flags" , "slave" , "link-pending-commands" , "1" , "link-refcount" , "1" , "last-ping-sent" , "0" , "last-ok-ping-reply" , "1055" , "last-ping-reply" , "1055" , "down-after-milliseconds" , "5000" , "info-refresh" , "2075" , "role-reported" , "slave" , "role-reported-time" , "2983114" , "master-link-down-time" , "0" , "master-link-status" , "ok" , "master-host" , "xxxxB" , "master-port" , "6379" , "slave-priority" , "0" , "slave-repl-offset" , "124614695" }
40+ slaveInfoBlobC := []interface {}{"name" , "[xxxxB]:6371" , "ip" , "slave-priority" , "slave-priority" , "100" }
41+ slaveInfoBlobD := []interface {}{"name" , "[xxxxB]:6371" , "ip" , "xxxxB" , "slave-priority" }
42+ type args struct {
43+ name string
44+ slaveInfoBlob interface {}
45+ }
46+ tests := []struct {
47+ name string
48+ args args
49+ want string
50+ }{
51+ {
52+ name : "slaveA" ,
53+ args : args {
54+ name : "slave-priority" ,
55+ slaveInfoBlob : slaveInfoBlobA ,
56+ },
57+ want : "1" ,
58+ },
59+ {
60+ name : "slaveB" ,
61+ args : args {
62+ name : "slave-priority" ,
63+ slaveInfoBlob : slaveInfoBlobB ,
64+ },
65+ want : "0" ,
66+ },
67+ {
68+ name : "slaveC" ,
69+ args : args {
70+ name : "slave-priority" ,
71+ slaveInfoBlob : slaveInfoBlobC ,
72+ },
73+ want : "100" ,
74+ },
75+ {
76+ name : "slaveD" ,
77+ args : args {
78+ name : "slave-priority" ,
79+ slaveInfoBlob : slaveInfoBlobD ,
80+ },
81+ want : "" ,
82+ },
83+ }
84+ for _ , tt := range tests {
85+ t .Run (tt .name , func (t * testing.T ) {
86+ if got := slaveInfoFieldByName (tt .args .name , tt .args .slaveInfoBlob ); got != tt .want {
87+ t .Errorf ("slaveInfoFieldByName() = %v, want %v" , got , tt .want )
88+ }
89+ })
90+ }
91+ }
0 commit comments