You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Part of the easymongo refactor (see PLAN.md on the refactor branch). Agreed with the maintainer: keep one container per test function; do not consolidate into a shared container.
Working context (read this first)
Repository github.com/tophergopher/easymongo. Start from branch claude/mongotest-easymongo-refactor-wu2vhm; create a branch issue-<number>-<short-slug> from it and open a pull request back into it. PLAN.md on that branch is the source of truth; read it before writing code.
Go project, single module, all packages at the repo root except the new easymongotest/ subpackage. The final toolchain target is Go 1.27 (set by Toolchain: go 1.27, latest dependencies, tidy, remove replace directives #10); any Go 1.24 or newer works until then. Before pushing: gofmt -l . prints nothing, go vet ./..., go test -race ./....
The existing test suite (*_test.go at the root, package easymongo_test, every test function calling setup(t) from common_test.go) is the regression net for this refactor. It must pass after your change. It needs a Docker daemon reachable through the normal Docker environment and the mongo:8 image.
Method is test-driven: write the tests listed under "Tests first", confirm they fail for the expected reason, then implement. Never delete, skip or weaken an existing test to get green; if a test must change because the public API changed (for example primitive.ObjectID to bson.ObjectID), change only the types.
Commit messages: imperative summary line, blank line, body explaining why. Mention this issue number in the pull request description.
Scope
common_test.go: replace mongotest.NewTestConnection(true) / conn.KillMongoContainer() with easymongotest.Run(t); conn becomes *easymongotest.TestConnection so the embedded *easymongo.Connection methods (Database, D, Ping, MongoURI, DatabaseNames) keep working for the ten test functions (aggregate_test.go, connect_test.go, database_test.go, delete_query_test.go, find_and_query_test.go, find_distinct_test.go, find_query_test.go, index_test.go, insert_query_test.go, update_query_test.go).
setup(t) / teardown(t) can shrink to conn = easymongotest.Run(t) since Run registers cleanup; keep the helper names so the ten call sites do not change.
connect_test.go currently imports logrus for a logger fixture; replace with a small test logger implementing easymongo.Logger (also unblocks dropping logrus).
Remove the direct github.com/tophergopher/mongotest (v1 path) requirement from go.mod.
Implementation details
Current common_test.go (for reference; rewrite it):
varconn*easymongotest.TestConnectionfuncsetup(t*testing.T) { t.Helper(); conn=easymongotest.Run(t) }
functeardown(t*testing.T) { t.Helper() } // kept so call sites compile; Run already registers cleanup
createBatmanArchive(t) and the enemy fixture stay as they are (only the primitive import changes later in #4). connect_test.go builds a logrus logger for ConnectWith(...).Logger(...); replace it with:
After the change run go test -race -count=1 ./... && docker ps -a --filter label=mongotest=regression -q | wc -l and confirm the count is 0.
Tests first
This issue is itself the test change. Acceptance is the full suite:
go test -race ./... passes against Docker with the same ten containers started and removed (verify no mongotest=regression containers remain after the run).
Acceptance
No *_test.go file imports github.com/tophergopher/mongotest directly; they go through easymongotest.
Part of the easymongo refactor (see
PLAN.mdon the refactor branch). Agreed with the maintainer: keep one container per test function; do not consolidate into a shared container.Working context (read this first)
github.com/tophergopher/easymongo. Start from branchclaude/mongotest-easymongo-refactor-wu2vhm; create a branchissue-<number>-<short-slug>from it and open a pull request back into it.PLAN.mdon that branch is the source of truth; read it before writing code.easymongotest/subpackage. The final toolchain target is Go 1.27 (set by Toolchain: go 1.27, latest dependencies, tidy, remove replace directives #10); any Go 1.24 or newer works until then. Before pushing:gofmt -l .prints nothing,go vet ./...,go test -race ./....*_test.goat the root, packageeasymongo_test, every test function callingsetup(t)fromcommon_test.go) is the regression net for this refactor. It must pass after your change. It needs a Docker daemon reachable through the normal Docker environment and themongo:8image.*mongo.Clienttype flows fromConnectiontoDatabasetoCollection), so the four driver issues Driver v2: migrate connect.go (mongo.Connect, Disconnect, BSONOptions, write concern) #2, Driver v2: options struct literals become builders; drop MaxTime; ArrayFilters and Delete option changes #3, Driver v2: primitive package merged into bson; replace x/bsonx in index.go #4 and Driver v2: Distinct returns a DistinctResult that must be decoded #5 land together in one pull request, worked in that order. Before them, New easymongotest subpackage wrapping mongotest/v2 #7 and Switch the easymongo test suite to easymongotest #8 must land so the test suite no longer depends on the oldgithub.com/tophergopher/mongotestv0.1.0 module (which itself imports easymongo and breaks the moment easymongo's types change). Until mongotest'sv2module is tagged, use a localreplace github.com/tophergopher/mongotest/v2 => ../mongotest/v2ingo.modand say so in the pull request; Toolchain: go 1.27, latest dependencies, tidy, remove replace directives #10 removes it.primitive.ObjectIDtobson.ObjectID), change only the types.Scope
common_test.go: replacemongotest.NewTestConnection(true)/conn.KillMongoContainer()witheasymongotest.Run(t);connbecomes*easymongotest.TestConnectionso the embedded*easymongo.Connectionmethods (Database,D,Ping,MongoURI,DatabaseNames) keep working for the ten test functions (aggregate_test.go,connect_test.go,database_test.go,delete_query_test.go,find_and_query_test.go,find_distinct_test.go,find_query_test.go,index_test.go,insert_query_test.go,update_query_test.go).setup(t)/teardown(t)can shrink toconn = easymongotest.Run(t)sinceRunregisters cleanup; keep the helper names so the ten call sites do not change.connect_test.gocurrently imports logrus for a logger fixture; replace with a small test logger implementingeasymongo.Logger(also unblocks dropping logrus).github.com/tophergopher/mongotest(v1 path) requirement fromgo.mod.Implementation details
Current
common_test.go(for reference; rewrite it):New version:
createBatmanArchive(t)and theenemyfixture stay as they are (only theprimitiveimport changes later in #4).connect_test.gobuilds a logrus logger forConnectWith(...).Logger(...); replace it with:After the change run
go test -race -count=1 ./... && docker ps -a --filter label=mongotest=regression -q | wc -land confirm the count is 0.Tests first
This issue is itself the test change. Acceptance is the full suite:
go test -race ./...passes against Docker with the same ten containers started and removed (verify nomongotest=regressioncontainers remain after the run).Acceptance
*_test.gofile importsgithub.com/tophergopher/mongotestdirectly; they go througheasymongotest.Depends on: #7.