Add a complete runnable Postgres example (fixes #24) - #38
Open
peczenyj wants to merge 2 commits into
Open
Conversation
A self-contained, fully commented walkthrough of the record/playback workflow, including a committed recording so 'go test ./examples/pq' passes with no database, and a context.Context demonstration. Addresses cockroachdb#24.
Member
Open
Author
|
Hey guys, anything wrong with this pull request? |
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.
Summary
Fixes #24.
This adds a complete, self-contained, runnable example under
examples/pq, aimed at newcomers:app.go— ordinary application code (no copyist imports): a plain query function and acontext.Context-aware variant.app_test.go— a heavily commented walkthrough of the whole workflow:Register,SetSessionInit,TestMainwiring,defer copyist.Open(t).Close(), and opening through thecopyist_postgresdriver. The comments are the documentation; the file reads top-to-bottom without needing any other file.testdata/app_test.copyist— a committed recording, sogo test ./examples/pqpasses immediately after cloning with no database, no Docker, no network. Re-recording is one command (go test ./examples/pq -record); the test starts a throwawaypostgres:16container itself via the existingdrivertest/dockerdbhelper, which also keepsmake test(which deletes and re-records all recordings) working.It also answers the second question in #24:
context.Contextneeds no mocking — copyist forwards contexts to the wrapped driver untouched, andTestQueryNameAtdemonstrates aQueryRowContextcall recorded and played back like any other.Test Plan
go test ./examples/pqpasses with no database running (playback from the committed recording)go test ./examples/pq -recordrecords against a real Postgres in Docker and regenerates the recordinggo test ./...at root passes (the example is part of the root module, so existing CI covers it on Go 1.18)gofmt/go vetclean🤖 Generated with Claude Code