Skip to content

Commit

Permalink
integration tests for RPOP
Browse files Browse the repository at this point in the history
  • Loading branch information
Kripu77 committed Dec 9, 2024
1 parent 099f0d2 commit d7ede74
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
46 changes: 46 additions & 0 deletions integration_tests/commands/http/deque_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,3 +599,49 @@ func TestLPOPCount(t *testing.T) {

exec.FireCommand(HTTPCommand{Command: "DEL", Body: map[string]interface{}{"keys": [...]string{"k"}}})
}

func TestRPOPCount(t *testing.T) {
exec := NewHTTPCommandExecutor()
exec.FireCommand(HTTPCommand{Command: "FLUSHDB"})
testCases := []struct {
name string
cmds []HTTPCommand
expect []any
}{
{
name: "RPOP with count argument - valid, invalid, and edge cases",
cmds: []HTTPCommand{
{Command: "RPUSH", Body: map[string]interface{}{"key": "k", "value": "v1"}},
{Command: "RPUSH", Body: map[string]interface{}{"key": "k", "value": "v2"}},
{Command: "RPUSH", Body: map[string]interface{}{"key": "k", "value": "v3"}},
{Command: "RPUSH", Body: map[string]interface{}{"key": "k", "value": "v4"}},
{Command: "RPOP", Body: map[string]interface{}{"key": "k", "value": 2}},
{Command: "RPOP", Body: map[string]interface{}{"key": "k", "value": 2}},
{Command: "RPOP", Body: map[string]interface{}{"key": "k", "value": -1}},
{Command: "RPOP", Body: map[string]interface{}{"key": "k", "value": "abc"}},
{Command: "LLEN", Body: map[string]interface{}{"key": "k"}},
},
expect: []any{
float64(1),
float64(2),
float64(3),
float64(4),
[]interface{}{"v3", "v4"},
[]interface{}{"v1", "v2"},
"ERR value is not an integer or out of range",
"ERR value is not an integer or a float",
float64(0),
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
exec.FireCommand(HTTPCommand{Command: "DEL", Body: map[string]interface{}{"keys": []interface{}{"k"}}})
for i, cmd := range tc.cmds {
result, _ := exec.FireCommand(cmd)
assert.Equal(t, tc.expect[i], result, "Value mismatch for cmd %v", cmd)
}
})
}
}
50 changes: 50 additions & 0 deletions integration_tests/commands/websocket/deque_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,53 @@ func TestLPOPCount(t *testing.T) {
})
}
}

func TestRPOPCount(t *testing.T) {
exec := NewWebsocketCommandExecutor()

testCases := []struct {
name string
commands []string
expected []interface{}
cleanupKey string
}{
{
name: "RPOP with count argument - valid, invalid, and edge cases",
commands: []string{
"RPUSH k v1",
"RPUSH k v2",
"RPUSH k v3",
"RPUSH k v4",
"RPOP k 2",
"RPOP k 2",
"RPOP k -1",
"RPOP k abc",
"LLEN k",
},
expected: []interface{}{
float64(1),
float64(2),
float64(3),
float64(4),
[]interface{}{"v3", "v4"},
[]interface{}{"v1", "v2"},
"ERR value is not an integer or out of range",
"ERR value is not an integer or a float",
float64(0),
},
cleanupKey: "k",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
conn := exec.ConnectToServer()

for i, cmd := range tc.commands {
result, err := exec.FireCommandAndReadResponse(conn, cmd)
assert.NilError(t, err)
assert.DeepEqual(t, tc.expected[i], result)
}
DeleteKey(t, conn, exec, tc.cleanupKey)
})
}
}

0 comments on commit d7ede74

Please sign in to comment.