Skip to content

Commit

Permalink
Tests for pull failing
Browse files Browse the repository at this point in the history
  • Loading branch information
cleve-fauna committed Dec 12, 2024
1 parent 0ab9968 commit 391d12e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/lib/docker-containers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ async function pullImage(imageName) {
);
});
} catch (error) {
throw new CommandError(`[PullImage] Failed to pull image '${imageName}': ${error.message}. ${SUPPORT_MESSAGE}`, { cause: error });
throw new CommandError(
`[PullImage] Failed to pull image '${imageName}': ${error.message}. ${SUPPORT_MESSAGE}`,
{ cause: error },
);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/lib/errors.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import util from "util";

import { container } from "../cli.mjs";

const BUG_REPORT_MESSAGE = "If you believe this is a bug, please report this issue on GitHub: https://github.com/fauna/fauna-shell/issues";
export const SUPPORT_MESSAGE = "If this issue persists contact support: https://support.fauna.com/hc/en-us/requests/new";
const BUG_REPORT_MESSAGE =
"If you believe this is a bug, please report this issue on GitHub: https://github.com/fauna/fauna-shell/issues";
export const SUPPORT_MESSAGE =
"If this issue persists contact support: https://support.fauna.com/hc/en-us/requests/new";

/*
* These are the error message prefixes that yargs throws during
Expand Down
32 changes: 32 additions & 0 deletions test/local.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,38 @@ describe("ensureContainerRunning", () => {
);
});

it("The user can control the hostPort and containerPort", async () => {
docker.pull.onCall(0).resolves();
docker.modem.followProgress.callsFake((stream, onFinished) => {
onFinished();
});
docker.listContainers.onCall(0).resolves([]);
fetch.onCall(0).resolves(f({})); // fast succeed the health check
logsStub.callsFake(async () => ({
on: () => {},
destroy: () => {},
}));
docker.createContainer.resolves({
start: startStub,
logs: logsStub,
unpause: unpauseStub,
});
await run("local --hostPort 10 --containerPort 11", container);
expect(docker.createContainer).to.have.been.calledWith({
Image: "fauna/faunadb:latest",
name: "faunadb",
HostConfig: {
PortBindings: {
"11/tcp": [{ HostPort: "10" }],
},
AutoRemove: true,
},
ExposedPorts: {
"11/tcp": {},
},
});
});

it("Skips pull if --pull is false.", async () => {
docker.listContainers.onCall(0).resolves([]);
fetch.onCall(0).resolves(f({})); // fast succeed the health check
Expand Down

0 comments on commit 391d12e

Please sign in to comment.