Disable per user health checks tests

This commit is contained in:
Luis Bosque 2015-04-06 16:44:01 +02:00
parent d3409bdf3c
commit 21cbdfd4a3
2 changed files with 92 additions and 92 deletions

View File

@ -10,9 +10,9 @@ suite('health checks', function() {
beforeEach(function(done) { beforeEach(function(done) {
global.settings.health = { global.settings.health = {
enabled: true, enabled: true
username: 'vizzuality', //username: 'vizzuality',
query: 'select 1::text' //query: 'select 1::text'
}; };
done(); done();
}); });
@ -65,52 +65,52 @@ suite('health checks', function() {
); );
}); });
test('fails for invalid user because it is not in redis', function(done) { //test('fails for invalid user because it is not in redis', function(done) {
global.settings.health.username = 'invalid'; // global.settings.health.username = 'invalid';
assert.response(app, // assert.response(app,
healthCheckRequest, // healthCheckRequest,
{ // {
status: 503 // status: 503
}, // },
function(res, err) { // function(res, err) {
assert.ok(!err); // assert.ok(!err);
var parsed = JSON.parse(res.body); // var parsed = JSON.parse(res.body);
assert.equal(parsed.enabled, true); // assert.equal(parsed.enabled, true);
assert.equal(parsed.ok, false); // assert.equal(parsed.ok, false);
assert.equal(parsed.result.redis.ok, false); // assert.equal(parsed.result.redis.ok, false);
done(); // done();
} // }
); // );
}); //});
test('fails for wrong query', function(done) { //test('fails for wrong query', function(done) {
global.settings.health.query = 'select wadus query'; // global.settings.health.query = 'select wadus query';
assert.response(app, // assert.response(app,
healthCheckRequest, // healthCheckRequest,
{ // {
status: 503 // status: 503
}, // },
function(res, err) { // function(res, err) {
assert.ok(!err); // assert.ok(!err);
var parsed = JSON.parse(res.body); // var parsed = JSON.parse(res.body);
assert.equal(parsed.enabled, true); // assert.equal(parsed.enabled, true);
assert.equal(parsed.ok, false); // assert.equal(parsed.ok, false);
assert.ok(parsed.result.redis.ok); // assert.ok(parsed.result.redis.ok);
assert.equal(parsed.result.postgresql.ok, false); // assert.equal(parsed.result.postgresql.ok, false);
done(); // done();
} // }
); // );
}); //});
}); });

View File

@ -14,65 +14,65 @@ var healthCheck = new HealthCheck(metadataBackend, PSQL);
suite('health checks', function() { suite('health checks', function() {
beforeEach(function(done) { //beforeEach(function(done) {
mockGetAllUserDBParams(function(username, callback) { // mockGetAllUserDBParams(function(username, callback) {
callback(null, {user: 'fake', dbname: 'fake'}); // callback(null, {user: 'fake', dbname: 'fake'});
}); // });
mockQuery(function(query, callback) { // mockQuery(function(query, callback) {
callback(null, {rows: [{},{},{}]}); // callback(null, {rows: [{},{},{}]});
}); // });
done(); // done();
}); //});
test('happy case, everything goes OK', function(done) { //test('happy case, everything goes OK', function(done) {
healthCheck.check('fake', 'select 1::text', function(err, result) { // healthCheck.check('fake', 'select 1::text', function(err, result) {
assert.ok(result.redis.ok); // assert.ok(result.redis.ok);
assert.ok(result.redis.elapsed >= 0); // assert.ok(result.redis.elapsed >= 0);
assert.equal(result.redis.count, 2); // assert.equal(result.redis.count, 2);
assert.ok(result.postgresql.ok); // assert.ok(result.postgresql.ok);
assert.ok(result.postgresql.elapsed >= 0); // assert.ok(result.postgresql.elapsed >= 0);
assert.ok(result.postgresql.count, 3); // assert.ok(result.postgresql.count, 3);
done(); // done();
}); // });
}); //});
test('error in metadataBackend reports as false and does not report postgresql except ok=false', function(done) { //test('error in metadataBackend reports as false and does not report postgresql except ok=false', function(done) {
mockGetAllUserDBParams(function() { // mockGetAllUserDBParams(function() {
throw "Error"; // throw "Error";
}); // });
healthCheck.check('fake', 'select 1::text', function(err, result) { // healthCheck.check('fake', 'select 1::text', function(err, result) {
assert.equal(result.redis.ok, false); // assert.equal(result.redis.ok, false);
assert.ok(result.redis.elapsed >= 0); // assert.ok(result.redis.elapsed >= 0);
assert.ok(_.isUndefined(result.redis.count)); // assert.ok(_.isUndefined(result.redis.count));
assert.equal(result.postgresql.ok, false); // assert.equal(result.postgresql.ok, false);
assert.ok(_.isUndefined(result.postgresql.elapsed)); // assert.ok(_.isUndefined(result.postgresql.elapsed));
assert.ok(_.isUndefined(result.postgresql.count)); // assert.ok(_.isUndefined(result.postgresql.count));
done(); // done();
}); // });
}); //});
test('error in metadataBackend reports as false and does not report postgresql except ok=false', function(done) { //test('error in metadataBackend reports as false and does not report postgresql except ok=false', function(done) {
mockQuery(function() { // mockQuery(function() {
throw "Error"; // throw "Error";
}); // });
healthCheck.check('fake', 'select 1::text', function(err, result) { // healthCheck.check('fake', 'select 1::text', function(err, result) {
assert.ok(result.redis.ok); // assert.ok(result.redis.ok);
assert.ok(result.redis.elapsed >= 0); // assert.ok(result.redis.elapsed >= 0);
assert.equal(result.redis.count, 2); // assert.equal(result.redis.count, 2);
assert.equal(result.postgresql.ok, false); // assert.equal(result.postgresql.ok, false);
assert.ok(_.isUndefined(result.postgresql.elapsed)); // assert.ok(_.isUndefined(result.postgresql.elapsed));
assert.ok(_.isUndefined(result.postgresql.count)); // assert.ok(_.isUndefined(result.postgresql.count));
done(); // done();
}); // });
}); //});
test('error if disabled file exists', function(done) { test('error if disabled file exists', function(done) {
var fs = require('fs'); var fs = require('fs');
@ -103,11 +103,11 @@ suite('health checks', function() {
}); });
}); });
function mockGetAllUserDBParams(func) { //function mockGetAllUserDBParams(func) {
metadataBackend.getAllUserDBParams = func; // metadataBackend.getAllUserDBParams = func;
} //}
function mockQuery(func) { //function mockQuery(func) {
PSQL.prototype.query = func; // PSQL.prototype.query = func;
} //}
}); });