From d97bfa50286718aa588ef3a322dababac4d8d09b Mon Sep 17 00:00:00 2001 From: RW Date: Sat, 29 Nov 2025 15:58:10 +0100 Subject: [PATCH] Add README for Redis test helper --- .github/workflows/test-testhelpers-tck.yml | 29 +++++++++++++++++ testhelpers/README.md | 19 ++++++++++++ testhelpers/redis/README.md | 36 ++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 .github/workflows/test-testhelpers-tck.yml create mode 100644 testhelpers/README.md create mode 100644 testhelpers/redis/README.md diff --git a/.github/workflows/test-testhelpers-tck.yml b/.github/workflows/test-testhelpers-tck.yml new file mode 100644 index 00000000..618ac113 --- /dev/null +++ b/.github/workflows/test-testhelpers-tck.yml @@ -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 diff --git a/testhelpers/README.md b/testhelpers/README.md new file mode 100644 index 00000000..aace183c --- /dev/null +++ b/testhelpers/README.md @@ -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. diff --git a/testhelpers/redis/README.md b/testhelpers/redis/README.md new file mode 100644 index 00000000..78135fb4 --- /dev/null +++ b/testhelpers/redis/README.md @@ -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.