Skip to content

Commit

Permalink
Merge pull request #89 from natete/master
Browse files Browse the repository at this point in the history
Add stopOne() command
  • Loading branch information
AlexZeitler authored Aug 15, 2019
2 parents 61d4641 + 3cea146 commit 9b00f30
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
10 changes: 10 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9b00f30

Please sign in to comment.