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) {
global.settings.health = {
enabled: true,
username: 'vizzuality',
query: 'select 1::text'
enabled: true
//username: 'vizzuality',
//query: 'select 1::text'
};
done();
});
@ -65,52 +65,52 @@ suite('health checks', function() {
);
});
test('fails for invalid user because it is not in redis', function(done) {
global.settings.health.username = 'invalid';
//test('fails for invalid user because it is not in redis', function(done) {
// global.settings.health.username = 'invalid';
assert.response(app,
healthCheckRequest,
{
status: 503
},
function(res, err) {
assert.ok(!err);
// assert.response(app,
// healthCheckRequest,
// {
// status: 503
// },
// function(res, err) {
// assert.ok(!err);
var parsed = JSON.parse(res.body);
// var parsed = JSON.parse(res.body);
assert.equal(parsed.enabled, true);
assert.equal(parsed.ok, false);
// assert.equal(parsed.enabled, true);
// 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) {
global.settings.health.query = 'select wadus query';
//test('fails for wrong query', function(done) {
// global.settings.health.query = 'select wadus query';
assert.response(app,
healthCheckRequest,
{
status: 503
},
function(res, err) {
assert.ok(!err);
// assert.response(app,
// healthCheckRequest,
// {
// status: 503
// },
// function(res, err) {
// assert.ok(!err);
var parsed = JSON.parse(res.body);
// var parsed = JSON.parse(res.body);
assert.equal(parsed.enabled, true);
assert.equal(parsed.ok, false);
// assert.equal(parsed.enabled, true);
// 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() {
beforeEach(function(done) {
mockGetAllUserDBParams(function(username, callback) {
callback(null, {user: 'fake', dbname: 'fake'});
});
//beforeEach(function(done) {
// mockGetAllUserDBParams(function(username, callback) {
// callback(null, {user: 'fake', dbname: 'fake'});
// });
mockQuery(function(query, callback) {
callback(null, {rows: [{},{},{}]});
});
// mockQuery(function(query, callback) {
// callback(null, {rows: [{},{},{}]});
// });
done();
});
// done();
//});
test('happy case, everything goes OK', function(done) {
healthCheck.check('fake', 'select 1::text', function(err, result) {
assert.ok(result.redis.ok);
assert.ok(result.redis.elapsed >= 0);
assert.equal(result.redis.count, 2);
//test('happy case, everything goes OK', function(done) {
// healthCheck.check('fake', 'select 1::text', function(err, result) {
// assert.ok(result.redis.ok);
// assert.ok(result.redis.elapsed >= 0);
// assert.equal(result.redis.count, 2);
assert.ok(result.postgresql.ok);
assert.ok(result.postgresql.elapsed >= 0);
assert.ok(result.postgresql.count, 3);
// assert.ok(result.postgresql.ok);
// assert.ok(result.postgresql.elapsed >= 0);
// 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) {
mockGetAllUserDBParams(function() {
throw "Error";
});
healthCheck.check('fake', 'select 1::text', function(err, result) {
assert.equal(result.redis.ok, false);
assert.ok(result.redis.elapsed >= 0);
assert.ok(_.isUndefined(result.redis.count));
//test('error in metadataBackend reports as false and does not report postgresql except ok=false', function(done) {
// mockGetAllUserDBParams(function() {
// throw "Error";
// });
// healthCheck.check('fake', 'select 1::text', function(err, result) {
// assert.equal(result.redis.ok, false);
// assert.ok(result.redis.elapsed >= 0);
// assert.ok(_.isUndefined(result.redis.count));
assert.equal(result.postgresql.ok, false);
assert.ok(_.isUndefined(result.postgresql.elapsed));
assert.ok(_.isUndefined(result.postgresql.count));
// assert.equal(result.postgresql.ok, false);
// assert.ok(_.isUndefined(result.postgresql.elapsed));
// 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) {
mockQuery(function() {
throw "Error";
});
healthCheck.check('fake', 'select 1::text', function(err, result) {
assert.ok(result.redis.ok);
assert.ok(result.redis.elapsed >= 0);
assert.equal(result.redis.count, 2);
//test('error in metadataBackend reports as false and does not report postgresql except ok=false', function(done) {
// mockQuery(function() {
// throw "Error";
// });
// healthCheck.check('fake', 'select 1::text', function(err, result) {
// assert.ok(result.redis.ok);
// assert.ok(result.redis.elapsed >= 0);
// assert.equal(result.redis.count, 2);
assert.equal(result.postgresql.ok, false);
assert.ok(_.isUndefined(result.postgresql.elapsed));
assert.ok(_.isUndefined(result.postgresql.count));
// assert.equal(result.postgresql.ok, false);
// assert.ok(_.isUndefined(result.postgresql.elapsed));
// assert.ok(_.isUndefined(result.postgresql.count));
done();
});
});
// done();
// });
//});
test('error if disabled file exists', function(done) {
var fs = require('fs');
@ -103,11 +103,11 @@ suite('health checks', function() {
});
});
function mockGetAllUserDBParams(func) {
metadataBackend.getAllUserDBParams = func;
}
//function mockGetAllUserDBParams(func) {
// metadataBackend.getAllUserDBParams = func;
//}
function mockQuery(func) {
PSQL.prototype.query = func;
}
//function mockQuery(func) {
// PSQL.prototype.query = func;
//}
});