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

Re-enable docker-compose-js and types unit tests #3893

Merged
merged 3 commits into from
Jan 8, 2025
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
4 changes: 2 additions & 2 deletions packages/docker-compose-js/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@terascope/docker-compose-js",
"displayName": "Docker Compose Js",
"version": "1.4.2",
"version": "1.4.3",
"description": "Node.js driver for controlling docker-compose testing environments.",
"keywords": [
"docker",
Expand Down Expand Up @@ -48,7 +48,7 @@
},
"srcMain": "src/index.ts",
"terascope": {
"testSuite": "disabled",
"testSuite": "unit",
"enableTypedoc": true
}
}
15 changes: 9 additions & 6 deletions packages/docker-compose-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,20 @@ export class Compose {
});
cmd.on('close', (code) => {
debug('close with code', code);
/// Do not throw an error if 'docker compose' fails
if (code !== 0 && sCommand !== 'docker') {
// In the scenario that the 'docker' command exists but the 'compose' arg is
// invalid try 'docker-compose' command instead
if (code === 125 && a[0] === 'compose') {
runCommand('docker-compose', args);
} else if (code !== 0) {
const error = new Error(`Command exited: ${code}\n${stderr}`);
// @ts-expect-error
error.stdout = stdout;
reject(error);
/// In the senario that the docker command exists but the compose arg is invalid
} else if (code === 125 && a[0] === 'compose') {
runCommand('docker-compose', args);
} else {
resolve(stdout);
// sometimes a command is successful (no error), but prints a failure of
// some kind to stderr. If no stdout, return stderr instead.
const msg = stdout !== '' ? stdout : stderr;
resolve(msg);
}
});
}
Expand Down
48 changes: 28 additions & 20 deletions packages/docker-compose-js/test/docker-compose-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'jest-extended';
import { jest } from '@jest/globals';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { Compose } from '../src/index.js';
Expand All @@ -25,37 +26,42 @@ describe('compose', () => {
it('should be able to call compose.version()', async () => {
const result = await compose.version();
expect(result).not.toBeNil();
expect(result).toContain('docker-compose version');
expect(result).toContain('Docker Compose version');
});

describe('when the cluster is up', () => {
beforeAll(() => compose.up({
timeout: 1,
'force-recreate': ''
}));
beforeAll(async () => {
await compose.up({
timeout: 1,
'force-recreate': ''
});
});

afterAll(() => compose.down({
timeout: 1,
'--volumes': '',
'--remove-orphans': ''
}));

it('should be able to call rm on the service', () => {
expect(() => compose.rm('test')).not.toThrow();
it('should be able to call rm on the service', async () => {
const result = await compose.rm('test');
expect(result).toContain('No stopped containers');
});

it('should be able to call port', () => {
it('should be able to call port on the service', () => {
expect(() => compose.port('test', '40230')).not.toThrow();
});

it('should be able to call pause and unpause the service', async () => {
await expect(async () => {
await compose.pause('test');
await compose.unpause('test');
}).resolves.not.toThrow();
it('should be able to call pause and unpause on the service', async () => {
await expect(
(async () => {
await compose.pause('test');
await compose.unpause('test');
})()
).resolves.not.toThrow();
});

it('should be able to call start, ps and stop the service', async () => {
it('should be able to call start, ps and stop on the service', async () => {
await compose.start('test');

const result = await compose.ps();
Expand All @@ -67,11 +73,13 @@ describe('compose', () => {
});
});

it('should be able to call restart and kill the service', async () => {
await expect(async () => {
await compose.restart('test', { '--timeout': 1 });
await compose.kill('test');
}).resolves.not.toThrow();
it('should be able to call restart and kill on the service', async () => {
await expect(
(async () => {
await compose.restart('test', { '--timeout': 1 });
await compose.kill('test');
})()
).resolves.not.toThrow();
});

it('should return a rejection when passing in incorrect options', async () => {
Expand All @@ -80,7 +88,7 @@ describe('compose', () => {
await compose.start('something wrong');
} catch (err) {
expect(err.message).toContain('Command exited: 1');
expect(err.message).toContain('No such service: something wrong');
expect(err.message).toContain('no such service: something wrong');
expect(err.stdout).toBeDefined();
}
});
Expand Down
1 change: 0 additions & 1 deletion packages/docker-compose-js/test/fixtures/example.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '2'
services:
test:
image: 'bash:3.2.57'
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"srcMain": "src/index.ts",
"terascope": {
"testSuite": "disabled",
"testSuite": "unit",
"enableTypedoc": true
}
}
Loading