Skip to content

Cache and Storage Tests

Cache and storage tests should use local drivers by default.

Use backend integration tests only when backend-specific behavior matters.

Cache Tests

Use memory, file, or null cache for local tests:

text
CACHE_SUPPORTED_DRIVERS=memory,file,null
CACHE_DRIVER=memory

Test cache behavior as derived state:

  • cache miss
  • cache hit
  • TTL behavior when relevant
  • invalidation
  • fallback to source-of-truth data

Do not test business correctness only through cache.

Storage Tests

Use local or memory storage for local tests:

text
STORAGE_SUPPORTED_DRIVERS=local,memory
STORAGE_DRIVER=local
STORAGE_ROOT=/tmp/app-storage-test

Test:

  • path normalization
  • writes
  • reads
  • deletes
  • generated URLs when supported
  • missing file behavior

Backend Tests

Use integration tests for Redis, S3, GCS, FTP, SFTP, SQL-backed cache, and other backend-specific behavior.

Keep those tests explicit and isolated because they may need containers, emulators, credentials, or network access.

Verify

With the relevant generated component enabled and the local driver environment set for the test process, run the owning package tests:

bash
CACHE_DRIVER=memory STORAGE_DRIVER=local STORAGE_ROOT=/tmp/app-storage-test go test ./internal/...

Expected result: packages that exercise cache or storage report ok without requiring a remote backend. Use a test-owned temporary directory when writing a new test; /tmp/app-storage-test is only a local command example.

Next Steps