command_info_test.go - Overview
This file contains test functions for the COMMAND INFO
functionality, verifying the information returned for various commands. It includes tests for valid commands like SET
, GET
, and PING
, as well as invalid commands, and combinations thereof. It also includes a benchmark test to evaluate the performance of the COMMAND INFO
command.
Detailed Documentation
getInfoTestCases
var getInfoTestCases = []struct {
name string
inCmd string
expected interface{}
}
- Purpose: Defines a set of test cases for the
COMMAND INFO
command. Each test case includes a name, the input command string, and the expected result.name
: A descriptive name for the test case.inCmd
: The input command string to be tested.expected
: The expected result from theCOMMAND INFO
command.
TestCommandInfo
func TestCommandInfo(t *testing.T) {
client := getLocalConnection()
defer client.Close()
for _, tc := range getInfoTestCases {
t.Run(tc.name, func(t *testing.T) {
result := client.FireString("COMMAND INFO " + tc.inCmd)
assert.Equal(t, tc.expected, result)
})
}
}
- Purpose: Tests the
COMMAND INFO
functionality by iterating through thegetInfoTestCases
and verifying that the actual result matches the expected result.- Parameters:
t
: A pointer to atesting.T
object, used for running and reporting test results.
- Returns: None.
- Parameters:
BenchmarkCommandInfo
func BenchmarkCommandInfo(b *testing.B) {
client := getLocalConnection()
defer client.Close()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, tc := range getInfoTestCases {
client.FireString("COMMAND INFO " + tc.inCmd)
}
}
}
- Purpose: Benchmarks the performance of the
COMMAND INFO
command by repeatedly executing it with different input commands.- Parameters:
b
: A pointer to atesting.B
object, used for running and reporting benchmark results.
- Returns: None.
- Parameters: