Skip to content

Write tests for resolveDockerHost (follow-up to #119) #121

@veksen

Description

@veksen

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:

  1. Non-localhost passthrough — return the input Connectable unchanged when db.isLocalhost() is false.
  2. 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.
  3. Docker host reachable — when host.docker.internal is reachable and SELECT 1 succeeds, return the escaped Connectable and log the resolution.
  4. Docker host unreachable — when the probe throws, fall back to the original db and log the fallback.
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions