Skip to content

Add Register and Lookup - #23

Merged
winebarrel merged 1 commit into
mainfrom
sandpit-registry
Nov 8, 2026
Merged

winebarrel merged 1 commit into
mainfrom
sandpit-registry

Conversation

@winebarrel

Copy link
Copy Markdown
Owner

Summary

  • Add Register, which makes a *Sandpit available under a name, and Lookup, which returns it, so that tests can choose a database by name.
  • Register takes a *Sandpit rather than a DSN, so one made with NewWithConfig can be registered too, and With() works on what Lookup returns.
  • Register panics on a nil Sandpit or a name that is already registered, and Lookup panics on an unknown name.
  • Register and Lookup are safe for concurrent use.
  • Update docs, README and tests.
// internal/testdb/testdb.go
func init() {
	pgsandpit.Register("testdb1", pgsandpit.New("postgres://xxx"))
}

// a test package
import _ "example.com/myapp/internal/testdb"

func TestFoo(t *testing.T) {
	s := pgsandpit.Lookup("testdb1").Session(t)
	// ...
}

Each test package runs in its own process, so the registrations are shared by a package that registers them in init, not by the registry itself.

There is no function to close every registered Sandpit. Lookup(name).Close() closes one.

Test plan

  • make vet
  • go test -race -count=1 ./...
  • go test -race -count=20 -run 'TestRegister|TestLookup' ./...
  • golangci-lint run

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.75%. Comparing base (3eee5a1) to head (84bd1fa).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #23      +/-   ##
==========================================
+ Coverage   92.44%   92.75%   +0.31%     
==========================================
  Files           6        7       +1     
  Lines         344      359      +15     
==========================================
+ Hits          318      333      +15     
  Misses         14       14              
  Partials       12       12              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@winebarrel
winebarrel merged commit 4a4435d into main Nov 8, 2026
4 checks passed
@winebarrel
winebarrel deleted the sandpit-registry branch November 8, 2026 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant