Documentation
¶
Overview ¶
Package mongotest runs a store's test suite against MongoDB.
It is the document-store counterpart to sqlxtest. MongoDB stays hand-written rather than sharing an implementation with the SQL backends, which makes it the one place where a behaviour can drift unnoticed: most domains ship a MongoDB store with no test that touches a database. A suite written against the domain's Store interface can run on every backend, so a domain's behaviour is asserted once and checked everywhere.
MongoDB runs only when MONGO_TEST_DSN names a reachable server; otherwise the subtest skips. The variable is deliberately not MONGODB_URL — a suite that creates and drops databases should take a separate, explicit opt-in.
Index ¶
Constants ¶
const DSNEnv = "MONGO_TEST_DSN"
DSNEnv names the environment variable holding the test MongoDB connection string.
Variables ¶
This section is empty.
Functions ¶
func DatabaseName ¶
DatabaseName builds a unique database name for a test.
The counter only separates subtests inside one process, and `go test ./...` runs packages in parallel — two packages that happen to share a test name would otherwise create *and drop* the same database. The pid separates them.
MongoDB rejects names of 64 bytes or more, so the test name is bounded rather than concatenated whole: a nested subtest name easily runs past the limit on its own.
Types ¶
This section is empty.