CartoDB-SQL-API/test/unit/health_check.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

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() {
test('error if disabled file exists', function(done) {
var fs = require('fs');
2015-03-26 01:39:45 +08:00
var readFileFn = fs.readFile;
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;
});
});
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;
fs.readFile = function(filename, callback) {
2015-03-26 01:39:45 +08:00
callback(new Error("ENOENT"), null);
}
healthCheck.check('fake', 'select 1', function(err, result) {
assert.equal(err, null);
done();
2015-03-26 01:39:45 +08:00
fs.readFile = readFileFn;
});
});
});