Windshaft-cartodb/test/integration/pg-query-runner-test.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

'use strict';
require('../support/test-helper');
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');
var PgQueryRunner = require('../../lib/backends/pg-query-runner');
2019-10-22 01:07:24 +08:00
describe('PgQueryRunner', function () {
var queryRunner;
2019-10-22 01:07:24 +08:00
before(function () {
var redisPool = new RedisPool(global.environment.redis);
2019-10-22 01:07:24 +08:00
var metadataBackend = cartodbRedis({ pool: redisPool });
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) {
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) {
assert.ok(!err, err);
assert.ok(Array.isArray(result));
assert.strictEqual(result.length, 3);
done();
});
});
2019-10-22 01:07:24 +08:00
it('should receive rows array even on error', function (done) {
var query = 'select __error___ from test_table';
2019-10-22 01:07:24 +08:00
queryRunner.run('localhost', query, function (err, result) {
assert.ok(err);
assert.ok(Array.isArray(result));
assert.strictEqual(result.length, 0);
done();
});
});
});