Repository navigation
Make runnable examples drop the databases they create - #10
Merged
Merged
Conversation
Examples have no *testing.T, so the runnable ones used a zero testing.T. Its Cleanup accepts functions and never runs them, so every database an example created through Setup or New stayed on the server: twelve per go test run, over two hundred on a developer's machine. exampleT, a small stand-in embedding testing.TB, implements what the library calls and runs the registered cleanups when the example is done, in reverse order as testing does. Cleanup failures print to stdout, so they break the example's expected output and fail it visibly. Compile-only examples keep their zero T; they never execute.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Go examples have no
*testing.T, so the runnableExample_*functions usedt := &testing.T{}. A zerotesting.Tacceptst.Cleanup(...)and never runs it (nothing drives thatT), so every database an example created throughpostgres.Setup/Newstayed on the server: 12 pergo test, and 219 had accumulated on the dev server.The fix is
exampleT, a small stand-in embeddingtesting.TBthat implements only what the library calls (Helper,Cleanup,Context,Failed,Logf,Errorf,Fatalf) and adone()that runs the registered cleanups in reverse order, astestingdoes. Runnable examples becomet := newExampleT(); defer t.done(). Cleanup failures print to stdout, which breaks the example's// Output:and fails it visibly. Compile-only examples keep their zeroT, since they never execute.Verified: the Postgres server holds the same number of databases before and after running every example.