set_test
Overview
The file set_test.go
contains test cases for the SET
command in the Ironhawk database. It tests various functionalities of the SET
command, including setting simple values, integer values, expiry options (EX, PX, PXAT), and conditional setting (NX, XX).
Detailed Documentation
TestSET
Function
Purpose: Tests the functionality of the SET
command with different options and scenarios.
Parameters:
t
:*testing.T
- Testing object for running test cases.
Returns:
- None
The function defines a series of test cases, each with a name, a list of commands to execute, expected results, and optional delays. It then iterates through these test cases, executes the commands against a local Ironhawk client, and verifies that the actual results match the expected results.
The test cases cover scenarios such as:
- Setting and retrieving simple and integer values.
- Overwriting existing keys.
- Setting with expiry options (EX, PX, PXAT) to test time-to-live functionality.
- Using
XX
andNX
options for conditional setting. - Testing invalid syntax and argument counts.
- Using the
GET
option to return the old value. - Testing
KEEPTTL
option and its interactions with other options.
TestCase
struct (From context)
The TestCase
struct is used to define test cases for the Ironhawk commands. Although not defined in this file, it is used in runTestcases
and needs to be documented to understand the TestSET
function.
Purpose: Defines a test case structure for command testing.
Fields:
name
:string
- Name of the test case.commands
:[]string
- A slice of commands to be executed in the test case.expected
:[]interface{}
- A slice of expected results for each command.delay
:[]time.Duration
- A slice of durations to wait between commands (optional).
getLocalConnection
function (From context)
The getLocalConnection
function is used to obtain a local connection to the Ironhawk server. Although not defined in this file, it is crucial for the test setup and needs to be documented to understand the TestSET
function.
Purpose: Establishes a local connection to the Ironhawk server for testing.
Returns:
- A client connection to the local Ironhawk server.
runTestcases
function (From context)
The runTestcases
function is used to execute the test cases against the Ironhawk server and verify the results. Although not defined in this file, it is essential for running the tests and needs to be documented to understand the TestSET
function.
Purpose: Executes a series of test cases against the Ironhawk server and verifies the results.
Parameters:
t
:*testing.T
- Testing object for reporting test failures.client
: A client connection to the Ironhawk server.testCases
:[]TestCase
- A slice ofTestCase
structs representing the test cases to be executed.
Returns:
- None
Code Examples
N/A
Getting Started Relevance
YES