-
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.
#735: tests: COMMAND GETKEYS, COMMAND INFO, COMMAND LIST, COMMAND REN…
…AME, COPY (#768)
- Loading branch information
1 parent
4eaef20
commit 3795c7d
Showing
6 changed files
with
412 additions
and
3 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
integration_tests/commands/http/command_getkeys_test.go
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,107 @@ | ||
package http | ||
|
||
import ( | ||
"testing" | ||
|
||
"gotest.tools/v3/assert" | ||
) | ||
|
||
func TestCommandGetKeys(t *testing.T) { | ||
exec := NewHTTPCommandExecutor() | ||
|
||
testCases := []TestCase{ | ||
{ | ||
name: "Set command", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/GETKEYS", Body: map[string]interface{}{"key": "SET", "keys": []interface{}{"1", "2"}, "values": []interface{}{"2", "3"}}}, | ||
}, | ||
expected: []interface{}{[]interface{}{"1"}}, | ||
}, | ||
{ | ||
name: "Get command", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/GETKEYS", Body: map[string]interface{}{"key": "GET", "field": "key"}}, | ||
}, | ||
expected: []interface{}{[]interface{}{"key"}}, | ||
}, | ||
{ | ||
name: "TTL command", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/GETKEYS", Body: map[string]interface{}{"key": "TTL", "field": "key"}}, | ||
}, | ||
expected: []interface{}{[]interface{}{"key"}}, | ||
}, | ||
{ | ||
name: "Del command", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/GETKEYS", Body: map[string]interface{}{"key": "DEL", "field": "1 2 3 4 5 6 7"}}, | ||
}, | ||
expected: []interface{}{[]interface{}{"1 2 3 4 5 6 7"}}, | ||
}, | ||
{ | ||
name: "MSET command", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/GETKEYS", Body: map[string]interface{}{"key": "MSET", "keys": []interface{}{"key1 key2"}, "values": []interface{}{" val1 val2"}}}, | ||
}, | ||
expected: []interface{}{[]interface{}{"key1 key2"}}, | ||
}, | ||
{ | ||
name: "Expire command", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/GETKEYS", Body: map[string]interface{}{"key": "EXPIRE", "field": "key", "values": []interface{}{"time", "extra"}}}, | ||
}, | ||
expected: []interface{}{[]interface{}{"key"}}, | ||
}, | ||
{ | ||
name: "BFINIT command", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/GETKEYS", Body: map[string]interface{}{"key": "BFINIT", "field": "bloom", "values": []interface{}{"some", "parameters"}}}, | ||
}, | ||
expected: []interface{}{[]interface{}{"bloom"}}, | ||
}, | ||
{ | ||
name: "PING command", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/GETKEYS", Body: map[string]interface{}{"key": "PING"}}, | ||
}, | ||
expected: []interface{}{"ERR the command has no key arguments"}, | ||
}, | ||
{ | ||
name: "Invalid Get command", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/GETKEYS", Body: map[string]interface{}{"key": "GET"}}, | ||
}, | ||
expected: []interface{}{"ERR invalid number of arguments specified for command"}, | ||
}, | ||
{ | ||
name: "Abort command", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/GETKEYS", Body: map[string]interface{}{"key": "ABORT"}}, | ||
}, | ||
expected: []interface{}{"ERR the command has no key arguments"}, | ||
}, | ||
{ | ||
name: "Invalid command", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/GETKEYS", Body: map[string]interface{}{"key": "NotValidCommand"}}, | ||
}, | ||
expected: []interface{}{"ERR invalid command specified"}, | ||
}, | ||
{ | ||
name: "Wrong number of arguments", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/GETKEYS", Body: map[string]interface{}{"key": ""}}, | ||
}, | ||
expected: []interface{}{"ERR invalid command specified"}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
for i, cmd := range tc.commands { | ||
result, _ := exec.FireCommand(cmd) | ||
assert.DeepEqual(t, tc.expected[i], result) | ||
} | ||
}) | ||
} | ||
} |
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,71 @@ | ||
package http | ||
|
||
import ( | ||
"testing" | ||
|
||
"gotest.tools/v3/assert" | ||
) | ||
|
||
func TestCommandInfo(t *testing.T) { | ||
exec := NewHTTPCommandExecutor() | ||
|
||
testCases := []TestCase{ | ||
{ | ||
name: "Set command", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/INFO", Body: map[string]interface{}{"key": "SET"}}, | ||
}, | ||
expected: []interface{}{[]interface{}{[]interface{}{"SET", float64(-3), float64(1), float64(0), float64(0)}}}, | ||
}, | ||
{ | ||
name: "Get command", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/INFO", Body: map[string]interface{}{"key": "GET"}}, | ||
}, | ||
expected: []interface{}{[]interface{}{[]interface{}{"GET", float64(2), float64(1), float64(0), float64(0)}}}, | ||
}, | ||
{ | ||
name: "PING command", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/INFO", Body: map[string]interface{}{"key": "PING"}}, | ||
}, | ||
expected: []interface{}{[]interface{}{[]interface{}{"PING", float64(-1), float64(0), float64(0), float64(0)}}}, | ||
}, | ||
{ | ||
name: "Invalid command", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/INFO", Body: map[string]interface{}{"key": "INVALID_CMD"}}, | ||
}, | ||
expected: []interface{}{[]interface{}{"(nil)"}}, | ||
}, | ||
{ | ||
name: "Combination of valid and Invalid command", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/INFO", Body: map[string]interface{}{"keys": []interface{}{"SET", "INVALID_CMD"}}}, | ||
}, | ||
expected: []interface{}{[]interface{}{ | ||
[]interface{}{"SET", float64(-3), float64(1), float64(0), float64(0)}, | ||
"(nil)", | ||
}}, | ||
}, | ||
{ | ||
name: "Combination of multiple valid commands", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/INFO", Body: map[string]interface{}{"keys": []interface{}{"SET", "GET"}}}, | ||
}, | ||
expected: []interface{}{[]interface{}{ | ||
[]interface{}{"SET", float64(-3), float64(1), float64(0), float64(0)}, | ||
[]interface{}{"GET", float64(2), float64(1), float64(0), float64(0)}, | ||
}}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
for i, cmd := range tc.commands { | ||
result, _ := exec.FireCommand(cmd) | ||
assert.DeepEqual(t, tc.expected[i], result) | ||
} | ||
}) | ||
} | ||
} |
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,37 @@ | ||
package http | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"gotest.tools/v3/assert" | ||
) | ||
|
||
func TestCommandList(t *testing.T) { | ||
exec := NewHTTPCommandExecutor() | ||
|
||
testCases := []TestCase{ | ||
{ | ||
name: "Command list should not be empty", | ||
commands: []HTTPCommand{ | ||
{Command: "COMMAND/LIST", Body: map[string]interface{}{"key": ""}}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
for _, cmd := range tc.commands { | ||
result, _ := exec.FireCommand(cmd) | ||
var commandList []string | ||
for _, v := range result.([]interface{}) { | ||
commandList = append(commandList, v.(string)) | ||
} | ||
|
||
assert.Assert(t, len(commandList) > 0, | ||
fmt.Sprintf("Unexpected number of CLI commands found. expected greater than 0, %d found", len(commandList))) | ||
} | ||
|
||
}) | ||
} | ||
} |
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,69 @@ | ||
package http | ||
|
||
import ( | ||
"testing" | ||
|
||
"gotest.tools/v3/assert" | ||
) | ||
|
||
func TestCommandRename(t *testing.T) { | ||
exec := NewHTTPCommandExecutor() | ||
|
||
testCases := []TestCase{ | ||
{ | ||
name: "Set key and Rename key", | ||
commands: []HTTPCommand{ | ||
{Command: "SET", Body: map[string]interface{}{"key": "sourceKey", "value": "hello"}}, | ||
{Command: "GET", Body: map[string]interface{}{"key": "sourceKey"}}, | ||
{Command: "RENAME", Body: map[string]interface{}{"keys": []interface{}{"sourceKey", "destKey"}}}, | ||
{Command: "GET", Body: map[string]interface{}{"key": "destKey"}}, | ||
{Command: "GET", Body: map[string]interface{}{"key": "sourceKey"}}, | ||
}, | ||
expected: []interface{}{"OK", "hello", "OK", "hello", "(nil)"}, | ||
}, | ||
{ | ||
name: "same key for source and destination on Rename", | ||
commands: []HTTPCommand{ | ||
{Command: "SET", Body: map[string]interface{}{"key": "Key", "value": "hello"}}, | ||
{Command: "GET", Body: map[string]interface{}{"key": "Key"}}, | ||
{Command: "RENAME", Body: map[string]interface{}{"keys": []interface{}{"Key", "Key"}}}, | ||
{Command: "GET", Body: map[string]interface{}{"key": "Key"}}, | ||
}, | ||
expected: []interface{}{"OK", "hello", "OK", "hello"}, | ||
}, | ||
{ | ||
name: "If source key doesn't exists", | ||
commands: []HTTPCommand{ | ||
{Command: "RENAME", Body: map[string]interface{}{"keys": []interface{}{"unknownKey", "Key"}}}, | ||
}, | ||
expected: []interface{}{"ERR no such key"}, | ||
}, | ||
{ | ||
name: "If source key doesn't exists and renaming the same key to the same key", | ||
commands: []HTTPCommand{ | ||
{Command: "RENAME", Body: map[string]interface{}{"keys": []interface{}{"unknownKey", "unknownKey"}}}, | ||
}, | ||
expected: []interface{}{"ERR no such key"}, | ||
}, | ||
{ | ||
name: "If destination Key already presents", | ||
commands: []HTTPCommand{ | ||
{Command: "SET", Body: map[string]interface{}{"key": "destinationKey", "value": "world"}}, | ||
{Command: "SET", Body: map[string]interface{}{"key": "newKey", "value": "hello"}}, | ||
{Command: "RENAME", Body: map[string]interface{}{"keys": []interface{}{"newKey", "destinationKey"}}}, | ||
{Command: "GET", Body: map[string]interface{}{"key": "newKey"}}, | ||
{Command: "GET", Body: map[string]interface{}{"key": "destinationKey"}}, | ||
}, | ||
expected: []interface{}{"OK", "OK", "OK", "(nil)", "hello"}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
for i, cmd := range tc.commands { | ||
result, _ := exec.FireCommand(cmd) | ||
assert.DeepEqual(t, tc.expected[i], result) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.