This repository was archived by the owner on Jun 23, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
#740 Add HTTP integration tests #873
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b5dac5b
Add integration test for HSETNX
hgupta12 36829b9
Add integration tests for HSTRLEN
hgupta12 4c35450
Remove duplicate test case from hyperloglog_test
hgupta12 211e0ba
Add http integration tests for hyperloglog
hgupta12 6f5d7bb
Add http integration tests for INCRBYFLOAT command
hgupta12 2d51821
Add http integration tests for INCR and INCRBY commands
hgupta12 b1de702
Fix failing intergration tests
hgupta12 5a65b42
Fix linting errors
hgupta12 486c332
Fix linting errors
hgupta12 49c6c5c
Merge branch 'master' into http-integration-tests
hgupta12 c36f855
Merge branch 'master' into http-integration-tests
JyotinderSingh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,73 @@ | ||
package http | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"gotest.tools/v3/assert" | ||
) | ||
|
||
func TestHSetNX(t *testing.T) { | ||
exec := NewHTTPCommandExecutor() | ||
|
||
testCases := []struct { | ||
name string | ||
commands []HTTPCommand | ||
expected []interface{} | ||
delays []time.Duration | ||
}{ | ||
{ | ||
name: "HSetNX returns 0 when field is already set", | ||
commands: []HTTPCommand{ | ||
{Command: "HSETNX", Body: map[string]interface{}{"key": "key_nx_t1", "field": "field", "value": "value"}}, | ||
{Command: "HSETNX", Body: map[string]interface{}{"key": "key_nx_t1", "field": "field", "value": "value_new"}}, | ||
}, | ||
expected: []interface{}{float64(1), float64(0)}, | ||
delays: []time.Duration{0, 0}, | ||
}, | ||
{ | ||
name: "HSetNX with new field", | ||
commands: []HTTPCommand{ | ||
{Command: "HSETNX", Body: map[string]interface{}{"key": "key_nx_t2", "field": "field", "value": "value"}}, | ||
}, | ||
expected: []interface{}{float64(1)}, | ||
delays: []time.Duration{0}, | ||
}, | ||
{ | ||
name: "HSetNX with wrong number of arguments", | ||
commands: []HTTPCommand{ | ||
{Command: "HSETNX", Body: map[string]interface{}{"key": "key_nx_t3", "field": "field", "value": "value"}}, | ||
{Command: "HSETNX", Body: map[string]interface{}{"key": "key_nx_t3", "field": "field", "value": "value_new"}}, | ||
{Command: "HSETNX", Body: map[string]interface{}{"key": "key_nx_t3"}}, | ||
}, | ||
expected: []interface{}{float64(1), float64(0), "ERR wrong number of arguments for 'hsetnx' command"}, | ||
delays: []time.Duration{0, 0, 0}, | ||
}, | ||
{ | ||
name: "HSetNX with wrong type", | ||
commands: []HTTPCommand{ | ||
{Command: "SET", Body: map[string]interface{}{"key": "key_nx_t4", "value": "v"}}, | ||
{Command: "HSETNX", Body: map[string]interface{}{"key": "key_nx_t4", "field": "f", "value": "v_new"}}, | ||
}, | ||
expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, | ||
delays: []time.Duration{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, err := exec.FireCommand(cmd) | ||
if err != nil { | ||
// Check if the error message matches the expected result | ||
assert.Equal(t, tc.expected[i], err.Error(), "Error message mismatch for cmd %s", cmd) | ||
} else { | ||
assert.Equal(t, tc.expected[i], result, "Value mismatch for cmd %s, expected %v, got %v", cmd, tc.expected[i], result) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains hidden or 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,88 @@ | ||
package http | ||
|
||
import ( | ||
"log" | ||
"testing" | ||
"time" | ||
|
||
"gotest.tools/v3/assert" | ||
) | ||
|
||
func TestHStrLen(t *testing.T) { | ||
exec := NewHTTPCommandExecutor() | ||
|
||
testCases := []struct { | ||
name string | ||
commands []HTTPCommand | ||
expected []interface{} | ||
delays []time.Duration | ||
}{ | ||
{ | ||
name: "HSTRLEN with wrong number of arguments", | ||
commands: []HTTPCommand{ | ||
{Command: "HSTRLEN", Body: map[string]interface{}{"key": "KEY"}}, | ||
{Command: "HSTRLEN", Body: map[string]interface{}{"key": "KEY", "field": "field", "another_field": "another_field"}}, | ||
}, | ||
expected: []interface{}{ | ||
"ERR wrong number of arguments for 'hstrlen' command", | ||
"ERR wrong number of arguments for 'hstrlen' command"}, | ||
delays: []time.Duration{0, 0}, | ||
}, | ||
{ | ||
name: "HSTRLEN with wrong key", | ||
commands: []HTTPCommand{ | ||
{Command: "HSET", Body: map[string]interface{}{"key": "key_hStrLen1", "field": "field", "value": "value"}}, | ||
{Command: "HSTRLEN", Body: map[string]interface{}{"key": "wrong_key_hStrLen", "field": "field"}}, | ||
}, | ||
expected: []interface{}{float64(1), float64(0)}, | ||
delays: []time.Duration{0, 0}, | ||
}, | ||
{ | ||
name: "HSTRLEN with wrong field", | ||
commands: []HTTPCommand{ | ||
{Command: "HSET", Body: map[string]interface{}{"key": "key_hStrLen2", "field": "field", "value": "value"}}, | ||
{Command: "HSTRLEN", Body: map[string]interface{}{"key": "key_hStrLen2", "field": "wrong_field"}}, | ||
}, | ||
expected: []interface{}{float64(1), float64(0)}, | ||
delays: []time.Duration{0, 0}, | ||
}, | ||
{ | ||
name: "HSTRLEN", | ||
commands: []HTTPCommand{ | ||
{Command: "HSET", Body: map[string]interface{}{"key": "key_hStrLen3", "field": "field", "value": "HelloWorld"}}, | ||
{Command: "HSTRLEN", Body: map[string]interface{}{"key": "key_hStrLen3", "field": "field"}}, | ||
}, | ||
expected: []interface{}{float64(1), float64(10)}, | ||
delays: []time.Duration{0, 0}, | ||
}, | ||
{ | ||
name: "HSTRLEN with wrong type", | ||
commands: []HTTPCommand{ | ||
{Command: "SET", Body: map[string]interface{}{"key": "key", "value": "value"}}, | ||
{Command: "HSTRLEN", Body: map[string]interface{}{"key": "key", "field": "field"}}, | ||
}, | ||
expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, | ||
delays: []time.Duration{0, 0}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
defer exec.FireCommand(HTTPCommand{Command: "DEL", Body: map[string]interface{}{"keys": [...]string{"KEY", "key"}}}) | ||
|
||
for i, cmd := range tc.commands { | ||
if tc.delays[i] > 0 { | ||
time.Sleep(tc.delays[i]) | ||
} | ||
result, err := exec.FireCommand(cmd) | ||
if err != nil { | ||
// Check if the error message matches the expected result | ||
log.Println(tc.expected[i]) | ||
assert.Equal(t, tc.expected[i], err.Error(), "Error message mismatch for cmd %s", cmd) | ||
} else { | ||
assert.Equal(t, tc.expected[i], result, "Value mismatch for cmd %s, expected %v, got %v", cmd, tc.expected[i], result) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains hidden or 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,150 @@ | ||
package http | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"gotest.tools/v3/assert" | ||
) | ||
|
||
func TestHyperLogLogCommands(t *testing.T) { | ||
exec := NewHTTPCommandExecutor() | ||
|
||
testCases := []struct { | ||
name string | ||
commands []HTTPCommand | ||
expected []interface{} | ||
delays []time.Duration | ||
}{ | ||
{ | ||
name: "PFADD with one key-value pair", | ||
commands: []HTTPCommand{ | ||
{Command: "PFADD", Body: map[string]interface{}{"key": "hll0", "value": "v1"}}, | ||
{Command: "PFCOUNT", Body: map[string]interface{}{"key": "hll0"}}, | ||
}, | ||
expected: []interface{}{float64(1), float64(1)}, | ||
delays: []time.Duration{0, 0}, | ||
}, | ||
{ | ||
name: "PFADD with multiple key-value pair", | ||
commands: []HTTPCommand{ | ||
{Command: "PFADD", Body: map[string]interface{}{"key": "hll", "values": [...]string{"a", "b", "c", "d", "e", "f"}}}, | ||
{Command: "PFCOUNT", Body: map[string]interface{}{"key": "hll"}}, | ||
}, | ||
expected: []interface{}{float64(1), float64(6)}, | ||
delays: []time.Duration{0, 0}, | ||
}, | ||
{ | ||
name: "PFADD with duplicate key-value pairs", | ||
commands: []HTTPCommand{ | ||
{Command: "PFADD", Body: map[string]interface{}{"key": "hll1", "values": [...]string{"foo", "bar", "zap"}}}, | ||
{Command: "PFADD", Body: map[string]interface{}{"key": "hll1", "values": [...]string{"zap", "zap", "zap"}}}, | ||
{Command: "PFADD", Body: map[string]interface{}{"key": "hll1", "values": [...]string{"foo", "bar"}}}, | ||
{Command: "PFCOUNT", Body: map[string]interface{}{"key": "hll1"}}, | ||
}, | ||
expected: []interface{}{float64(1), float64(0), float64(0), float64(3)}, | ||
delays: []time.Duration{0, 0, 0, 0}, | ||
}, | ||
{ | ||
name: "PFADD with multiple keys", | ||
commands: []HTTPCommand{ | ||
{Command: "PFADD", Body: map[string]interface{}{"key": "hll2", "values": [...]string{"foo", "bar", "zap"}}}, | ||
{Command: "PFADD", Body: map[string]interface{}{"key": "hll2", "values": [...]string{"zap", "zap", "zap"}}}, | ||
{Command: "PFCOUNT", Body: map[string]interface{}{"key": "hll2"}}, | ||
{Command: "PFADD", Body: map[string]interface{}{"key": "some-other-hll", "values": [...]string{"1", "2", "3"}}}, | ||
{Command: "PFCOUNT", Body: map[string]interface{}{"keys": [...]string{"hll2", "some-other-hll"}}}, | ||
}, | ||
expected: []interface{}{float64(1), float64(0), float64(3), float64(1), float64(6)}, | ||
delays: []time.Duration{0, 0, 0, 0, 0}, | ||
}, | ||
{ | ||
name: "PFADD with non-existing key", | ||
commands: []HTTPCommand{ | ||
{Command: "PFADD", Body: map[string]interface{}{"key": "hll3", "values": [...]string{"foo", "bar", "zap"}}}, | ||
{Command: "PFADD", Body: map[string]interface{}{"key": "hll3", "values": [...]string{"zap", "zap", "zap"}}}, | ||
{Command: "PFCOUNT", Body: map[string]interface{}{"key": "hll3"}}, | ||
{Command: "PFCOUNT", Body: map[string]interface{}{"keys": [...]string{"hll3", "non-exist-hll"}}}, | ||
{Command: "PFADD", Body: map[string]interface{}{"key": "some-new-hll", "value": "abc"}}, | ||
{Command: "PFCOUNT", Body: map[string]interface{}{"keys": [...]string{"hll3", "non-exist-hll", "some-new-hll"}}}, | ||
}, | ||
expected: []interface{}{float64(1), float64(0), float64(3), float64(3), float64(1), float64(4)}, | ||
delays: []time.Duration{0, 0, 0, 0, 0, 0}, | ||
}, | ||
{ | ||
name: "PFMERGE with srcKey non-existing", | ||
commands: []HTTPCommand{ | ||
{Command: "PFMERGE", Body: map[string]interface{}{"key": "NON_EXISTING_SRC_KEY"}}, | ||
{Command: "PFCOUNT", Body: map[string]interface{}{"key": "NON_EXISTING_SRC_KEY"}}, | ||
}, | ||
expected: []interface{}{"OK", float64(0)}, | ||
delays: []time.Duration{0, 0}, | ||
}, | ||
{ | ||
name: "PFMERGE with destKey non-existing", | ||
commands: []HTTPCommand{ | ||
{Command: "PFMERGE", Body: map[string]interface{}{"keys": []string{"EXISTING_SRC_KEY", "NON_EXISTING_SRC_KEY"}}}, | ||
{Command: "PFCOUNT", Body: map[string]interface{}{"key": "EXISTING_SRC_KEY"}}, | ||
}, | ||
expected: []interface{}{"OK", float64(0)}, | ||
delays: []time.Duration{0, 0}, | ||
}, | ||
{ | ||
name: "PFMERGE with destKey existing", | ||
commands: []HTTPCommand{ | ||
{Command: "PFADD", Body: map[string]interface{}{"key": "DEST_KEY_1", "values": [...]string{"foo", "bar", "zap", "a"}}}, | ||
{Command: "PFADD", Body: map[string]interface{}{"key": "DEST_KEY_2", "values": [...]string{"a", "b", "c", "foo"}}}, | ||
{Command: "PFMERGE", Body: map[string]interface{}{"keys": [...]string{"SRC_KEY_1", "DEST_KEY_1", "DEST_KEY_2"}}}, | ||
{Command: "PFCOUNT", Body: map[string]interface{}{"key": "SRC_KEY_1"}}, | ||
}, | ||
expected: []interface{}{float64(1), float64(1), "OK", float64(6)}, | ||
delays: []time.Duration{0, 0, 0, 0}, | ||
}, | ||
{ | ||
name: "PFMERGE with only one destKey existing", | ||
commands: []HTTPCommand{ | ||
{Command: "PFADD", Body: map[string]interface{}{"key": "DEST_KEY_3", "values": [...]string{"foo", "bar", "zap", "a"}}}, | ||
{Command: "PFMERGE", Body: map[string]interface{}{"keys": [...]string{"SRC_KEY_2", "DEST_KEY_3", "NON_EXISTING_DEST_KEY"}}}, | ||
{Command: "PFCOUNT", Body: map[string]interface{}{"key": "SRC_KEY_2"}}, | ||
}, | ||
expected: []interface{}{float64(1), "OK", float64(4)}, | ||
delays: []time.Duration{0, 0, 0}, | ||
}, | ||
{ | ||
name: "PFMERGE with invalid object", | ||
commands: []HTTPCommand{ | ||
{Command: "PFADD", Body: map[string]interface{}{"key": "INVALID_HLL", "values": [...]string{"a", "b", "c"}}}, | ||
{Command: "SET", Body: map[string]interface{}{"key": "INVALID_HLL", "value": "1"}}, | ||
{Command: "PFMERGE", Body: map[string]interface{}{"key": "INVALID_HLL"}}, | ||
}, | ||
expected: []interface{}{float64(1), "OK", "WRONGTYPE Key is not a valid HyperLogLog string value."}, | ||
delays: []time.Duration{0, 0, 0}, | ||
}, | ||
{ | ||
name: "PFMERGE with invalid src object", | ||
commands: []HTTPCommand{ | ||
{Command: "PFADD", Body: map[string]interface{}{"key": "INVALID_SRC_HLL", "values": [...]string{"a", "b", "c"}}}, | ||
{Command: "SET", Body: map[string]interface{}{"key": "INVALID_SRC_HLL", "value": "1"}}, | ||
{Command: "PFMERGE", Body: map[string]interface{}{"keys": [...]string{"HLL", "INVALID_SRC_HLL"}}}, | ||
}, | ||
expected: []interface{}{float64(1), "OK", "WRONGTYPE Key is not a valid HyperLogLog string value."}, | ||
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, err := exec.FireCommand(cmd) | ||
if err != nil { | ||
// Check if the error message matches the expected result | ||
assert.Equal(t, tc.expected[i], err.Error(), "Error message mismatch for cmd %s", cmd) | ||
} else { | ||
assert.Equal(t, tc.expected[i], result, "Value mismatch for cmd %s, expected %v, got %v", cmd, tc.expected[i], result) | ||
} | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.