-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
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
Showing
3 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} | ||
} |