Add stopOne command

This commit is contained in:
Nacho González 2019-08-15 08:59:55 +02:00
parent 61d46416ef
commit 3cea146b6e
3 changed files with 15 additions and 0 deletions

View file

@ -26,6 +26,7 @@ npm install --save-dev docker-compose
* `down(options)` - Stops containers and removes containers, networks, volumes, and images created by `up`
* `kill(options)` - Force stop service containers
* `stop(options)` - Stop running containers without removing them
* `stopOne(service, options)` - Stops one container without removing it
* `rm(options)` - Remove stopped service containers - always uses the `-f` flag due to non interactive mode
* `exec(container, command, options)` - Exec `command` inside `container`, uses `-T` to properly handle stdin & stdout
* `logs(services, options)` - Show logs of service(s). Use `options.follow` `true|false` to turn on `--follow` flag.

View file

@ -128,6 +128,10 @@ export const stop = function (options?: IDockerComposeOptions): Promise<IDockerC
return execCompose('stop', [], options);
};
export const stopOne = function (service: string, options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
return execCompose('stop', [ service ], options);
};
export const kill = function (options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
return execCompose('kill', [], options);
};

View file

@ -172,6 +172,16 @@ test('ensure container gets stopped', async (): Promise<void> => {
await compose.down({ cwd: path.join(__dirname), log: logOutput });
});
test('ensure only single container gets stopped', async (): Promise<void> => {
await compose.upAll({ cwd: path.join(__dirname), log: logOutput });
expect(await isContainerRunning('/compose_test_alpine')).toBeTruthy();
await compose.stopOne('alpine', { cwd: path.join(__dirname), log: logOutput });
expect(await isContainerRunning('/compose_test_alpine')).toBeFalsy();
expect(await isContainerRunning('/compose_test_nginx')).toBeTruthy();
await compose.down({ cwd: path.join(__dirname), log: logOutput });
});
test('ensure container gets killed', async (): Promise<void> => {
await compose.upAll({ cwd: path.join(__dirname), log: logOutput });
expect(await isContainerRunning('/compose_test_nginx')).toBeTruthy();