Documentation
¶
Overview ¶
Package testdb is the dockerized MariaDB integration-test harness.
It provides real-database seams for tests that need actual MariaDB behavior (EXPLAIN plans, optimizer choices, SQL semantics) instead of sqlmock. The schema is forum-shaped: it carries exactly the XenForo and add-on tables the API reads, cribbed from production DDL, with production's stock indexes — and deliberately WITHOUT the four indexes proposed by the "Goodbye gRPC" PRD (#112), so that "red" EXPLAIN plans stay reproducible:
- xf_post: no user_id_post_date composite
- xf_nf_rosters_service_record: no idx_relation_id
- xf_nf_rosters_user_award: no idx_relation_id
- xf_nf_rosters_user: no idx_user_id
Tests opt in via the TESTDB_ADDR environment variable (host:port of a MariaDB server, e.g. 127.0.0.1:3310). When it is unset, Open skips the calling test, so a plain `go test ./...` stays green without docker. Use `make test-integration` to spin up the dockerized server and run the full suite against it.
Index ¶
Constants ¶
const ( ActiveAPIKey = "cav7_harness_active" RevokedAPIKey = "cav7_harness_revoked" )
ActiveAPIKey is the raw bearer key seeded with active scopes ("read", "read:tickets"); its hash lives in xf_cav7_api_key. RevokedAPIKey is seeded inactive and must fail validation.
Variables ¶
var IndexDDL string
IndexDDL is the PRD #112 Phase 1 index script (testdb/indexes.sql), embedded verbatim. The file is the in-repo source of truth that the DB admin applies manually to production (issue #122); tests apply it to their own disposable databases to assert the green EXPLAIN plans. It is idempotent (ADD INDEX IF NOT EXISTS) and deliberately separate from the schema: the harness stays unindexed so red plans stay reproducible. The API binary never executes it.
Functions ¶
func Open ¶
Open creates a fresh database on the harness MariaDB server, applies the forum-shaped schema and fixtures, and returns an open handle plus the DSN of the new database (for callers that dial their own connection, e.g. through gorm). The database is uniquely named per call, so tests may freely mutate it — including DDL such as CREATE INDEX — without affecting other tests. It is dropped on test cleanup.
Skips the calling test when TESTDB_ADDR is unset; fails it when the variable is set but the server is unreachable or seeding fails.
Types ¶
This section is empty.