Skip to content

Commit

Permalink
add tests for default service config
Browse files Browse the repository at this point in the history
* verify default service config is applied properly
* verify config is merged properly into the default config

see issue #11
  • Loading branch information
alrik committed Oct 14, 2015
1 parent 67cce13 commit aa9cda0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const
Config = require('../Config'),
Service = require('../Service'),
ServiceManager = require('../ServiceManager'),
ServiceWithDefaultConfig = require('./lib/ServiceWithDefaultConfig'),
EventEmitter = require('events').EventEmitter;

describe('srvoa::service', function() {
Expand Down Expand Up @@ -96,4 +97,30 @@ describe('srvoa::service', function() {

assert(srv.serviceConfig.get('test.test2') === undefined, 'Expected config key `test.test2` to equal undefined after resetting configuration.');
});

it('should apply the default service config during configuration.', function() {
var srv = new ServiceWithDefaultConfig();

assert(srv.serviceConfig === null, 'Expected `serviceConfig` to be null before configure is called.');

srv.configure();

assert(srv.serviceConfig instanceof Config, 'Expected `serviceConfig` to be instance of `Config` after configure is called.');
assert(srv.serviceConfig.get('test.test2') === 1, 'Expected default service config to be applied thus config key `test.test2` must equal 1.');
});

it('should merge config into default service config during configuration.', function() {
var srv = new ServiceWithDefaultConfig();

srv.configure({
test: {
test2: 2
},
test2: 1
});

assert(srv.serviceConfig.get('test.test2') === 2, 'Expected configs got merged properly thus config key `test.test2` must equal 2.');
assert(srv.serviceConfig.get('test.test3') === 1, 'Expected configs got merged properly thus config key `test.test3` must equal 1.');
assert(srv.serviceConfig.get('test2') === 1, 'Expected configs got merged properly thus config key `test2` must equal 1.');
});
});
16 changes: 16 additions & 0 deletions test/lib/ServiceWithDefaultConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use strict";

const Service = require('../../Service');

class ServiceWithDefaultConfig extends Service {
getDefaultServiceConfig() {
return {
test: {
test2: 1,
test3: 1
}
};
}
}

module.exports = ServiceWithDefaultConfig;

0 comments on commit aa9cda0

Please sign in to comment.