cache_test.go
cache_test.go - Overview
This file contains unit tests for the in-memory cache implementation. It tests the functionalities of creating a new cache, connecting to the cache (which is a no-op in this in-memory implementation), storing data, retrieving data, setting TTL, removing a single entry, and bulk removing entries from the cache.
Detailed Documentation
TestNew
- Purpose: Tests the
New
function which creates a new in-memory cache instance. - Parameters:
t
(*testing.T): Testing context.
- Returns: None
TestConnect
- Purpose: Tests the
Connect
function. In this in-memory implementation, it should returnnil
error. - Parameters:
t
(*testing.T): Testing context.
- Returns: None
TestStore
- Purpose: Tests the
Store
function, ensuring data can be stored in the cache. - Parameters:
t
(*testing.T): Testing context.
- Returns: None
TestRetrieve
- Purpose: Tests the
Retrieve
function, verifying that data can be stored and retrieved correctly. - Parameters:
t
(*testing.T): Testing context.
- Returns: None
TestSetTTL
- Purpose: Tests the
SetTTL
function, ensuring that the TTL (Time To Live) of a cached entry can be updated and that entries expire as expected. - Parameters:
t
(*testing.T): Testing context.
- Returns: None
TestRemove
- Purpose: Tests the
Remove
function, confirming that a specific entry can be removed from the cache. - Parameters:
t
(*testing.T): Testing context.
- Returns: None
TestBulkRemove
- Purpose: Tests the
BulkRemove
function, verifying that multiple entries can be removed from the cache at once. - Parameters:
t
(*testing.T): Testing context.
- Returns: None
TestCache
- Purpose: Tests basic cache operations like store, retrieve and remove.
- Parameters:
t
(*testing.T): Testing context.
- Returns: None
Code Examples
None
Include in Getting Started: NO