2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../support/test-helper');
|
2016-01-21 20:33:45 +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');
|
2019-10-07 15:40:50 +08:00
|
|
|
var OverviewsMetadataBackend = require('../../lib/backends/overviews-metadata');
|
2016-01-21 20:33:45 +08:00
|
|
|
|
|
|
|
|
2018-04-10 01:47:24 +08:00
|
|
|
describe('OverviewsMetadataBackend', function() {
|
2016-01-21 20:33:45 +08:00
|
|
|
|
2018-04-10 01:47:24 +08:00
|
|
|
var overviewsMetadataBackend;
|
2016-01-21 20:33:45 +08:00
|
|
|
|
|
|
|
before(function() {
|
|
|
|
var redisPool = new RedisPool(global.environment.redis);
|
|
|
|
var metadataBackend = cartodbRedis({pool: redisPool});
|
|
|
|
var pgConnection = new PgConnection(metadataBackend);
|
|
|
|
var pgQueryRunner = new PgQueryRunner(pgConnection);
|
2018-04-10 01:47:24 +08:00
|
|
|
overviewsMetadataBackend = new OverviewsMetadataBackend(pgQueryRunner);
|
2016-01-21 20:33:45 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return an empty relation for tables that have no overviews', function(done) {
|
|
|
|
var query = 'select * from test_table';
|
2018-04-10 01:47:24 +08:00
|
|
|
overviewsMetadataBackend.getOverviewsMetadata('localhost', query, function(err, result) {
|
2016-01-21 20:33:45 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.deepEqual(result, {});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return overviews metadata', function(done) {
|
|
|
|
var query = 'select * from test_table_overviews';
|
2018-04-10 01:47:24 +08:00
|
|
|
overviewsMetadataBackend.getOverviewsMetadata('localhost', query, function(err, result) {
|
2016-01-21 20:33:45 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.deepEqual(result, {
|
2016-01-26 18:38:21 +08:00
|
|
|
'test_table_overviews': {
|
2016-04-20 23:47:43 +08:00
|
|
|
schema: 'public',
|
|
|
|
1: { table: '_vovw_1_test_table_overviews' },
|
|
|
|
2: { table: '_vovw_2_test_table_overviews' }
|
2016-01-21 20:33:45 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|