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);
|
|
|
|
|
2015-01-13 19:09:02 +08:00
|
|
|
suite('health checks', function () {
|
|
|
|
|
2015-01-30 23:50:06 +08:00
|
|
|
function resetHealthConfig() {
|
2015-01-13 19:09:02 +08:00
|
|
|
global.environment.health = {
|
|
|
|
enabled: true,
|
|
|
|
username: 'localhost',
|
|
|
|
z: 0,
|
|
|
|
x: 0,
|
|
|
|
y: 0
|
2014-11-05 22:42:28 +08:00
|
|
|
};
|
2015-01-30 23:50:06 +08:00
|
|
|
}
|
2015-01-13 19:09:02 +08:00
|
|
|
|
|
|
|
var healthCheckRequest = {
|
|
|
|
url: '/health',
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
test('returns 200 and ok=true with enabled configuration', function (done) {
|
2015-01-30 23:50:06 +08:00
|
|
|
resetHealthConfig();
|
|
|
|
|
2015-01-13 19:09:02 +08:00
|
|
|
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
|
|
|
|
2015-01-13 19:09:02 +08:00
|
|
|
test('fails for invalid user because it is not in redis', function (done) {
|
2015-01-30 23:50:06 +08:00
|
|
|
resetHealthConfig();
|
|
|
|
|
2015-01-13 19:09:02 +08:00
|
|
|
global.environment.health.username = 'invalid';
|
2014-11-05 22:42:28 +08:00
|
|
|
|
2015-01-13 19:09:02 +08:00
|
|
|
assert.response(server,
|
|
|
|
healthCheckRequest,
|
|
|
|
{
|
|
|
|
status: 503
|
|
|
|
},
|
|
|
|
function (res, err) {
|
|
|
|
assert.ok(!err);
|
2014-11-05 22:42:28 +08:00
|
|
|
|
2015-01-13 19:09:02 +08:00
|
|
|
var parsed = JSON.parse(res.body);
|
2014-11-05 22:42:28 +08:00
|
|
|
|
2015-01-13 19:09:02 +08:00
|
|
|
assert.equal(parsed.enabled, true);
|
|
|
|
assert.equal(parsed.ok, false);
|
2014-11-05 22:42:28 +08:00
|
|
|
|
2015-01-13 19:09:02 +08:00
|
|
|
assert.equal(parsed.result.redis.ok, false);
|
2014-11-05 22:42:28 +08:00
|
|
|
|
2015-01-13 19:09:02 +08:00
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2014-11-05 22:42:28 +08:00
|
|
|
|
2015-01-13 18:29:19 +08:00
|
|
|
});
|