Skip to content

Commit

Permalink
feat(config): remove appName duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
peteyycz committed Sep 21, 2015
1 parent da227a4 commit c3e7d65
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 21 deletions.
4 changes: 0 additions & 4 deletions lib/reporters/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ function TraceReporter (options) {
if (!this.apiKey) {
throw new Error('Missing apiKey');
}

if (!this.appName) {
throw new Error('Missing appName');
}
}

// USE THIS WITH CAUTION, IT WILL BE BLOCKING
Expand Down
14 changes: 0 additions & 14 deletions lib/reporters/trace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@ describe('The Trace reporter module', function () {
throw new Error('Unhandled error');
});

it('throws an error if appName is missing', function () {
var traceReporter;
try {
traceReporter = TraceReporter.create({
apiKey: 'test'
});
} catch (ex) {
expect(ex.message).to.eql('Missing appName');
return;
}

throw new Error('Unhandled error');
});

it('can be instantiated w/ appName and apiKey', function () {
var traceReporter = TraceReporter.create({
appName: 'test',
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/configReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ ConfigReader.prototype.getConfig = function () {

if (!config.reporter) {
reporterConfig = this._getReporterConfig();
reporterConfig.appName = config.appName;
config.reporter = this._require('../reporters')[this.collectorConfig.reporterType]
.create(reporterConfig);
} else {
config.reporter.appName = config.appName;
}

var resultConfig = defaults({}, this.collectorConfig, config);
Expand Down
24 changes: 24 additions & 0 deletions lib/utils/configReader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,28 @@ describe('Config Reader module', function () {
throw new Error('Error should have been thrown');
});

it('gets the config', function () {
var reporter = {};
var collectorConfig = {};

var config = {
appName: 'app',
reporter: reporter
};

var configReader = ConfigReader.create(collectorConfig);

var initStub = this.sandbox.stub(configReader, '_initConfig', function () {
return config;
});

var result = configReader.getConfig();

expect(initStub).to.have.been.calledOnce;
expect(initStub).to.have.been.calledWith();

expect(result).to.be.eql(defaults({}, collectorConfig, config));
expect(reporter.appName).to.be.eql(config.appName);
});

});
1 change: 0 additions & 1 deletion test/e2e/service1/trace.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ var traceConfig = {};
traceConfig.appName = 'service1';
traceConfig.reporter = require('../../../lib/reporters').trace.create({
apiKey: 'key',
appName: traceConfig.appName,
collectInterval: 100
});

Expand Down
3 changes: 1 addition & 2 deletions test/e2e/service2/trace.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ var traceConfig = {};

traceConfig.appName = 'service2';
traceConfig.reporter = require('../../../lib/reporters').trace.create({
apiKey: 'key',
appName: traceConfig.appName
apiKey: 'key'
});

module.exports = traceConfig;
Expand Down

0 comments on commit c3e7d65

Please sign in to comment.