Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minimal integration tests for randomkey over http, resp and websocket
Browse files Browse the repository at this point in the history
xanish committed Oct 20, 2024
1 parent 116fec4 commit bc83cfe
Showing 3 changed files with 129 additions and 0 deletions.
43 changes: 43 additions & 0 deletions integration_tests/commands/http/randomkey_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package http

import (
"testing"
"time"

"gotest.tools/v3/assert"
)

func TestRandomKey(t *testing.T) {
exec := NewHTTPCommandExecutor()

testCases := []struct {
name string
commands []HTTPCommand
expected []interface{}
delays []time.Duration
}{

{
name: "Random Key",
commands: []HTTPCommand{
{Command: "FLUSHDB"},
{Command: "SET", Body: map[string]interface{}{"key": "k1", "value": "v1"}},
{Command: "RANDOMKEY"},
},
expected: []interface{}{"OK", "OK", "k1"},
delays: []time.Duration{0, 0, 0},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
for i, cmd := range tc.commands {
if tc.delays[i] > 0 {
time.Sleep(tc.delays[i])
}
result, _ := exec.FireCommand(cmd)
assert.Equal(t, tc.expected[i], result, "Value mismatch for cmd %s", cmd)
}
})
}
}
43 changes: 43 additions & 0 deletions integration_tests/commands/resp/randomkey_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package resp

import (
"testing"
"time"

"gotest.tools/v3/assert"
)

func TestRandomKey(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()

testCases := []struct {
name string
cmds []string
expect []interface{}
delays []time.Duration
}{
{
name: "Random Key",
cmds: []string{
"FLUSHDB",
"SET k1 v1",
"RANDOMKEY",
},
expect: []interface{}{"OK", "OK", "k1"},
delays: []time.Duration{0, 0, 0},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
for i, cmd := range tc.cmds {
if tc.delays[i] > 0 {
time.Sleep(tc.delays[i])
}
result := FireCommand(conn, cmd)
assert.Equal(t, tc.expect[i], result, "Value mismatch for cmd %s", cmd)
}
})
}
}
43 changes: 43 additions & 0 deletions integration_tests/commands/websocket/randomkey_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package websocket

import (
"testing"
"time"

"gotest.tools/v3/assert"
)

func TestRandomKey(t *testing.T) {
exec := NewWebsocketCommandExecutor()
conn := exec.ConnectToServer()

testCases := []struct {
name string
cmds []string
expect []interface{}
delays []time.Duration
}{
{
name: "Random Key",
cmds: []string{
"FLUSHDB",
"SET k1 v1",
"RANDOMKEY",
},
expect: []interface{}{"OK", "OK", "k1"},
delays: []time.Duration{0, 0, 0},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
for i, cmd := range tc.cmds {
if tc.delays[i] > 0 {
time.Sleep(tc.delays[i])
}
result := exec.FireCommand(conn, cmd)
assert.Equal(t, tc.expect[i], result, "Value mismatch for cmd %s", cmd)
}
})
}
}

0 comments on commit bc83cfe

Please sign in to comment.