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

48 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-10-24 21:42:33 +08:00
'use strict';
require('../helper');
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);
describe('health checks', function() {
2014-08-27 00:40:58 +08:00
it('errors 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(function(err) {
assert.equal(err.message, "Maintenance");
assert.equal(err.http_status, 503);
2015-03-26 01:39:45 +08:00
fs.readFile = readFileFn;
done();
});
});
it('does not err if disabled file does not exists', function(done) {
var fs = require('fs');
2018-10-24 21:42:33 +08:00
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(function(err) {
assert.equal(err, null);
2015-03-26 01:39:45 +08:00
fs.readFile = readFileFn;
done();
});
});
});