fix(mux-sql): make the quickstart work out of the box with Docker Compose - #244
Open
Lakshay0916 wants to merge 3 commits into
Open
Lakshay0916 wants to merge 3 commits into
Lakshay0916 wants to merge 3 commits into
Conversation
…pose - getProducts: wrap the deferred rows.Close() in a closure. The argument was evaluated immediately, closing the rows before the loop, so GET /products always returned []. Also check rows.Err(). - Read the Postgres host/port from DB_HOST/DB_PORT (defaults localhost/5432); docker-compose.yml sets DB_HOST=postgres, so main.go no longer needs editing. - Drop the external keploy-network (Compose's default network works with Keploy 3.x and needs no manual 'docker network create'). - Make the published Postgres port overridable via POSTGRES_HOST_PORT. - Set pull_policy: build so code changes are rebuilt before keploy test. - Remove the obsolete compose 'version' key. Signed-off-by: Lakshay0916 <lakshaysinghal2006@gmail.com>
They use the old 'Postgres' mock format and all fail on replay with
Keploy 3.x ("session RecordedIndex missing PostgresV3Session mock").
Signed-off-by: Lakshay0916 <lakshaysinghal2006@gmail.com>
Correct the app description (product catalog, not a URL shortener), fix typos and a broken code block, update the /products output, and document DB_HOST, DB_PORT and POSTGRES_HOST_PORT. Signed-off-by: Lakshay0916 <lakshaysinghal2006@gmail.com>
Lakshay0916
force-pushed
the
fix/mux-sql-quickstart
branch
from
September 30, 2026 18:04
9f9d3cd to
0203f47
Compare
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
While following the Mux + Postgres quickstart with Keploy 3.8.x, I hit several issues in the
mux-sqlsample. This PR fixes them so the documented Docker Compose flow works out of the box, andGET /productsreturns what the docs show.Problems and fixes
1.
GET /productsalways returns[](model.go)defer handleDeferError(rows.Close())evaluatesrows.Close()immediately, so the rows are closed before thefor rows.Next()loop runs. The call is now wrapped in a closure, androws.Err()is checked after the loop.2. The app can't reach Postgres under Docker Compose (
main.go,app.go,docker-compose.yml)main.gohardcodeslocalhost, but inside Compose the database is atpostgres. The docs' Docker steps don't mention editing this, sokeploy recordfails as documented. The host and port now come fromDB_HOST/DB_PORT(defaulting tolocalhost/5432, so native runs are unchanged), anddocker-compose.ymlsetsDB_HOST=postgres.3.
docker compose upfails on a fresh machineThe compose file declared
keploy-networkasexternal, so it had to be created by hand first (the docs don't mention this). With Keploy 3.x the sample works on Compose's default network, so the custom network is removed. I checked that this also works when an olderkeploy-networkalready exists.4. Port clash on 5432
Anyone with a local Postgres can't start the sample. The published port is now
${POSTGRES_HOST_PORT:-5432}, so the default is unchanged but easy to override.5. Code changes are silently ignored on replay
docker compose upreuses a previously built image, sokeploy testkept testing old code after edits.pull_policy: buildrebuilds (from cache) on every run.6. Shipped recordings fail on Keploy 3.x
keploy/test-set-0uses the oldPostgresmock format; replaying it with Keploy 3.8.49 fails all 3 tests (session RecordedIndex missing PostgresV3Session mock). Removed, since users generate their own recordings in the quickstart.7. README
Corrected the description (it said "URL shortener"), fixed typos and a broken code block, updated the
/productsoutput, added the Docker Compose flow, and documented the new environment variables.Also removed the obsolete
versionkey from the compose file. Line endings (CRLF) of the compose file and README are preserved to keep the diff small.Verification
keploy record -c "docker compose up" --container-name "muxSqlApp" --build-delay 50on a clean checkout (no network created, no code edits): app starts,POST /product,GET /products, andGET /product/1all return the expected responses, with/productsnow returning[{"id":1,"name":"Bubbles","price":123}].keploy test -c "docker compose up" --container-name "muxSqlApp" --build-delay 50 --delay 10: 3/3 passed (Keploy 3.8.49, macOS, Docker 29.2.1).keploy testwithout a manualdocker compose build: the change was picked up and the tests failed as expected, confirmingpull_policy: build.go vet,go build, and the existinggo test ./...pass (Go 1.20, the Dockerfile's image);golangci-lintv2.13.2 with the repo's.golangci.ymlreports 0 issues.localhost:5432).Notes
With this change the existing docs page works as written for the Docker flow. The docs still list the generated files as
test-1.yml/mocks.yml, while Keploy 3.x writeskeploy/test-set-0/tests/<route>-1.yamlandkeploy/test-set-0/mocks.yaml; happy to send a separate docs PR for that.