Add README for Redis test helper

This commit is contained in:
RW
2025-11-29 15:58:10 +01:00
parent 1a15196e91
commit d97bfa5028
3 changed files with 84 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
on:
push:
branches:
- master
- main
paths:
- 'testhelpers/tck/**'
pull_request:
paths:
- 'testhelpers/tck/**'
workflow_dispatch:
name: "Tests TestHelper TCK"
jobs:
Tests:
runs-on: ubuntu-latest
strategy:
matrix:
go-version:
- 1.24.x
steps:
- name: Fetch Repository
uses: actions/checkout@v6
- name: Install Go
uses: actions/setup-go@v6
with:
go-version: '${{ matrix.go-version }}'
- name: Run Test
working-directory: testhelpers/tck
run: go test ./... -v -race

19
testhelpers/README.md Normal file
View File

@@ -0,0 +1,19 @@
# Test Helpers
This directory hosts reusable utilities for exercising storage implementations in end-to-end and compatibility testing scenarios. Each helper is maintained as its own Go module so it can be consumed independently.
## Available helpers
- **Redis** (`testhelpers/redis`): Spins up Redis with Testcontainers and exposes convenience functions for running integration tests against Redis-backed storage implementations.
- **Test Compatibility Kit (TCK)** (`testhelpers/tck`): Provides a reusable test suite that validates any `storage.Storage` implementation for correctness and API parity.
## Running tests locally
From the repository root, run tests for a helper by changing into its directory and executing `go test`:
```sh
cd testhelpers/redis
go test ./... -v -race
```
The helpers rely on Docker via [testcontainers-go](https://github.com/testcontainers/testcontainers-go), so ensure Docker is available and running before executing the tests.

View File

@@ -0,0 +1,36 @@
# Redis Test Helper
This module provides utilities for starting a disposable Redis instance with [testcontainers-go](https://github.com/testcontainers/testcontainers-go). It is useful for integration tests against storage implementations that rely on Redis.
## Features
- Starts Redis containers with optional TLS, host/port, address, or URL connection helpers.
- Supports container reuse via `WithReuse` for faster local iteration.
- Exposes connection details (URL, host/port, addresses, TLS config) through the returned `Container` struct.
## Usage
Import the helper and start a Redis container in your tests:
```go
import (
testredis "github.com/klauspost/storage/testhelpers/redis"
)
func TestExample(t *testing.T) {
ctr := testredis.Start(t, "redis:7-alpine")
// Use ctr.URL, ctr.Host/Port, or ctr.TLSConfig in your test code.
}
```
## Running locally
From the repository root, execute the helper's tests:
```sh
cd testhelpers/redis
go test ./... -v -race
```
Docker must be available and running for the tests to start Redis containers.