chore: add more tests (#2795)
* chore: add more tests * chore: add more tests * chore: add more tests * chore: add more tests * chore: add more tests * chore: add more tests
This commit is contained in:
@@ -2278,12 +2278,25 @@ func (s *Redis) ZrangeWithScoresByFloatCtx(ctx context.Context, key string, star
|
||||
}
|
||||
|
||||
// ZRevRangeWithScores is the implementation of redis zrevrange command with scores.
|
||||
// Deprecated: use ZrevrangeWithScores instead.
|
||||
func (s *Redis) ZRevRangeWithScores(key string, start, stop int64) ([]Pair, error) {
|
||||
return s.ZRevRangeWithScoresCtx(context.Background(), key, start, stop)
|
||||
return s.ZrevrangeWithScoresCtx(context.Background(), key, start, stop)
|
||||
}
|
||||
|
||||
// ZrevrangeWithScores is the implementation of redis zrevrange command with scores.
|
||||
func (s *Redis) ZrevrangeWithScores(key string, start, stop int64) ([]Pair, error) {
|
||||
return s.ZrevrangeWithScoresCtx(context.Background(), key, start, stop)
|
||||
}
|
||||
|
||||
// ZRevRangeWithScoresCtx is the implementation of redis zrevrange command with scores.
|
||||
// Deprecated: use ZrevrangeWithScoresCtx instead.
|
||||
func (s *Redis) ZRevRangeWithScoresCtx(ctx context.Context, key string, start, stop int64) (
|
||||
val []Pair, err error) {
|
||||
return s.ZrevrangeWithScoresCtx(ctx, key, start, stop)
|
||||
}
|
||||
|
||||
// ZrevrangeWithScoresCtx is the implementation of redis zrevrange command with scores.
|
||||
func (s *Redis) ZrevrangeWithScoresCtx(ctx context.Context, key string, start, stop int64) (
|
||||
val []Pair, err error) {
|
||||
err = s.brk.DoWithAcceptable(func() error {
|
||||
conn, err := getRedis(s)
|
||||
@@ -2304,12 +2317,25 @@ func (s *Redis) ZRevRangeWithScoresCtx(ctx context.Context, key string, start, s
|
||||
}
|
||||
|
||||
// ZRevRangeWithScoresByFloat is the implementation of redis zrevrange command with scores by float.
|
||||
// Deprecated: use ZrevrangeWithScoresByFloat instead.
|
||||
func (s *Redis) ZRevRangeWithScoresByFloat(key string, start, stop int64) ([]FloatPair, error) {
|
||||
return s.ZRevRangeWithScoresByFloatCtx(context.Background(), key, start, stop)
|
||||
return s.ZrevrangeWithScoresByFloatCtx(context.Background(), key, start, stop)
|
||||
}
|
||||
|
||||
// ZrevrangeWithScoresByFloat is the implementation of redis zrevrange command with scores by float.
|
||||
func (s *Redis) ZrevrangeWithScoresByFloat(key string, start, stop int64) ([]FloatPair, error) {
|
||||
return s.ZrevrangeWithScoresByFloatCtx(context.Background(), key, start, stop)
|
||||
}
|
||||
|
||||
// ZRevRangeWithScoresByFloatCtx is the implementation of redis zrevrange command with scores by float.
|
||||
// Deprecated: use ZrevrangeWithScoresByFloatCtx instead.
|
||||
func (s *Redis) ZRevRangeWithScoresByFloatCtx(ctx context.Context, key string, start, stop int64) (
|
||||
val []FloatPair, err error) {
|
||||
return s.ZrevrangeWithScoresByFloatCtx(ctx, key, start, stop)
|
||||
}
|
||||
|
||||
// ZrevrangeWithScoresByFloatCtx is the implementation of redis zrevrange command with scores by float.
|
||||
func (s *Redis) ZrevrangeWithScoresByFloatCtx(ctx context.Context, key string, start, stop int64) (
|
||||
val []FloatPair, err error) {
|
||||
err = s.brk.DoWithAcceptable(func() error {
|
||||
conn, err := getRedis(s)
|
||||
|
||||
@@ -959,7 +959,11 @@ func TestRedis_SortedSet(t *testing.T) {
|
||||
assert.Equal(t, int64(2), val)
|
||||
_, err = New(client.Addr, badType()).ZRevRangeWithScores("key", 1, 3)
|
||||
assert.NotNil(t, err)
|
||||
pairs, err := client.ZRevRangeWithScores("key", 1, 3)
|
||||
_, err = client.ZRevRangeWithScores("key", 1, 3)
|
||||
assert.Nil(t, err)
|
||||
_, err = client.ZRevRangeWithScoresCtx(context.Background(), "key", 1, 3)
|
||||
assert.Nil(t, err)
|
||||
pairs, err := client.ZrevrangeWithScores("key", 1, 3)
|
||||
assert.Nil(t, err)
|
||||
assert.EqualValues(t, []Pair{
|
||||
{
|
||||
@@ -1129,65 +1133,105 @@ func TestRedis_SortedSet(t *testing.T) {
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.ZaddFloat("key", 1, "value")
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.Zadds("key")
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.Zadds("key")
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.Zcard("key")
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.Zcard("key")
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.Zcount("key", 1, 2)
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.Zcount("key", 1, 2)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.Zincrby("key", 1, "value")
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.Zincrby("key", 1, "value")
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.Zscore("key", "value")
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.Zscore("key", "value")
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.Zrem("key", "value")
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.Zrem("key", "value")
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.Zremrangebyscore("key", 1, 2)
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.Zremrangebyscore("key", 1, 2)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.Zremrangebyrank("key", 1, 2)
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.Zremrangebyrank("key", 1, 2)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.ZrangeWithScores("key", 1, 2)
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.ZrangeWithScores("key", 1, 2)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.ZrangeWithScoresByFloat("key", 1, 2)
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.ZrangeWithScoresByFloat("key", 1, 2)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.ZRevRangeWithScores("key", 1, 2)
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.ZRevRangeWithScores("key", 1, 2)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.ZRevRangeWithScoresByFloat("key", 1, 2)
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.ZRevRangeWithScoresByFloat("key", 1, 2)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.ZrangebyscoreWithScores("key", 1, 2)
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.ZrangebyscoreWithScores("key", 1, 2)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.ZrangebyscoreWithScoresByFloat("key", 1, 2)
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.ZrangebyscoreWithScoresByFloat("key", 1, 2)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.ZrangebyscoreWithScoresAndLimit("key", 1, 2, 1, 1)
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.ZrangebyscoreWithScoresAndLimit("key", 1, 2, 1, 1)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.ZrangebyscoreWithScoresByFloatAndLimit("key", 1, 2, 1, 1)
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.ZrangebyscoreWithScoresByFloatAndLimit("key", 1, 2, 1, 1)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.ZrevrangebyscoreWithScores("key", 1, 2)
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.ZrevrangebyscoreWithScores("key", 1, 2)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.ZrevrangebyscoreWithScoresByFloat("key", 1, 2)
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.ZrevrangebyscoreWithScoresByFloat("key", 1, 2)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.ZrevrangebyscoreWithScoresAndLimit("key", 1, 2, 1, 1)
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.ZrevrangebyscoreWithScoresAndLimit("key", 1, 2, 1, 1)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
_, err = client.ZrevrangebyscoreWithScoresByFloatAndLimit("key", 1, 2, 1, 1)
|
||||
runOnRedisWithError(t, func(client *Redis) {
|
||||
_, err := client.ZrevrangebyscoreWithScoresByFloatAndLimit("key", 1, 2, 1, 1)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
})
|
||||
@@ -1206,7 +1250,11 @@ func TestRedis_SortedSetByFloat64(t *testing.T) {
|
||||
_, _ = client.ZaddFloat("key", 10.346, "value2")
|
||||
_, err = New(client.Addr, badType()).ZRevRangeWithScoresByFloat("key", 0, -1)
|
||||
assert.NotNil(t, err)
|
||||
pairs, err := client.ZRevRangeWithScoresByFloat("key", 0, -1)
|
||||
_, err = client.ZRevRangeWithScoresByFloat("key", 0, -1)
|
||||
assert.Nil(t, err)
|
||||
_, err = client.ZRevRangeWithScoresByFloatCtx(context.Background(), "key", 0, -1)
|
||||
assert.Nil(t, err)
|
||||
pairs, err := client.ZrevrangeWithScoresByFloat("key", 0, -1)
|
||||
assert.Nil(t, err)
|
||||
assert.EqualValues(t, []FloatPair{
|
||||
{
|
||||
|
||||
@@ -8,12 +8,39 @@ import (
|
||||
)
|
||||
|
||||
func TestBlockingNode(t *testing.T) {
|
||||
r, err := miniredis.Run()
|
||||
assert.Nil(t, err)
|
||||
node, err := CreateBlockingNode(New(r.Addr()))
|
||||
assert.Nil(t, err)
|
||||
node.Close()
|
||||
node, err = CreateBlockingNode(New(r.Addr(), Cluster()))
|
||||
assert.Nil(t, err)
|
||||
node.Close()
|
||||
t.Run("test blocking node", func(t *testing.T) {
|
||||
r, err := miniredis.Run()
|
||||
assert.NoError(t, err)
|
||||
defer r.Close()
|
||||
|
||||
node, err := CreateBlockingNode(New(r.Addr()))
|
||||
assert.NoError(t, err)
|
||||
node.Close()
|
||||
// close again to make sure it's safe
|
||||
assert.NotPanics(t, func() {
|
||||
node.Close()
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("test blocking node with cluster", func(t *testing.T) {
|
||||
r, err := miniredis.Run()
|
||||
assert.NoError(t, err)
|
||||
defer r.Close()
|
||||
|
||||
node, err := CreateBlockingNode(New(r.Addr(), Cluster(), WithTLS()))
|
||||
assert.NoError(t, err)
|
||||
node.Close()
|
||||
assert.NotPanics(t, func() {
|
||||
node.Close()
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("test blocking node with bad type", func(t *testing.T) {
|
||||
r, err := miniredis.Run()
|
||||
assert.NoError(t, err)
|
||||
defer r.Close()
|
||||
|
||||
_, err = CreateBlockingNode(New(r.Addr(), badType()))
|
||||
assert.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user