Add test focused on x-cache-channel handling
This commit is contained in:
parent
7d2d585c54
commit
197c14f30f
@ -30,7 +30,7 @@
|
||||
"libxmljs": "~0.6.1"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "test/run_tests.sh ${RUNTESTFLAGS} test/unit/redis_pool.test.js test/unit/metadata.test.js test/unit/oauth.test.js test/unit/psql.test.js test/acceptance/app.test.js test/acceptance/app.auth.test.js test/acceptance/export/*.js"
|
||||
"test": "test/run_tests.sh ${RUNTESTFLAGS} test/unit/redis_pool.test.js test/unit/metadata.test.js test/unit/oauth.test.js test/unit/psql.test.js test/acceptance/app.test.js test/acceptance/app.auth.test.js test/acceptance/x-cache-channel.js test/acceptance/export/*.js"
|
||||
},
|
||||
"engines": { "node": ">= 0.4.1 < 0.9" }
|
||||
}
|
||||
|
107
test/acceptance/x-cache-channel.js
Normal file
107
test/acceptance/x-cache-channel.js
Normal file
@ -0,0 +1,107 @@
|
||||
require('../helper');
|
||||
require('../support/assert');
|
||||
|
||||
var app = require(global.settings.app_root + '/app/controllers/app')
|
||||
, assert = require('assert')
|
||||
, querystring = require('querystring')
|
||||
, _ = require('underscore')
|
||||
;
|
||||
|
||||
// allow lots of emitters to be set to silence warning
|
||||
app.setMaxListeners(0);
|
||||
|
||||
suite('x_cache_channel', function() {
|
||||
|
||||
assert.contains = function(ary, elem) {
|
||||
assert.ok(_.contains(ary,elem), 'missing "' + elem +'" from x-cache-channel: '+ ary);
|
||||
};
|
||||
|
||||
test('supports joins', function(done) {
|
||||
var query = querystring.stringify({
|
||||
q: "SELECT a.name as an, b.name as bn FROM untitle_table_4 a left join private_table b ON (a.cartodb_id = b.cartodb_id)",
|
||||
api_key: 1234
|
||||
});
|
||||
assert.response(app, {
|
||||
url: '/api/v1/sql?' + query,
|
||||
headers: {host: 'vizzuality.cartodb.com' },
|
||||
method: 'GET'
|
||||
},{ }, function(res) {
|
||||
assert.equal(res.statusCode, 200, res.body);
|
||||
// Check x-cache headers
|
||||
var cc = res.headers['x-cache-channel'].split(':');
|
||||
assert.equal(cc[0], 'cartodb_test_user_1_db');
|
||||
var tt = cc[1].split(',');
|
||||
assert.equal(tt.length, 2);
|
||||
assert.contains(tt, 'private_table');
|
||||
assert.contains(tt, 'untitle_table_4');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('supports multistatements', function(done) {
|
||||
var query = querystring.stringify({
|
||||
q: "SELECT * FROM untitle_table_4; SELECT * FROM private_table",
|
||||
api_key: 1234
|
||||
});
|
||||
assert.response(app, {
|
||||
url: '/api/v1/sql?' + query,
|
||||
headers: {host: 'vizzuality.cartodb.com' },
|
||||
method: 'GET'
|
||||
},{ }, function(res) {
|
||||
assert.equal(res.statusCode, 200, res.body);
|
||||
// Check x-cache headers
|
||||
var cc = res.headers['x-cache-channel'].split(':');
|
||||
assert.equal(cc[0], 'cartodb_test_user_1_db');
|
||||
var tt = cc[1].split(',');
|
||||
assert.equal(tt.length, 2);
|
||||
assert.contains(tt, 'private_table');
|
||||
assert.contains(tt, 'untitle_table_4');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('supports explicit transactions', function(done) {
|
||||
var query = querystring.stringify({
|
||||
q: "BEGIN; SELECT * FROM untitle_table_4; COMMIT; BEGIN; SELECT * FROM private_table; COMMIT;",
|
||||
api_key: 1234
|
||||
});
|
||||
assert.response(app, {
|
||||
url: '/api/v1/sql?' + query,
|
||||
headers: {host: 'vizzuality.cartodb.com' },
|
||||
method: 'GET'
|
||||
},{ }, function(res) {
|
||||
assert.equal(res.statusCode, 200, res.body);
|
||||
// Check x-cache headers
|
||||
var cc = res.headers['x-cache-channel'].split(':');
|
||||
assert.equal(cc[0], 'cartodb_test_user_1_db');
|
||||
var tt = cc[1].split(',');
|
||||
assert.equal(tt.length, 2);
|
||||
assert.contains(tt, 'private_table');
|
||||
assert.contains(tt, 'untitle_table_4');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('survives partial transactions', function(done) {
|
||||
var query = querystring.stringify({
|
||||
q: "BEGIN; SELECT * FROM untitle_table_4",
|
||||
api_key: 1234
|
||||
});
|
||||
assert.response(app, {
|
||||
url: '/api/v1/sql?' + query,
|
||||
headers: {host: 'vizzuality.cartodb.com' },
|
||||
method: 'GET'
|
||||
},{ }, function(res) {
|
||||
assert.equal(res.statusCode, 200, res.body);
|
||||
// Check x-cache headers
|
||||
var cc = res.headers['x-cache-channel'].split(':');
|
||||
assert.equal(cc[0], 'cartodb_test_user_1_db');
|
||||
var tt = cc[1].split(',');
|
||||
assert.equal(tt.length, 1);
|
||||
assert.contains(tt, 'untitle_table_4');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user