Skip to content

fix(mux-sql): make the quickstart work out of the box with Docker Compose - #244

Open
Lakshay0916 wants to merge 3 commits into
keploy:mainfrom
Lakshay0916:fix/mux-sql-quickstart
Open

Lakshay0916 wants to merge 3 commits into
keploy:mainfrom
Lakshay0916:fix/mux-sql-quickstart

Conversation

@Lakshay0916

Copy link
Copy Markdown

Summary

While following the Mux + Postgres quickstart with Keploy 3.8.x, I hit several issues in the mux-sql sample. This PR fixes them so the documented Docker Compose flow works out of the box, and GET /products returns what the docs show.

Problems and fixes

1. GET /products always returns [] (model.go)
defer handleDeferError(rows.Close()) evaluates rows.Close() immediately, so the rows are closed before the for rows.Next() loop runs. The call is now wrapped in a closure, and rows.Err() is checked after the loop.

2. The app can't reach Postgres under Docker Compose (main.go, app.go, docker-compose.yml)
main.go hardcodes localhost, but inside Compose the database is at postgres. The docs' Docker steps don't mention editing this, so keploy record fails as documented. The host and port now come from DB_HOST / DB_PORT (defaulting to localhost / 5432, so native runs are unchanged), and docker-compose.yml sets DB_HOST=postgres.

3. docker compose up fails on a fresh machine
The compose file declared keploy-network as external, 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 older keploy-network already 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 up reuses a previously built image, so keploy test kept testing old code after edits. pull_policy: build rebuilds (from cache) on every run.

6. Shipped recordings fail on Keploy 3.x
keploy/test-set-0 uses the old Postgres mock 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 /products output, added the Docker Compose flow, and documented the new environment variables.

Also removed the obsolete version key 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 50 on a clean checkout (no network created, no code edits): app starts, POST /product, GET /products, and GET /product/1 all return the expected responses, with /products now 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).
  • Changed a JSON tag and re-ran keploy test without a manual docker compose build: the change was picked up and the tests failed as expected, confirming pull_policy: build.
  • go vet, go build, and the existing go test ./... pass (Go 1.20, the Dockerfile's image); golangci-lint v2.13.2 with the repo's .golangci.yml reports 0 issues.
  • Not tested: the native Linux/WSL flow (no Linux machine available). The native defaults are unchanged (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 writes keploy/test-set-0/tests/<route>-1.yaml and keploy/test-set-0/mocks.yaml; happy to send a separate docs PR for that.

Copilot AI balanced review requested due to automatic review settings September 30, 2026 18:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…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
Lakshay0916 force-pushed the fix/mux-sql-quickstart branch from 9f9d3cd to 0203f47 Compare September 30, 2026 18:04
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.

2 participants