Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#735: tests: COMMAND GETKEYS, COMMAND INFO, COMMAND LIST, COMMAND RENAME, COPY #768

Merged
merged 6 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions integration_tests/commands/http/command_getkeys_test.go
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)
}
})
}
}
71 changes: 71 additions & 0 deletions integration_tests/commands/http/command_info_test.go
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)
}
})
}
}
37 changes: 37 additions & 0 deletions integration_tests/commands/http/command_list_test.go
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)))
}

})
}
}
69 changes: 69 additions & 0 deletions integration_tests/commands/http/command_rename_test.go
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)
}
})
}
}
Loading