UNPKG

testcontainers

Version:

Testcontainers is a NodeJS library that supports tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container

56 lines 2.43 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PodmanContainerClient = void 0; const byline_1 = __importDefault(require("byline")); const docker_container_client_1 = require("./docker-container-client"); const common_1 = require("../../../common"); class PodmanContainerClient extends docker_container_client_1.DockerContainerClient { async exec(container, command, opts) { const execOptions = { Cmd: command, AttachStdout: true, AttachStderr: true, }; if (opts?.env !== undefined) { execOptions.Env = Object.entries(opts.env).map(([key, value]) => `${key}=${value}`); } if (opts?.workingDir !== undefined) { execOptions.WorkingDir = opts.workingDir; } if (opts?.user !== undefined) { execOptions.User = opts.user; } const chunks = []; try { if (opts?.log) { common_1.log.debug(`Execing container with command "${command.join(" ")}"...`, { containerId: container.id }); } const exec = await container.exec(execOptions); const stream = await this.demuxStream(container.id, await exec.start({ stdin: true, Detach: false, Tty: true })); if (opts?.log && common_1.execLog.enabled()) { (0, byline_1.default)(stream).on("data", (line) => common_1.execLog.trace(line, { containerId: container.id })); } await new Promise((res, rej) => { stream.on("data", (chunk) => chunks.push(chunk)); stream.on("end", res); stream.on("error", rej); }); stream.destroy(); const inspectResult = await exec.inspect(); const exitCode = inspectResult.ExitCode ?? -1; const output = chunks.join(""); return { output, exitCode }; } catch (err) { common_1.log.error(`Failed to exec container with command "${command.join(" ")}": ${err}: ${chunks.join("")}`, { containerId: container.id, }); throw err; } } } exports.PodmanContainerClient = PodmanContainerClient; //# sourceMappingURL=podman-container-client.js.map