Skip to content

Commit

Permalink
more tests, fix the module log condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Panthro committed Nov 9, 2016
1 parent 6106340 commit 436fbe6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Module extends EventEmitter {
}

options = _.defaults(options, defaults);
if (!options instanceof Module) {
if (!(options instanceof Module)) {
logger.debug('Initializing module with options:', options);
}

Expand Down
43 changes: 43 additions & 0 deletions test/module.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as chai from 'chai';
import dirtyChai from 'dirty-chai';
import Module from '../src/module';
import logger from '../src/logging/logger';
import dockerNames from 'docker-names';

// TEST SETUP
Expand All @@ -22,6 +23,48 @@ describe('Module', function () {
});
});

it('Should log when a new module is being initialized with options', function (done) {

logger._test_debug = logger.debug;
logger.debug = function () {
if (arguments[0] === 'Initializing module with options:') {
// reset logger;
logger.debug = logger._test_debug;
done();
}
logger._test_debug.apply(logger, arguments);

};

const m = new Module({ service: 'testService' });

logger.info(`Module initialized [${m.service}]-[${m.name}]`);

});

it('Should NOT log when a new module is being initialized with Module', function (done) {

let m = new Module({ service: 'testService' });

logger._test_debug = logger.debug;
logger.debug = function () {
if (arguments[0] === 'Initializing module with options:') {
// reset logger;
logger.debug = logger._test_debug;
done(new Error('Module initialization with module should not be logged'));
}
logger._test_debug.apply(logger, arguments);

};

m = new Module(m);

logger.info(`Module initialized [${m.service}]-[${m.name}]`);
logger.debug = logger._test_debug;
done();

});

it('Should fail when a new property is added and not reflected in the test', function () {
const m = new Module('test-service-name');

Expand Down
18 changes: 17 additions & 1 deletion test/orchestrator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let o;
describe('Orchestrator', function () {

const registerMock = function () {
mock({
return mock({
registerQueue: o.registerQueue
}).register();
};
Expand Down Expand Up @@ -385,5 +385,21 @@ describe('Orchestrator', function () {
});
});

it('Should always only have 1 persistence module', function () {
registerMock();
return o.listen()
.then(() => {
chai.expect(o.modulesCollection.find({ type: 'persistence' }))
.to.have.lengthOf(1);
return registerMock()
.then((newModule) => {
const registeredModules = o.modulesCollection.find({ type: 'persistence' });

chai.expect(registeredModules).to.have.lengthOf(1);
chai.expect(registeredModules[0].name).to.be.equal(newModule.name);
});
});
});

})
;

0 comments on commit 436fbe6

Please sign in to comment.