From 5921b51977cbd51ffcb1def458738ccfccbe1dd9 Mon Sep 17 00:00:00 2001 From: Westlad Date: Mon, 19 Jul 2021 15:18:14 +0100 Subject: [PATCH] feat: single container pause and unpause added --- src/index.ts | 16 ++++++++++++++++ test/index.test.ts | 23 +++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/index.ts b/src/index.ts index 8bfb2c3..614ebfa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -273,6 +273,20 @@ export const stopOne = function ( return execCompose('stop', [service], options) } +export const pauseOne = function ( + service: string, + options?: IDockerComposeOptions +): Promise { + return execCompose('pause', [service], options) +} + +export const unpauseOne = function ( + service: string, + options?: IDockerComposeOptions +): Promise { + return execCompose('unpause', [service], options) +} + export const kill = function ( options?: IDockerComposeOptions ): Promise { @@ -497,6 +511,8 @@ export default { down, stop, stopOne, + pauseOne, + unpauseOne, kill, rm, exec, diff --git a/test/index.test.ts b/test/index.test.ts index bff60f8..39da2c6 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -223,6 +223,29 @@ test('ensure only single container gets stopped', async (): Promise => { await compose.down({ cwd: path.join(__dirname), log: logOutput }) }) +test('ensure only single container gets paused then resumed', async (): Promise => { + const opts = { cwd: path.join(__dirname), log: logOutput } + await compose.upAll(opts) + expect(await isContainerRunning('/compose_test_web')).toBeTruthy() + expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy() + + await compose.pauseOne('proxy', opts) + expect(await isContainerRunning('/compose_test_web')).toBeTruthy() + expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy() + try { + await compose.exec('proxy', 'cat /etc/os-release', opts) + fail('Container was not paused') + } catch(err) { + expect(err.err).toContain('is paused') + } + await compose.unpauseOne('proxy', opts) + expect(await isContainerRunning('/compose_test_web')).toBeTruthy() + expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy() + const std = await compose.exec('proxy', 'cat /etc/os-release', opts) + expect(std.out).toContain('Alpine Linux') + await compose.down(opts) +}) + test('ensure container gets started with --abort-on-container-exit option', async (): Promise => { const result = await compose.upAll({ cwd: path.join(__dirname),