Skip to content

Commit f6f4da8

Browse files
committed
Add test with environment variables
1 parent 25a104a commit f6f4da8

File tree

8 files changed

+49
-18
lines changed

8 files changed

+49
-18
lines changed

tests/00-module/001-dc-manager.test.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var module = require('../../src/docker-compose-manager'),
3030
logger = require('../../src/logger/logger');
3131

3232
describe('Docker compose manager Module tests', function () {
33-
this.timeout(60000);
33+
this.timeout(120000);
3434

3535
it('The module exposes "dockerComposeUp" function', () => {
3636

@@ -82,19 +82,20 @@ describe('Docker compose manager Module tests', function () {
8282
});
8383

8484
it('Functions sequence', done => {
85-
var file = __dirname + '/../docker-compose.yaml';
85+
var file = __dirname + '/../without-environment/docker-compose.yaml';
86+
8687
module.dockerComposeUp(file).then(() => {
8788
return module.dockerComposeStop(file);
8889
}).then(() => {
8990
return module.dockerComposeStart(file);
9091
}).then(() => {
91-
return module.dockerExec('tests_mongo_1', ['mongo', '--version']);
92+
return module.dockerExec('withoutenvironment_mongo_1', ['mongo', '--version']);
9293
}).then(() => {
93-
return module.dockerInspectIPAddressOfContainer('tests_mongo_1', { network: "tests_default" }).then(ip => {
94+
return module.dockerInspectIPAddressOfContainer('withoutenvironment_mongo_1', { network: "withoutenvironment_default" }).then(ip => {
9495
expect(ip).to.match(/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/);
9596
});
9697
}).then(() => {
97-
return module.dockerInspectPortOfContainer('tests_mongo_1').then(port => {
98+
return module.dockerInspectPortOfContainer('withoutenvironment_mongo_1').then(port => {
9899
expect(port).to.be.equal('27017');
99100
});
100101
}).then(() => {

tests/00-module/002-dc-up.test.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,32 @@ var module = require('../../src/docker-compose-manager'),
2727
fs = require('fs');
2828

2929
describe('docker-compose up tests', function () {
30-
this.timeout(60000);
30+
this.timeout(120000);
3131

32-
var file = __dirname + '/../docker-compose.yaml';
32+
var file = __dirname + '/../without-environment/docker-compose.yaml';
33+
var fileEnv = __dirname + '/../with-environment/docker-compose.yaml';
3334
it('Execute command up', done => {
3435

3536
module.dockerComposeUp(file).then(out => {
36-
expect(out.indexOf('Creating network "tests_default" with the default driver')).to.not.equal(-1);
37-
expect(out.indexOf('Creating tests_mongo_1')).to.not.equal(-1);
37+
expect(out.indexOf('Creating network "withoutenvironment_default" with the default driver')).to.not.equal(-1);
38+
expect(out.indexOf('Creating withoutenvironment_mongo_1')).to.not.equal(-1);
3839
expect(out.indexOf('done')).to.not.equal(-1);
3940
done();
40-
}, done);
41+
}).catch(err => done(err));
42+
43+
});
44+
45+
it('Execute command up with env', done => {
46+
47+
process.env.MONGO_VERSION = '3.0.15';
48+
49+
module.dockerComposeUp(fileEnv).then(() => {
50+
return module.dockerExec('withenvironment_mongo_1', ['mongo', '--version']);
51+
}).then((out) => {
52+
return Promise.resolve(expect(out.indexOf('3.0.15')).to.not.be.equal(-1));
53+
}).then(() => {
54+
return module.dockerComposeDown(fileEnv);
55+
}).then(() => done()).catch(err => done(err));
4156

4257
});
4358

tests/00-module/003-dc-stop.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ var module = require('../../src/docker-compose-manager'),
2929
describe('docker-compose stop tests', function () {
3030
this.timeout(30000);
3131

32-
var file = __dirname + '/../docker-compose.yaml';
32+
var file = __dirname + '/../without-environment/docker-compose.yaml';
3333
it('Execute command stop', done => {
3434

3535
module.dockerComposeStop(file).then(out => {
36-
expect(out.indexOf('Stopping tests_mongo_1')).to.not.equal(-1);
36+
expect(out.indexOf('Stopping withoutenvironment_mongo_1')).to.not.equal(-1);
3737
expect(out.indexOf('done')).to.not.equal(-1);
3838
done();
3939
}, done);

tests/00-module/004-dc-start.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var module = require('../../src/docker-compose-manager'),
2929
describe('docker-compose start tests', function () {
3030
this.timeout(30000);
3131

32-
var file = __dirname + '/../docker-compose.yaml';
32+
var file = __dirname + '/../without-environment/docker-compose.yaml';
3333
it('Execute command start', done => {
3434

3535
module.dockerComposeStart(file).then(out => {

tests/00-module/005-dc-down.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ var module = require('../../src/docker-compose-manager'),
2929
describe('docker-compose down tests', function () {
3030
this.timeout(30000);
3131

32-
var file = __dirname + '/../docker-compose.yaml';
32+
var file = __dirname + '/../without-environment/docker-compose.yaml';
3333
it('Execute command down', done => {
3434

3535
module.dockerComposeDown(file).then(out => {
36-
expect(out.indexOf('Stopping tests_mongo_1')).to.not.equal(-1);
37-
expect(out.indexOf('Removing tests_mongo_1')).to.not.equal(-1);
36+
expect(out.indexOf('Stopping withoutenvironment_mongo_1')).to.not.equal(-1);
37+
expect(out.indexOf('Removing withoutenvironment_mongo_1')).to.not.equal(-1);
3838
expect(out.indexOf('done')).to.not.equal(-1);
39-
expect(out.indexOf('Removing network tests_default')).to.not.equal(-1);
39+
expect(out.indexOf('Removing network withoutenvironment_default')).to.not.equal(-1);
4040
done();
4141
}, done);
4242

tests/01-cmd/000-cmd.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,15 @@ describe('CMD Module tests', function () {
5353

5454
});
5555

56+
it('The "execCommand" function with args and env return a child_process object', done => {
57+
58+
process.env.DIR = '/';
59+
60+
module.execCommand('ls', ['-la', '$DIR']).then(child => {
61+
expect(child).to.not.be.equal(undefined);
62+
done();
63+
}, done);
64+
65+
});
66+
5667
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version: '3'
2+
services:
3+
mongo:
4+
image: mongo:${MONGO_VERSION}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '2'
1+
version: '3'
22
services:
33
mongo:
44
image: mongo

0 commit comments

Comments
 (0)