Skip to content

Commit

Permalink
add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
propan committed Dec 23, 2021
1 parent 414e0b4 commit 16948fd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd_sorted_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ func (m *Miniredis) cmdZunion(c *server.Peer, cmd string, args []string) {
} else {
c.WriteLen(len(sset))
}
for _, el := range sset.byScore(desc) {
for _, el := range sset.byScore(asc) {
c.WriteBulk(el.member)
if withScores {
c.WriteFloat(el.score)
Expand Down
48 changes: 48 additions & 0 deletions integration/sorted_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,54 @@ func TestZscan(t *testing.T) {
})
}

func TestZunion(t *testing.T) {
testRaw(t, func(c *client) {
// example from the docs https://redis.io/commands/ZUNION
c.Do("ZADD", "zset1", "1", "one")
c.Do("ZADD", "zset1", "2", "two")
c.Do("ZADD", "zset2", "1", "one")
c.Do("ZADD", "zset2", "2", "two")
c.Do("ZADD", "zset2", "3", "three")
c.Do("ZUNION", "2", "zset1", "zset2")
c.Do("ZUNION", "2", "zset1", "zset2", "WITHSCORES")
})
testRaw(t, func(c *client) {
c.Do("ZADD", "h1", "1.0", "key1")
c.Do("ZADD", "h1", "2.0", "key2")
c.Do("ZADD", "h2", "1.0", "key1")
c.Do("ZADD", "h2", "4.0", "key2")
c.Do("ZUNION", "2", "h1", "h2", "WITHSCORES")

c.Do("ZUNION", "2", "h1", "h2", "WEIGHTS", "2.0", "12", "WITHSCORES")
c.Do("ZUNION", "2", "h1", "h2", "WEIGHTS", "2", "-12", "WITHSCORES")

c.Do("ZUNION", "2", "h1", "h2", "AGGREGATE", "min", "WITHSCORES")
c.Do("ZUNION", "2", "h1", "h2", "AGGREGATE", "max", "WITHSCORES")
c.Do("ZUNION", "2", "h1", "h2", "AGGREGATE", "sum", "WITHSCORES")

// Error cases
c.Error("wrong number", "ZUNION")
c.Error("wrong number", "ZUNION", "noint")
c.Error("at least 1", "ZUNION", "0", "f")
c.Error("syntax error", "ZUNION", "2", "f")
c.Error("at least 1", "ZUNION", "-1", "f")
c.Error("syntax error", "ZUNION", "2", "f1", "f2", "f3")
c.Error("syntax error", "ZUNION", "2", "f1", "f2", "WEIGHTS")
c.Error("syntax error", "ZUNION", "2", "f1", "f2", "WEIGHTS", "1")
c.Error("syntax error", "ZUNION", "2", "f1", "f2", "WEIGHTS", "1", "2", "3")
c.Error("not a float", "ZUNION", "2", "f1", "f2", "WEIGHTS", "f", "2")
c.Error("syntax error", "ZUNION", "2", "f1", "f2", "AGGREGATE", "foo")
c.Do("SET", "str", "1")
c.Error("wrong kind", "ZUNION", "1", "str")
})
// not a sorted set, still fine
testRaw(t, func(c *client) {
c.Do("SADD", "super", "1", "2", "3")
c.Do("SADD", "exclude", "3")
c.Do("ZUNION", "2", "super", "exclude", "weights", "1", "0", "aggregate", "min", "withscores")
})
}

func TestZunionstore(t *testing.T) {
testRaw(t, func(c *client) {
c.Do("ZADD", "h1", "1.0", "key1")
Expand Down

0 comments on commit 16948fd

Please sign in to comment.