Skip to content

Pass *testing.T to the functions of the builders - #26

Merged
winebarrel merged 1 commit into
mainfrom
builder-func-testing-t
Nov 8, 2026
Merged

winebarrel merged 1 commit into
mainfrom
builder-func-testing-t

Conversation

@winebarrel

Copy link
Copy Markdown
Owner

Summary

  • The functions given to Connector and Conn of DBBuilder and SessionBuilder now take a *testing.T as their first argument, so a function shared by tests, such as one on a SessionBuilder made before the tests run, can report failures without panicking.
  • The t is always the test the session was opened for. When a subtest calls s.With().Conn(...).DB() on its parent's session, the function gets the parent's t, so calling FailNow on it from the subtest does not work properly. Such a function should use the subtest's t from its closure.
  • Breaking change: existing functions must be updated to the new signatures.
  • Remove testify from the samples in the README, including the existing DBBuilder.Conn and TxResults ones.
  • Update docs and tests.
var base = sandpit.With().
	Conn(func(t *testing.T, c *pgx.Conn) {
		if _, err := c.Exec(t.Context(), "SET TIME ZONE 'UTC'"); err != nil {
			t.Fatal(err)
		}
	})

Test plan

  • go vet ./...
  • make test (go test -v -race -count=1 ./...)
  • golangci-lint run

The functions given to Connector and Conn of DBBuilder and SessionBuilder
now take the test the session was opened for as their first argument, so
that a function shared by tests, such as one on a SessionBuilder made
before the tests run, can report failures without panicking.

This is a breaking change.

The samples in the README no longer use testify.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@winebarrel
winebarrel merged commit 61c017e into main Nov 8, 2026
2 checks passed
@winebarrel
winebarrel deleted the builder-func-testing-t branch November 8, 2026 12:04
@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.47%. Comparing base (6f4c90c) to head (e8eb711).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #26   +/-   ##
=======================================
  Coverage   92.47%   92.47%           
=======================================
  Files           7        7           
  Lines         425      425           
=======================================
  Hits          393      393           
  Misses         17       17           
  Partials       15       15           

☔ 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.

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