Windshaft-cartodb/test/acceptance/health_check.js

95 lines
2.3 KiB
JavaScript
Raw Normal View History

2014-11-05 22:42:28 +08:00
var helper = require(__dirname + '/../support/test_helper');
var assert = require('../support/assert');
var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/cartodb_windshaft');
var serverOptions = require(__dirname + '/../../lib/cartodb/server_options')();
var server = new CartodbWindshaft(serverOptions);
var metadataBackend = {};
var tilelive = {};
var HealthCheck = require('../../lib/cartodb/monitoring/health_check');
var healthCheck = new HealthCheck(metadataBackend, tilelive);
suite('health checks', function () {
function resetHealthConfig() {
global.environment.health = {
enabled: true,
username: 'localhost',
z: 0,
x: 0,
y: 0
2014-11-05 22:42:28 +08:00
};
}
var healthCheckRequest = {
url: '/health',
method: 'GET',
headers: {
host: 'localhost'
}
};
test('returns 200 and ok=true with enabled configuration', function (done) {
resetHealthConfig();
assert.response(server,
healthCheckRequest,
{
status: 200
},
function (res, err) {
assert.ok(!err);
var parsed = JSON.parse(res.body);
assert.ok(parsed.enabled);
assert.ok(parsed.ok);
done();
}
);
});
2014-11-05 22:42:28 +08:00
test('error if disabled file exists', function(done) {
var fs = require('fs');
2015-03-26 01:41:27 +08:00
var readFileFn = fs.readFile
fs.readFile = function(filename, callback) {
callback(null, "Maintenance");
}
healthCheck.check(null, function(err, result) {
assert.equal(err.message, "Maintenance");
assert.equal(err.http_status, 503);
done();
2015-03-26 01:41:27 +08:00
fs.readFile = readFileFn;
});
});
test('not err if disabled file does not exists', function(done) {
resetHealthConfig();
global.environment.disabled_file = '/tmp/ftreftrgtrccre';
assert.response(server,
healthCheckRequest,
{
status: 200
},
function (res, err) {
assert.ok(!err);
var parsed = JSON.parse(res.body);
assert.equal(parsed.enabled, true);
assert.equal(parsed.ok, true);
done();
}
);
});
});