2018-10-24 21:42:33 +08:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-13 00:34:25 +08:00
|
|
|
require('../helper');
|
2015-03-26 00:15:41 +08:00
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
var assert = require('assert');
|
2019-10-04 00:24:39 +08:00
|
|
|
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) {
|
|
|
|
assert.equal(err.message, 'Maintenance');
|
|
|
|
assert.equal(err.http_status, 503);
|
|
|
|
fs.readFile = readFileFn;
|
|
|
|
done();
|
|
|
|
});
|
2015-03-26 00:15:41 +08:00
|
|
|
});
|
|
|
|
|
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) {
|
|
|
|
assert.equal(err, null);
|
|
|
|
fs.readFile = readFileFn;
|
|
|
|
done();
|
|
|
|
});
|
2015-03-26 00:15:41 +08:00
|
|
|
});
|
|
|
|
});
|