@microtica/mocks
Version:
Mock services for automated tests
71 lines (70 loc) • 2.12 kB
TypeScript
import * as Dockerode from "dockerode";
export interface RunOptions {
env: string[];
portsToOpen: number[];
}
/**
* Executes docker commands on your behalf to run containers for you. Mostly for testing purposes
*
* @export
* @class DockerRunner
*/
export declare class DockerRunner {
private readonly imageName;
private readonly containerName;
/**
* Instance of Dockerode class
*
* @private
* @type {Dockerode}
* @memberof DockerRunner
*/
private readonly docker;
/**
* Creates an instance of DockerRunner.
* @param {string} imageName image scope/name which will be pulled from Docker Hub
* @param {string} containerName unique name of the container
* @memberof DockerRunner
*/
constructor(imageName: string, containerName: string);
/**
* Checks whether there is at least one running container with the name
*
* @returns {Promise<boolean>}
* @memberof DockerRunner
*/
isRunning(): Promise<boolean>;
/**
* Tries to find the container in the list of all containers
*
* @returns container info
* @memberof DockerRunner
*/
getContainers(): Promise<Dockerode.ContainerInfo[]>;
/**
* Forcefully removes all containers with the name
*
* @returns {Promise<void>}
* @memberof DockerRunner
*/
remove(): Promise<void>;
/**
* Downloads the image from Docker Hub
*
* @private
* @returns {Promise<void>}
* @memberof DockerRunner
*/
private downloadImage;
/**
* Runs a container from the specified image in the constructor after the image was pulled.
* It does nothing if the container is already running
*
* @param {RunOptions} opt options object
* @param {string[]} opt.env array of environment variables in unix format (key=value)
* @param {numbner[]} opt.portsToOpen opens the specified TCP ports for you
* @returns {Promise<Dockerode.Container>} Container instance
* @memberof DockerRunner
*/
run(opt: RunOptions): Promise<Dockerode.Container>;
}