2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../support/test-helper');
|
2015-12-31 00:48:00 +08:00
|
|
|
|
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
var RedisPool = require('redis-mpool');
|
|
|
|
var cartodbRedis = require('cartodb-redis');
|
|
|
|
|
2019-10-07 15:43:40 +08:00
|
|
|
var PgConnection = require('../../lib/backends/pg-connection');
|
2019-10-07 15:45:46 +08:00
|
|
|
var PgQueryRunner = require('../../lib/backends/pg-query-runner');
|
2015-12-31 00:48:00 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('PgQueryRunner', function () {
|
2015-12-31 00:48:00 +08:00
|
|
|
var queryRunner;
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
before(function () {
|
2015-12-31 00:48:00 +08:00
|
|
|
var redisPool = new RedisPool(global.environment.redis);
|
2019-10-22 01:07:24 +08:00
|
|
|
var metadataBackend = cartodbRedis({ pool: redisPool });
|
2015-12-31 00:48:00 +08:00
|
|
|
var pgConnection = new PgConnection(metadataBackend);
|
|
|
|
queryRunner = new PgQueryRunner(pgConnection);
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should work for happy case', function (done) {
|
2015-12-31 00:48:00 +08:00
|
|
|
var query = 'select cartodb_id from test_table limit 3';
|
2019-10-22 01:07:24 +08:00
|
|
|
queryRunner.run('localhost', query, function (err, result) {
|
2015-12-31 00:48:00 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.ok(Array.isArray(result));
|
|
|
|
assert.equal(result.length, 3);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should receive rows array even on error', function (done) {
|
2015-12-31 00:48:00 +08:00
|
|
|
var query = 'select __error___ from test_table';
|
2019-10-22 01:07:24 +08:00
|
|
|
queryRunner.run('localhost', query, function (err, result) {
|
2015-12-31 00:48:00 +08:00
|
|
|
assert.ok(err);
|
|
|
|
|
|
|
|
assert.ok(Array.isArray(result));
|
|
|
|
assert.equal(result.length, 0);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|