diff --git a/integration_tests/commands/http/randomkey_test.go b/integration_tests/commands/http/randomkey_test.go new file mode 100644 index 0000000000..6f55a67584 --- /dev/null +++ b/integration_tests/commands/http/randomkey_test.go @@ -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) + } + }) + } +} diff --git a/integration_tests/commands/resp/randomkey_test.go b/integration_tests/commands/resp/randomkey_test.go new file mode 100644 index 0000000000..8c1a94c234 --- /dev/null +++ b/integration_tests/commands/resp/randomkey_test.go @@ -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) + } + }) + } +} diff --git a/integration_tests/commands/websocket/randomkey_test.go b/integration_tests/commands/websocket/randomkey_test.go new file mode 100644 index 0000000000..ce619bb441 --- /dev/null +++ b/integration_tests/commands/websocket/randomkey_test.go @@ -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) + } + }) + } +}