CartoDB-SQL-API/test/unit/health-check-test.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-10-24 21:42:33 +08:00
'use strict';
require('../helper');
2019-12-24 01:19:08 +08:00
var assert = require('assert');
var HealthCheck = require('../../lib/monitoring/health-check');
2014-08-27 00:40:58 +08:00
var metadataBackend = {};
2019-12-24 01:19:08 +08:00
function PSQL (dbParams) {
2014-08-27 00:40:58 +08:00
this.params = dbParams;
}
var healthCheck = new HealthCheck(metadataBackend, PSQL);
2019-12-24 01:19:08 +08:00
describe('health checks', function () {
it('errors if disabled file exists', function (done) {
var fs = require('fs');
var readFileFn = fs.readFile;
fs.readFile = function (filename, callback) {
callback(null, 'Maintenance');
};
healthCheck.check(function (err) {
2019-12-26 21:01:18 +08:00
assert.strictEqual(err.message, 'Maintenance');
assert.strictEqual(err.http_status, 503);
2019-12-24 01:19:08 +08:00
fs.readFile = readFileFn;
done();
});
});
2019-12-24 01:19:08 +08:00
it('does not err if disabled file does not exists', function (done) {
var fs = require('fs');
var readFileFn = fs.readFile;
fs.readFile = function (filename, callback) {
callback(new Error('ENOENT'), null);
};
healthCheck.check(function (err) {
2019-12-26 21:01:18 +08:00
assert.strictEqual(err, undefined);
2019-12-24 01:19:08 +08:00
fs.readFile = readFileFn;
done();
});
});
});