Health check will always return error if file is found even if empty

This commit is contained in:
Raul Ochoa 2015-09-22 15:15:57 +02:00
parent ac7b02a434
commit b617bb0277
2 changed files with 7 additions and 7 deletions

View File

@ -10,8 +10,8 @@ module.exports = HealthCheck;
HealthCheck.prototype.check = function(callback) { HealthCheck.prototype.check = function(callback) {
fs.readFile(this.disableFile, function handleDisabledFile(err, data) { fs.readFile(this.disableFile, function handleDisabledFile(err, data) {
var disabledError = null; var disabledError = null;
if (!!data) { if (!err) {
disabledError = new Error(data); disabledError = new Error(data || 'Unknown error');
disabledError.http_status = 503; disabledError.http_status = 503;
} }
return callback(disabledError); return callback(disabledError);

View File

@ -76,21 +76,21 @@ describe('health checks', function () {
}); });
}); });
it('no error if disabled file exists but has no content', function(done) { it('error if disabled file exists but has no content', function(done) {
var readFileFn = fs.readFile; var readFileFn = fs.readFile;
fs.readFile = function(filename, callback) { fs.readFile = function(filename, callback) {
callback(null, ''); callback(null, '');
}; };
var server = new CartodbWindshaft(serverOptions); var server = new CartodbWindshaft(serverOptions);
assert.response(server, healthCheckRequest, RESPONSE_OK, function(res, err) { assert.response(server, healthCheckRequest, RESPONSE_FAIL, function(res, err) {
fs.readFile = readFileFn; fs.readFile = readFileFn;
assert.ok(!err); assert.ok(!err);
var parsed = JSON.parse(res.body); var parsed = JSON.parse(res.body);
assert.ok(parsed.enabled);
assert.equal(parsed.enabled, true); assert.ok(!parsed.ok);
assert.equal(parsed.ok, true); assert.equal(parsed.err, 'Unknown error');
done(); done();
}); });