2015-03-26 00:15:41 +08:00
|
|
|
require('../helper')
|
|
|
|
|
2014-08-27 00:40:58 +08:00
|
|
|
var assert = require('assert'),
|
|
|
|
_ = require('underscore'),
|
|
|
|
HealthCheck = require('../../app/monitoring/health_check');
|
|
|
|
|
|
|
|
var metadataBackend = {};
|
|
|
|
|
|
|
|
function PSQL(dbParams) {
|
|
|
|
this.params = dbParams;
|
|
|
|
}
|
|
|
|
|
|
|
|
var healthCheck = new HealthCheck(metadataBackend, PSQL);
|
|
|
|
|
|
|
|
suite('health checks', function() {
|
|
|
|
|
2015-03-26 00:15:41 +08:00
|
|
|
test('error if disabled file exists', function(done) {
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
healthCheck.check('fake', 'select 1', function(err, result) {
|
|
|
|
assert.equal(err.message, "Maintenance");
|
|
|
|
assert.equal(err.http_status, 503);
|
|
|
|
done();
|
2015-03-26 01:39:45 +08:00
|
|
|
fs.readFile = readFileFn;
|
2015-03-26 00:15:41 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('not err if disabled file does not exists', function(done) {
|
|
|
|
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) {
|
2015-03-26 01:39:45 +08:00
|
|
|
callback(new Error("ENOENT"), null);
|
2015-03-26 00:15:41 +08:00
|
|
|
}
|
|
|
|
healthCheck.check('fake', 'select 1', function(err, result) {
|
|
|
|
assert.equal(err, null);
|
|
|
|
done();
|
2015-03-26 01:39:45 +08:00
|
|
|
fs.readFile = readFileFn;
|
2015-03-26 00:15:41 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|