Skip to content

Commit

Permalink
Skip pull test
Browse files Browse the repository at this point in the history
  • Loading branch information
cleve-fauna committed Dec 12, 2024
1 parent f54ce2a commit 0cc381a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/commands/local.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ function buildLocalCommand(yargs) {
},
hostPort: {
describe:
"The port on the host machine mapped to the container's port. This is the port you'll connect to Fauna on.",
"The port on the host machine mapped to the container's port. This is the port you'll connect to Fauna on.",
type: "number",
default: 8443,
},
interval: {
describe:
"The interval (in milliseconds) between health check attempts. Determines how often the CLI checks if the Fauna container is ready.",
"The interval (in milliseconds) between health check attempts. Determines how often the CLI checks if the Fauna container is ready.",
type: "number",
default: 10000,
},
maxAttempts: {
describe:
"The maximum number of health check attempts before declaring the start Fauna continer process as failed.",
"The maximum number of health check attempts before declaring the start Fauna continer process as failed.",
type: "number",
default: 100,
},
Expand All @@ -63,10 +63,15 @@ function buildLocalCommand(yargs) {
})
.check((argv) => {
if (argv.maxAttempts < 1) {
throw new CommandError("--maxAttempts must be greater than 0.", { hideHelp: false });
throw new CommandError("--maxAttempts must be greater than 0.", {
hideHelp: false,
});
}
if (argv.interval < 0) {
throw new CommandError("--interval must be greater than or equal to 0.", { hideHelp: false });
throw new CommandError(
"--interval must be greater than or equal to 0.",
{ hideHelp: false },
);
}
return true;
});
Expand Down
23 changes: 23 additions & 0 deletions test/local.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,29 @@ describe.only("ensureContainerRunning", () => {
);
});

it("Skips pull if --pull is false.", async () => {
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 --pull false", container);
expect(docker.pull).not.to.have.been.called;
expect(docker.modem.followProgress).not.to.have.been.called;
expect(startStub).to.have.been.called;
expect(logsStub).to.have.been.called;
expect(docker.createContainer).to.have.been.called;
expect(logger.stderr).to.have.been.calledWith(
"[ContainerReady] Container 'faunadb' is up and healthy.",
);
});

it("Throws an error if the health check fails", async () => {
process.env.FAUNA_LOCAL_HEALTH_CHECK_INTERVAL_MS = "1";
docker.pull.onCall(0).resolves();
Expand Down

0 comments on commit 0cc381a

Please sign in to comment.