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,41 @@ 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+ type args struct {
41+ name string
42+ slaveInfoBlob interface {}
43+ }
44+ tests := []struct {
45+ name string
46+ args args
47+ want string
48+ }{
49+ {
50+ name : "slaveA" ,
51+ args : args {
52+ name : "slave-priority" ,
53+ slaveInfoBlob : slaveInfoBlobA ,
54+ },
55+ want : "1" ,
56+ },
57+ {
58+ name : "slaveB" ,
59+ args : args {
60+ name : "slave-priority" ,
61+ slaveInfoBlob : slaveInfoBlobB ,
62+ },
63+ want : "0" ,
64+ },
65+ }
66+ for _ , tt := range tests {
67+ t .Run (tt .name , func (t * testing.T ) {
68+ if got := slaveInfoFieldByName (tt .args .name , tt .args .slaveInfoBlob ); got != tt .want {
69+ t .Errorf ("slaveInfoFieldByName() = %v, want %v" , got , tt .want )
70+ }
71+ })
72+ }
73+ }
0 commit comments