Skip to main content

command_getkeys_test

File Name: command_getkeys_test.go

Overview

This file contains test cases for the COMMAND GETKEYS functionality in the ironhawk package. It tests the retrieval of keys associated with different commands and benchmarks the performance of the key retrieval process.

Detailed Documentation

getKeysTestCases

var getKeysTestCases = []struct {
name string
inCmd string
expected interface{}
}
  • Purpose: Defines a set of test cases for the COMMAND GETKEYS functionality. Each test case includes a command string (inCmd) and the expected result (expected).
    • name: A descriptive name for the test case.
    • inCmd: The input command string to be tested.
    • expected: The expected result of the COMMAND GETKEYS command.

TestCommandGetKeys(t *testing.T)

func TestCommandGetKeys(t *testing.T) {
client := getLocalConnection()
defer client.Close()

for _, tc := range getKeysTestCases {
t.Run(tc.name, func(t *testing.T) {
result := client.FireString("COMMAND GETKEYS " + tc.inCmd)
assert.Equal(t, tc.expected, result)
})
}
}
  • Purpose: Tests the COMMAND GETKEYS functionality by iterating through the getKeysTestCases and asserting that the result of COMMAND GETKEYS matches the expected value for each case.
    • Parameters:
      • t: A testing object used to report test failures.
    • Returns: None.

BenchmarkGetKeysMatch(b *testing.B)

func BenchmarkGetKeysMatch(b *testing.B) {
client := getLocalConnection()
defer client.Close()

b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, tc := range getKeysTestCases {
client.FireString("COMMAND GETKEYS " + tc.inCmd)
}
}
}
  • Purpose: Benchmarks the performance of the COMMAND GETKEYS functionality. It iterates through the getKeysTestCases multiple times and measures the time it takes to execute the COMMAND GETKEYS command for each case.
    • Parameters:
      • b: A benchmarking object used to measure the execution time.
    • Returns: None.

Getting Started Relevance