Follow-up to #119, which added resolveDockerHost in src/remote/remote-controller.ts to auto-swap localhost for host.docker.internal when the docker-escaped host is reachable.
The function currently has no test coverage. We should add tests covering its branches.
Cases to cover
resolveDockerHost(db) should:
- Non-localhost passthrough — return the input
Connectable unchanged when db.isLocalhost() is false.
- Same-hostname passthrough — when
escapeDocker() returns a Connectable whose hostname matches the input (e.g., env.HOSTED=true, which makes escapeDocker() return this), return the original db without attempting to connect.
- Docker host reachable — when
host.docker.internal is reachable and SELECT 1 succeeds, return the escaped Connectable and log the resolution.
- Docker host unreachable — when the probe throws, fall back to the original
db and log the fallback.
- Connection is always closed — the probe connection (
pg.close()) is invoked in both success and failure paths (the finally branch).
Integration check
onFullSync should assign the resolved db to this.lastSourceDb (so a subsequent redump() uses the docker-escaped host) and pass it to remote.syncFrom.
Notes
resolveDockerHost is a module-level function (not exported). Either export it for direct testing or exercise it through onFullSync + stubbed connectToSource / Connectable.
- Existing tests in
src/remote/remote-controller.test.ts use PostgreSqlContainer and hit a real DB — the reachable-host case can follow that pattern; the unreachable case likely needs a mocked connectToSource.
Follow-up to #119, which added
resolveDockerHostinsrc/remote/remote-controller.tsto auto-swaplocalhostforhost.docker.internalwhen the docker-escaped host is reachable.The function currently has no test coverage. We should add tests covering its branches.
Cases to cover
resolveDockerHost(db)should:Connectableunchanged whendb.isLocalhost()is false.escapeDocker()returns aConnectablewhose hostname matches the input (e.g.,env.HOSTED=true, which makesescapeDocker()returnthis), return the originaldbwithout attempting to connect.host.docker.internalis reachable andSELECT 1succeeds, return the escapedConnectableand log the resolution.dband log the fallback.pg.close()) is invoked in both success and failure paths (thefinallybranch).Integration check
onFullSyncshould assign the resolved db tothis.lastSourceDb(so a subsequentredump()uses the docker-escaped host) and pass it toremote.syncFrom.Notes
resolveDockerHostis a module-level function (not exported). Either export it for direct testing or exercise it throughonFullSync+ stubbedconnectToSource/Connectable.src/remote/remote-controller.test.tsusePostgreSqlContainerand hit a real DB — the reachable-host case can follow that pattern; the unreachable case likely needs a mockedconnectToSource.