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
|
|
|
|
2015-05-13 00:34:25 +08:00
|
|
|
var assert = require('assert');
|
|
|
|
var HealthCheck = require('../../app/monitoring/health_check');
|
2014-08-27 00:40:58 +08:00
|
|
|
|
|
|
|
var metadataBackend = {};
|
|
|
|
|
|
|
|
function PSQL(dbParams) {
|
|
|
|
this.params = dbParams;
|
|
|
|
}
|
|
|
|
|
|
|
|
var healthCheck = new HealthCheck(metadataBackend, PSQL);
|
|
|
|
|
2015-05-13 00:34:25 +08:00
|
|
|
describe('health checks', function() {
|
2014-08-27 00:40:58 +08:00
|
|
|
|
2015-05-13 00:34:25 +08:00
|
|
|
it('errors if disabled file exists', function(done) {
|
2015-03-26 00:15:41 +08:00
|
|
|
var fs = require('fs');
|
|
|
|
|
2015-03-26 01:39:45 +08:00
|
|
|
var readFileFn = fs.readFile;
|
2015-03-26 00:15:41 +08:00
|
|
|
fs.readFile = function(filename, callback) {
|
|
|
|
callback(null, "Maintenance");
|
2015-05-13 00:34:25 +08:00
|
|
|
};
|
2015-09-08 00:34:50 +08:00
|
|
|
healthCheck.check(function(err) {
|
2015-03-26 00:15:41 +08:00
|
|
|
assert.equal(err.message, "Maintenance");
|
|
|
|
assert.equal(err.http_status, 503);
|
2015-03-26 01:39:45 +08:00
|
|
|
fs.readFile = readFileFn;
|
2015-05-13 00:34:25 +08:00
|
|
|
done();
|
2015-03-26 00:15:41 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-05-13 00:34:25 +08:00
|
|
|
it('does not err if disabled file does not exists', function(done) {
|
2015-03-26 00:15:41 +08:00
|
|
|
var fs = require('fs');
|
2018-10-24 21:42:33 +08:00
|
|
|
|
2015-03-26 01:39:45 +08:00
|
|
|
var readFileFn = fs.readFile;
|
2015-03-26 00:15:41 +08:00
|
|
|
fs.readFile = function(filename, callback) {
|
2015-03-26 01:39:45 +08:00
|
|
|
callback(new Error("ENOENT"), null);
|
2015-05-13 00:34:25 +08:00
|
|
|
};
|
2015-09-08 00:34:50 +08:00
|
|
|
healthCheck.check(function(err) {
|
2015-03-26 00:15:41 +08:00
|
|
|
assert.equal(err, null);
|
2015-03-26 01:39:45 +08:00
|
|
|
fs.readFile = readFileFn;
|
2015-05-13 00:34:25 +08:00
|
|
|
done();
|
2015-03-26 00:15:41 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|