Skip to content

Commit

Permalink
add GETKEYS unit test for XREAD and XREADGROUP.
Browse files Browse the repository at this point in the history
  • Loading branch information
LindaSummer committed Nov 14, 2024
1 parent 29b08bd commit 4cabbe1
Showing 1 changed file with 134 additions and 0 deletions.
134 changes: 134 additions & 0 deletions tests/gocase/unit/command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,138 @@ func TestCommand(t *testing.T) {
require.Equal(t, "dst", vs[0])
require.Equal(t, "src", vs[1])
})

t.Run("COMMAND GETKEYS XREAD", func(t *testing.T) {
{
r := rdb.Do(ctx, "COMMAND", "GETKEYS", "XREAD",
"STREAMS", "k0-1", "k0-2", "0-0", "0-0")
vs, err := r.Slice()
require.NoError(t, err)
require.Len(t, vs, 2)
require.Equal(t, "k0-1", vs[0])
require.Equal(t, "k0-2", vs[1])
}

{
r := rdb.Do(ctx, "COMMAND", "GETKEYS", "XREAD", "COUNT", "10",
"STREAMS", "k1-1", "k1-2", "0-0", "0-0")
vs, err := r.Slice()
require.NoError(t, err)
require.Len(t, vs, 2)
require.Equal(t, "k1-1", vs[0])
require.Equal(t, "k1-2", vs[1])
}

{
r := rdb.Do(ctx, "COMMAND", "GETKEYS", "XREAD", "BLOCK", "1000",
"STREAMS", "k2-1", "k2-2", "0-0", "0-0")
vs, err := r.Slice()
require.NoError(t, err)
require.Len(t, vs, 2)
require.Equal(t, "k2-1", vs[0])
require.Equal(t, "k2-2", vs[1])
}

{
r := rdb.Do(ctx, "COMMAND", "GETKEYS", "XREAD", "COUNT", "10",
"BLOCK", "1000", "STREAMS", "k3-1", "k3-2", "0-0", "0-0")
vs, err := r.Slice()
require.NoError(t, err)
require.Len(t, vs, 2)
require.Equal(t, "k3-1", vs[0])
require.Equal(t, "k3-2", vs[1])
}
})

t.Run("COMMAND GETKEYS XREADGROUP", func(t *testing.T) {
{
r := rdb.Do(ctx, "COMMAND", "GETKEYS", "XREADGROUP", "GROUP", "group1", "consumer1",
"STREAMS", "gk0-1", "gk0-2", "0-0", "0-0")
vs, err := r.Slice()
require.NoError(t, err)
require.Len(t, vs, 2)
require.Equal(t, "gk0-1", vs[0])
require.Equal(t, "gk0-2", vs[1])
}

{
r := rdb.Do(ctx, "COMMAND", "GETKEYS", "XREADGROUP", "GROUP", "streams", "streams",
"STREAMS", "gk1-1", "gk1-2", "0-0", "0-0")
vs, err := r.Slice()
require.NoError(t, err)
require.Len(t, vs, 2)
require.Equal(t, "gk1-1", vs[0])
require.Equal(t, "gk1-2", vs[1])
}

{
r := rdb.Do(ctx, "COMMAND", "GETKEYS", "XREADGROUP", "GROUP", "group1", "consumer1",
"COUNT", "10", "STREAMS", "gk3-1", "gk3-2", "0-0", "0-0")
vs, err := r.Slice()
require.NoError(t, err)
require.Len(t, vs, 2)
require.Equal(t, "gk3-1", vs[0])
require.Equal(t, "gk3-2", vs[1])
}

{
r := rdb.Do(ctx, "COMMAND", "GETKEYS", "XREADGROUP", "GROUP", "group1", "consumer1",
"BLOCK", "10", "STREAMS", "gk4-1", "gk4-2", "0-0", "0-0")
vs, err := r.Slice()
require.NoError(t, err)
require.Len(t, vs, 2)
require.Equal(t, "gk4-1", vs[0])
require.Equal(t, "gk4-2", vs[1])
}

{
r := rdb.Do(ctx, "COMMAND", "GETKEYS", "XREADGROUP", "GROUP", "group1", "consumer1",
"NOACK", "STREAMS", "gk5-1", "gk5-2", "0-0", "0-0")
vs, err := r.Slice()
require.NoError(t, err)
require.Len(t, vs, 2)
require.Equal(t, "gk5-1", vs[0])
require.Equal(t, "gk5-2", vs[1])
}

{
r := rdb.Do(ctx, "COMMAND", "GETKEYS", "XREADGROUP", "GROUP", "group1", "consumer1",
"COUNT", "10", "NOACK", "STREAMS", "gk6-1", "gk6-2", "0-0", "0-0")
vs, err := r.Slice()
require.NoError(t, err)
require.Len(t, vs, 2)
require.Equal(t, "gk6-1", vs[0])
require.Equal(t, "gk6-2", vs[1])
}

{
r := rdb.Do(ctx, "COMMAND", "GETKEYS", "XREADGROUP", "GROUP", "group1", "consumer1",
"BLOCK", "1000", "NOACK", "STREAMS", "gk7-1", "gk7-2", "0-0", "0-0")
vs, err := r.Slice()
require.NoError(t, err)
require.Len(t, vs, 2)
require.Equal(t, "gk7-1", vs[0])
require.Equal(t, "gk7-2", vs[1])
}

{
r := rdb.Do(ctx, "COMMAND", "GETKEYS", "XREADGROUP", "GROUP", "group1", "consumer1",
"COUNT", "10", "BLOCK", "1000", "STREAMS", "gk8-1", "gk8-2", "0-0", "0-0")
vs, err := r.Slice()
require.NoError(t, err)
require.Len(t, vs, 2)
require.Equal(t, "gk8-1", vs[0])
require.Equal(t, "gk8-2", vs[1])
}

{
r := rdb.Do(ctx, "COMMAND", "GETKEYS", "XREADGROUP", "GROUP", "group1", "consumer1",
"COUNT", "10", "BLOCK", "1000", "NOACK", "STREAMS", "gk9-1", "gk9-2", "0-0", "0-0")
vs, err := r.Slice()
require.NoError(t, err)
require.Len(t, vs, 2)
require.Equal(t, "gk9-1", vs[0])
require.Equal(t, "gk9-2", vs[1])
}
})
}

0 comments on commit 4cabbe1

Please sign in to comment.