Windshaft-cartodb/test/acceptance/health_check.js

119 lines
3.0 KiB
JavaScript
Raw Normal View History

'use strict';
2015-04-27 23:54:07 +08:00
require(__dirname + '/../support/test_helper');
2014-11-05 22:42:28 +08:00
var fs = require('fs');
var assert = require('../support/assert');
2019-10-07 15:40:50 +08:00
var CartodbWindshaft = require('../../lib/server');
var serverOptions = require('../../lib/server_options');
2014-11-05 22:42:28 +08:00
2015-04-27 23:54:07 +08:00
describe('health checks', function () {
function enableHealthConfig() {
global.environment.health = {
enabled: true
};
}
function disableHealthConfig() {
global.environment.health = {
enabled: false
2014-11-05 22:42:28 +08:00
};
}
var healthCheckRequest = {
url: '/health',
method: 'GET',
headers: {
host: 'localhost'
}
};
beforeEach(enableHealthConfig);
afterEach(disableHealthConfig);
var RESPONSE_OK = {
status: 200
};
var RESPONSE_FAIL = {
status: 503
};
it('returns 200 and ok=true with enabled configuration', function (done) {
2015-07-09 02:50:34 +08:00
var server = new CartodbWindshaft(serverOptions);
assert.response(server, healthCheckRequest, RESPONSE_OK, 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-04-27 23:54:07 +08:00
it('error if disabled file exists', function(done) {
var errorMessage = "Maintenance";
var readFileFn = fs.readFile;
fs.readFile = function(filename, callback) {
callback(null, errorMessage);
};
var server = new CartodbWindshaft(serverOptions);
assert.response(server, healthCheckRequest, RESPONSE_FAIL, function(res, err) {
fs.readFile = readFileFn;
assert.ok(!err);
var parsed = JSON.parse(res.body);
assert.ok(parsed.enabled);
assert.ok(!parsed.ok);
assert.equal(parsed.err, errorMessage);
2015-07-09 02:50:34 +08:00
done();
});
});
it('error if disabled file exists but has no content', function(done) {
var readFileFn = fs.readFile;
fs.readFile = function(filename, callback) {
callback(null, '');
};
var server = new CartodbWindshaft(serverOptions);
assert.response(server, healthCheckRequest, RESPONSE_FAIL, function(res, err) {
fs.readFile = readFileFn;
assert.ok(!err);
var parsed = JSON.parse(res.body);
assert.ok(parsed.enabled);
assert.ok(!parsed.ok);
assert.equal(parsed.err, 'Unknown error');
done();
});
});
2018-08-16 18:16:20 +08:00
it('not err if disabled file does not exist', function(done) {
global.environment.disabled_file = '/tmp/ftreftrgtrccre';
var server = new CartodbWindshaft(serverOptions);
assert.response(server, healthCheckRequest, RESPONSE_OK, function (res, err) {
assert.ok(!err);
var parsed = JSON.parse(res.body);
assert.equal(parsed.enabled, true);
assert.equal(parsed.ok, true);
done();
});
2016-01-29 02:44:25 +08:00
});
});