Skip to content

Commit

Permalink
Throw an error when someone tries to create an unknown check
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmuller committed Apr 14, 2023
1 parent 70ad235 commit 8ec4858
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/healthchecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ class HealthChecks {
this.name = config.name;
this.description = config.description;
this.checks = config.checks
.filter(check => {
return check.type in healthchecks;
})
.map(check => {
if (!(check.type in healthchecks)) {
throw new Error(`Attempted to create check '${check.name}' of type ${check.type} which does not exist`);
}

return new healthchecks[check.type](check, this)
});
}
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions test/healthchecks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ describe('Healthchecks', function(){
});

describe('with an unknown type', function() {
before(function(){
it('Should throw an error for unknown check types', function() {
Healthchecks = require('../src/healthchecks');
fixture = require('./fixtures/config/unknownType.js');
healthchecks = new Healthchecks(fixture, require('../src/checks/'));
});
fixture = require('./fixtures/badConfig/unknownType.js');

const newHealthchecks = () => {
new Healthchecks(fixture, require('../src/checks/'))
};

it('Should ignore the unknown healthcheck silently', function() {
expect(healthchecks.checks.length).to.equal(1);
expect(healthchecks.checks[0].name).to.equal('A Graphite check');
expect(newHealthchecks).to.throw(/Attempted to create/);
});
});
});

0 comments on commit 8ec4858

Please sign in to comment.