Skip to main content

exists_test.go

exists_test.go - Overview

This file contains tests for the EXISTS command in the Ironhawk database. The tests verify that the EXISTS command correctly identifies the existence of keys, handles multiple keys, expired keys, duplicate keys, and edge cases with no arguments.

Detailed Documentation

TestExists Function

Purpose: Tests the functionality of the EXISTS command.

Parameters:

  • t (*testing.T): A pointer to the testing object, used for reporting test failures and other test-related functions.

Returns:

  • None.

The function defines a series of test cases, each consisting of a name, a list of commands to execute, a list of expected results, and optional delays to simulate key expiration. It iterates through these test cases, executing the commands against a local database connection and verifying that the actual results match the expected results.

The testCases variable is a slice of TestCase structs, where TestCase is defined (elsewhere, not in this file) as having fields name, commands, expected, and delay.

The test cases cover scenarios such as:

  • Basic existence checks (EXISTS key).
  • Checking multiple keys at once (EXISTS key key2 key3).
  • Testing existence of expired keys.
  • Edge cases like EXISTS with no arguments.
  • EXISTS with duplicate keys.

The runTestcases function (defined elsewhere) is used to execute the test cases against the database.