Skip to content

Commit

Permalink
Merge pull request #17 from userlerueda/add-tests-down
Browse files Browse the repository at this point in the history
Add tests for compose.down
  • Loading branch information
apocas authored Feb 28, 2022
2 parents 56f3645 + 94011ae commit 87fb986
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 40 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
133 changes: 93 additions & 40 deletions test/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,37 @@ describe('compose', function () {
(async () => {
var report = await compose.up();
expect(report.services).to.be.ok;
await new Promise(r => setTimeout(r, 2000));
let listContainers = await docker.listContainers({ 'all': true });
for (var containerInfo of listContainers) {
if (containerInfo.Names[0].includes("dockerodec_wordpress")) {
let container = docker.getContainer(containerInfo.Id);
if (containerInfo.State == 'running')
await container.stop();
await container.remove();
}
}
done();
})();
});
afterEach('clean up', function (done) {
this.timeout(60000);
(async () => {
await compose.down({ volumes: true });
done();
})();
});
});

describe('#down', function () {
beforeEach('bring up', function (done) {
this.timeout(20000);
(async () => {
await compose.up();
done();
})();
});
it("should do compose down", function (done) {
this.timeout(60000);
(async () => {
await compose.down({volumes: true});
let listContainers = await docker.listContainers({ 'all': true, 'filters': {"label":[`com.docker.compose.project=${compose.projectName}`]}});
expect(listContainers).to.be.empty
let listVolumes = await docker.listVolumes({ 'filters': {"label":[`com.docker.compose.project=${compose.projectName}`]}})
expect(listVolumes.Volumes).to.be.empty
expect(listVolumes.Warnings).to.be.null
let listNetworks = await docker.listNetworks({ 'filters': {"label":[`com.docker.compose.project=${compose.projectName}`]}})
expect(listNetworks).to.be.empty
done();
})();
});
Expand All @@ -62,16 +83,37 @@ describe('compose', function () {
(async () => {
var report = await compose_complex.up();
expect(report.services).to.be.ok;
await new Promise(r => setTimeout(r, 5000));
let listContainers = await docker.listContainers({ 'all': true });
for (var containerInfo of listContainers) {
if (containerInfo.Names[0].includes("dockerodec_complex")) {
let container = docker.getContainer(containerInfo.Id);
if (containerInfo.State == 'running')
await container.stop();
await container.remove();
}
}
done();
})();
});
afterEach('clean up', function (done) {
this.timeout(60000);
(async () => {
await compose_complex.down({ volumes: true });
done();
})();
});
});

describe('#down_complex', function () {
beforeEach('bring up', function (done) {
this.timeout(300000);
(async () => {
await compose_complex.up();
done();
})();
});
it("should do compose down complex example with extends and build", function (done) {
this.timeout(60000);
(async () => {
await compose_complex.down({volumes: true});
let listContainers = await docker.listContainers({ 'all': true, 'filters': {"label":[`com.docker.compose.project=${compose.projectName}`]}});
expect(listContainers).to.be.empty
let listVolumes = await docker.listVolumes({ 'filters': {"label":[`com.docker.compose.project=${compose.projectName}`]}})
expect(listVolumes.Volumes).to.be.empty
expect(listVolumes.Warnings).to.be.null
let listNetworks = await docker.listNetworks({ 'filters': {"label":[`com.docker.compose.project=${compose.projectName}`]}})
expect(listNetworks).to.be.empty
done();
})();
});
Expand All @@ -83,16 +125,6 @@ describe('compose', function () {
(async () => {
var report = await compose_build.up();
expect(report.services).to.be.ok;
await new Promise(r => setTimeout(r, 5000));
let listContainers = await docker.listContainers({ 'all': true });
for (var containerInfo of listContainers) {
if (containerInfo.Names[0].includes("dockerodec_build")) {
let container = docker.getContainer(containerInfo.Id);
if (containerInfo.State == 'running')
await container.stop();
await container.remove();
}
}
done();
})();
});
Expand All @@ -101,16 +133,37 @@ describe('compose', function () {
(async () => {
var report = await compose_build.up({ 'verbose': true });
expect(report.services).to.be.ok;
await new Promise(r => setTimeout(r, 5000));
let listContainers = await docker.listContainers({ 'all': true });
for (var containerInfo of listContainers) {
if (containerInfo.Names[0].includes("dockerodec_build")) {
let container = docker.getContainer(containerInfo.Id);
if (containerInfo.State == 'running')
await container.stop();
await container.remove();
}
}
done();
})();
});
afterEach('clean up', function (done) {
this.timeout(60000);
(async () => {
await compose_build.down({ volumes: true });
done();
})();
});
});

describe('#down_build', function () {
beforeEach('bring up', function (done) {
this.timeout(300000);
(async () => {
await compose_build.up();
done();
})();
});
it("should do compose down example with build", function (done) {
this.timeout(60000);
(async () => {
await compose_build.down({volumes: true});
let listContainers = await docker.listContainers({ 'all': true, 'filters': {"label":[`com.docker.compose.project=${compose.projectName}`]}});
expect(listContainers).to.be.empty
let listVolumes = await docker.listVolumes({ 'filters': {"label":[`com.docker.compose.project=${compose.projectName}`]}})
expect(listVolumes.Volumes).to.be.empty
expect(listVolumes.Warnings).to.be.null
let listNetworks = await docker.listNetworks({ 'filters': {"label":[`com.docker.compose.project=${compose.projectName}`]}})
expect(listNetworks).to.be.empty
done();
})();
});
Expand Down

0 comments on commit 87fb986

Please sign in to comment.