Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: stop many #200

Merged
merged 5 commits into from
Jan 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ npm install --save-dev docker-compose
* `run(service, command, options)` - Run a one-off `command` on a service - uses `-T` to properly handle stdin & stdout
* `stop(options)` - Stop running containers without removing them
* `stopOne(service, options)` - Stops one container without removing it
* `stopMany(options,services)` - Stops containers without removing them
* `unpauseOne(service, options)` - Resume the specified service
* `upAll(options)` - Builds, (re)creates, starts, and attaches to containers for all services - always uses the `-d` flag due to non interactive mode
* `upMany(services, options)` - Builds, (re)creates, starts, and attaches to containers for the services specified in `services` - always uses the `-d` flag due to non interactive mode
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,13 @@ export const stopOne = function (
return execCompose('stop', [service], options)
}

export const stopMany = function (
options?: IDockerComposeOptions,
...services: string[]
): Promise<IDockerComposeResult> {
return execCompose('stop', [...services], options)
}

export const pauseOne = function (
service: string,
options?: IDockerComposeOptions
Expand Down
15 changes: 15 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,21 @@ test('ensure only single container gets stopped', async (): Promise<void> => {
await compose.down({ cwd: path.join(__dirname), log: logOutput })
})

test('ensure multiple containers gets stopped', async (): Promise<void> => {
await compose.upAll({ cwd: path.join(__dirname), log: logOutput })
expect(await isContainerRunning('/compose_test_web')).toBeTruthy()
expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy()

await compose.stopMany(
{ cwd: path.join(__dirname), log: logOutput },
'proxy',
'web'
)
expect(await isContainerRunning('/compose_test_web')).toBeFalsy()
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy()
await compose.down({ cwd: path.join(__dirname), log: logOutput })
})

test('ensure only single container gets paused then resumed', async (): Promise<void> => {
const opts = { cwd: path.join(__dirname), log: logOutput }
await compose.upAll(opts)
Expand Down