dockest
Version:
Dockest is an integration testing tool aimed at alleviating the process of evaluating unit tests whilst running multi-container Docker applications.
35 lines • 2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createPostgresReadinessCheck = void 0;
const with_no_stop_1 = require("./with-no-stop");
const with_retry_1 = require("./with-retry");
const execa_wrapper_1 = require("../utils/execa-wrapper");
const defaultConfigMapper = (runner) => {
return runner.dockerComposeFileService.environment;
};
const postgresReadinessCheck = (configMapper) => async ({ runner }) => {
const config = await (typeof configMapper === 'function' ? configMapper(runner) : configMapper);
if (!(config === null || config === void 0 ? void 0 : config.POSTGRES_DB)) {
throw new Error("Value 'POSTGRES_DB' was not provided.");
}
if (!(config === null || config === void 0 ? void 0 : config.POSTGRES_USER)) {
throw new Error("Value 'POSTGRES_USER' was not provided.");
}
const passwordEnvironmentVariable = (config === null || config === void 0 ? void 0 : config.POSTGRES_PASSWORD) ? `PGPASSWORD='${config.POSTGRES_PASSWORD}'` : '';
// Ref: http://postgresguide.com/utilities/psql.html
const command = `docker exec ${runner.containerId} bash -c " \
${passwordEnvironmentVariable} psql \
-h localhost \
-d ${config.POSTGRES_DB} \
-U ${config.POSTGRES_USER} \
-c 'select 1'"`;
(0, execa_wrapper_1.execaWrapper)(command, { runner: runner });
};
const createPostgresReadinessCheck = (args) => {
var _a, _b;
return (0, with_no_stop_1.withNoStop)((0, with_retry_1.withRetry)(postgresReadinessCheck((_a = args === null || args === void 0 ? void 0 : args.config) !== null && _a !== void 0 ? _a : defaultConfigMapper), {
retryCount: (_b = args === null || args === void 0 ? void 0 : args.retryCount) !== null && _b !== void 0 ? _b : 30,
}));
};
exports.createPostgresReadinessCheck = createPostgresReadinessCheck;
//# sourceMappingURL=create-postgres-readiness-check.js.map