|
|
|
@ -1,9 +1,9 @@ |
|
|
|
|
package utils |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"testing" |
|
|
|
|
"fmt" |
|
|
|
|
"sort" |
|
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
|
) |
|
|
|
@ -14,8 +14,8 @@ func TestGetAllClusterNode(t *testing.T) { |
|
|
|
|
fmt.Printf("TestGetAllClusterNode case %d.\n", nr) |
|
|
|
|
nr++ |
|
|
|
|
|
|
|
|
|
client := OpenRedisConn([]string{"10.1.1.1:21333"}, "auth", "123456", false) |
|
|
|
|
ret, err := GetAllClusterNode(client, "master") |
|
|
|
|
client := OpenRedisConn([]string{"10.1.1.1:21333"}, "auth", "123456", false, false) |
|
|
|
|
ret, err := GetAllClusterNode(client, "master", "") |
|
|
|
|
sort.Strings(ret) |
|
|
|
|
assert.Equal(t, nil, err, "should be equal") |
|
|
|
|
assert.Equal(t, 3, len(ret), "should be equal") |
|
|
|
@ -28,8 +28,8 @@ func TestGetAllClusterNode(t *testing.T) { |
|
|
|
|
fmt.Printf("TestGetAllClusterNode case %d.\n", nr) |
|
|
|
|
nr++ |
|
|
|
|
|
|
|
|
|
client := OpenRedisConn([]string{"10.1.1.1:21333"}, "auth", "123456", false) |
|
|
|
|
ret, err := GetAllClusterNode(client, "slave") |
|
|
|
|
client := OpenRedisConn([]string{"10.1.1.1:21333"}, "auth", "123456", false, false) |
|
|
|
|
ret, err := GetAllClusterNode(client, "slave", "") |
|
|
|
|
sort.Strings(ret) |
|
|
|
|
assert.Equal(t, nil, err, "should be equal") |
|
|
|
|
assert.Equal(t, 3, len(ret), "should be equal") |
|
|
|
@ -42,8 +42,8 @@ func TestGetAllClusterNode(t *testing.T) { |
|
|
|
|
fmt.Printf("TestGetAllClusterNode case %d.\n", nr) |
|
|
|
|
nr++ |
|
|
|
|
|
|
|
|
|
client := OpenRedisConn([]string{"10.1.1.1:21333"}, "auth", "123456", false) |
|
|
|
|
ret, err := GetAllClusterNode(client, "all") |
|
|
|
|
client := OpenRedisConn([]string{"10.1.1.1:21333"}, "auth", "123456", false, false) |
|
|
|
|
ret, err := GetAllClusterNode(client, "all", "") |
|
|
|
|
sort.Strings(ret) |
|
|
|
|
assert.Equal(t, nil, err, "should be equal") |
|
|
|
|
assert.Equal(t, 6, len(ret), "should be equal") |
|
|
|
@ -55,3 +55,35 @@ func TestGetAllClusterNode(t *testing.T) { |
|
|
|
|
assert.Equal(t, "10.1.1.1:21336", ret[5], "should be equal") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestHasAtLeastOnePrefix(t *testing.T) { |
|
|
|
|
cases := []struct { |
|
|
|
|
key string |
|
|
|
|
prefixes []string |
|
|
|
|
expectResult bool |
|
|
|
|
}{ |
|
|
|
|
{ |
|
|
|
|
// no prefix provided
|
|
|
|
|
"a", |
|
|
|
|
[]string{}, |
|
|
|
|
false, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
// has prefix
|
|
|
|
|
"abc", |
|
|
|
|
[]string{"ab"}, |
|
|
|
|
true, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
// does NOT have prefix
|
|
|
|
|
"abc", |
|
|
|
|
[]string{"edf", "wab"}, |
|
|
|
|
false, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, c := range cases { |
|
|
|
|
result := HasAtLeastOnePrefix(c.key, c.prefixes) |
|
|
|
|
assert.Equal(t, c.expectResult, result) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|