Skip to content

Commit

Permalink
Merge pull request #311 from CartoDB/fix-tests
Browse files Browse the repository at this point in the history
Fix tests
  • Loading branch information
Raul Ochoa committed Mar 27, 2015
2 parents 0903475 + fbaa06d commit 1eb7e5c
Show file tree
Hide file tree
Showing 36 changed files with 306 additions and 922 deletions.
17 changes: 17 additions & 0 deletions Makefile
Expand Up @@ -20,6 +20,23 @@ test:
test/integration/renderers/*.js \
test/acceptance/*.js

test-acceptance:
@echo "***acceptance tests***"
@$(SHELL) ./run_tests.sh ${RUNTESTFLAGS} \
test/acceptance/*.js

test-integration:
@echo "***integration tests***"
@$(SHELL) ./run_tests.sh ${RUNTESTFLAGS} \
test/integration/renderers/*.js

test-unit:
@echo "***unit tests***"
@$(SHELL) ./run_tests.sh ${RUNTESTFLAGS} \
test/unit/*.js \
test/unit/renderers/*.js \
test/unit/controllers/*.js

jshint:
@echo "***jshint***"
@./node_modules/.bin/jshint lib/ test/
Expand Down
4 changes: 2 additions & 2 deletions run_tests.sh
Expand Up @@ -86,10 +86,10 @@ PATH=node_modules/.bin/:$PATH

if test x"$OPT_COVERAGE" = xyes; then
echo "Running tests with coverage"
./node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- -u tdd -t 5000 ${TESTS}
./node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- -u bdd -t 5000 ${TESTS}
else
echo "Running tests"
mocha -u tdd -t 5000 ${TESTS}
./node_modules/.bin/_mocha -u bdd -t 5000 ${TESTS}
fi
ret=$?

Expand Down
54 changes: 5 additions & 49 deletions test/acceptance/attributes.js
Expand Up @@ -6,13 +6,7 @@ var step = require('step');
var Windshaft = require('../../lib/windshaft');
var ServerOptions = require('../support/server_options');

suite('attributes', function() {

////////////////////////////////////////////////////////////////////
//
// SETUP
//
////////////////////////////////////////////////////////////////////
describe('attributes', function() {

var server = new Windshaft.Server(ServerOptions);
server.setMaxListeners(0);
Expand Down Expand Up @@ -40,18 +34,7 @@ suite('attributes', function() {
assert.equal(res.headers['access-control-allow-origin'], '*');
}

suiteSetup(function(done) {

// Check that we start with an empty redis db
redis_client.keys("*", function(err, matches) {
if ( err ) { done(err); return; }
assert.equal(matches.length, 0, "redis keys present at setup time:\n" + matches.join("\n"));
done();
});

});

test("can only be fetched from layer having an attributes spec",
it("can only be fetched from layer having an attributes spec",
function(done) {

var expected_token;
Expand Down Expand Up @@ -156,7 +139,7 @@ suite('attributes', function() {
});

// See https://github.com/CartoDB/Windshaft/issues/131
test("are checked at map creation time",
it("are checked at map creation time",
function(done) {

// clone the mapconfig test
Expand Down Expand Up @@ -193,7 +176,7 @@ suite('attributes', function() {
);
});

test("can be used with jsonp", function(done) {
it("can be used with jsonp", function(done) {

var expected_token;
step(
Expand Down Expand Up @@ -283,7 +266,7 @@ suite('attributes', function() {
//
// Test for http://github.com/CartoDB/Windshaft/issues/130
//
test("database access is read-only", function(done) {
it("database access is read-only", function(done) {

// clone the mapconfig test
var mapconfig = JSON.parse(JSON.stringify(test_mapconfig_1));
Expand Down Expand Up @@ -319,31 +302,4 @@ suite('attributes', function() {
);
});

////////////////////////////////////////////////////////////////////
//
// TEARDOWN
//
////////////////////////////////////////////////////////////////////

suiteTeardown(function(done) {

// Check that we left the redis db empty
redis_client.keys("*", function(err, matches) {
try {
assert.equal(matches.length, 0, "Left over redis keys:\n" + matches.join("\n"));
} catch (err2) {
if ( err ) {
err.message += '\n' + err2.message;
} else {
err = err2;
}
}
redis_client.flushall(function() {
done(err);
});
});

});

});

37 changes: 3 additions & 34 deletions test/acceptance/blend.js
@@ -1,25 +1,12 @@
require('../support/test_helper');

var assert = require('../support/assert');
var redis = require('redis');
var testClient = require('../support/test_client');

suite('blend png renderer', function() {
describe('blend png renderer', function() {

var IMAGE_TOLERANCE_PER_MIL = 20;

var redisClient = redis.createClient(global.environment.redis.port);

suiteSetup(function(done) {
// Check that we start with an empty redis db
redisClient.keys("*", function(err, matches) {
if (err) {
return done(err);
}
assert.equal(matches.length, 0, "redis keys present at setup time:\n" + matches.join("\n"));
done();
});
});

function plainTorqueMapConfig(plainColor) {
return {
version: '1.2.0',
Expand Down Expand Up @@ -93,7 +80,7 @@ suite('blend png renderer', function() {
testScenarios.forEach(function(testScenario) {
var tileRequest = testScenario.tile;
var zxy = [tileRequest.z, tileRequest.x, tileRequest.y];
test('tile all/' + zxy.join('/') + '.png', function (done) {
it('tile all/' + zxy.join('/') + '.png', function (done) {
testClient.getTileLayer(plainTorqueMapConfig(testScenario.plainColor), tileRequest, function(err, res) {
assert.imageEqualsFile(res.body, blendPngFixture(zxy), IMAGE_TOLERANCE_PER_MIL, function(err) {
assert.ok(!err);
Expand All @@ -102,22 +89,4 @@ suite('blend png renderer', function() {
});
});
});

suiteTeardown(function(done) {
// Check that we left the redis db empty
redisClient.keys("*", function(err, matches) {
try {
assert.equal(matches.length, 0, "Left over redis keys:\n" + matches.join("\n"));
} catch (err2) {
if (err) {
err.message += '\n' + err2.message;
} else {
err = err2;
}
}
redisClient.flushall(function() {
return done(err);
});
});
});
});
62 changes: 10 additions & 52 deletions test/acceptance/external_resources.js
Expand Up @@ -2,7 +2,6 @@ require('../support/test_helper');

var assert = require('../support/assert');
var fs = require('fs');
var redis = require('redis');
var Windshaft = require('../../lib/windshaft');
var ServerOptions = require('../support/server_options');
var http = require('http');
Expand All @@ -22,34 +21,17 @@ function rmdir_recursive_sync(dirname) {
}
}

suite('external resources', function() {

////////////////////////////////////////////////////////////////////
//
// SETUP
//
////////////////////////////////////////////////////////////////////
describe('external resources', function() {

var server = new Windshaft.Server(ServerOptions);
server.setMaxListeners(0);
var redis_client = redis.createClient(ServerOptions.redis.port);
var res_serv; // resources server
var res_serv_status = { numrequests:0 }; // status of resources server
var res_serv_port = 8033; // FIXME: make configurable ?

var IMAGE_EQUALS_TOLERANCE_PER_MIL = 25;

suiteSetup(function(done) {

// Check that we start with an empty redis db
redis_client.keys("*", function(err, matches) {

if ( err ) { done(err); return; }

assert.equal(matches.length, 0,
"redis keys present at setup time on port " +
ServerOptions.redis.port + ":\n" + matches.join("\n"));

before(function(done) {
// Start a server to test external resources
res_serv = http.createServer( function(request, response) {
++res_serv_status.numrequests;
Expand All @@ -66,9 +48,6 @@ suite('external resources', function() {
});
});
res_serv.listen(res_serv_port, done);

});

});

function imageCompareFn(fixture, done) {
Expand All @@ -80,7 +59,7 @@ suite('external resources', function() {
};
}

test("basic external resource", function(done) {
it("basic external resource", function(done) {

var circleStyle = "#test_table_3 { marker-file: url('http://localhost:" + res_serv_port +
"/circle.svg'); marker-transform:'scale(0.2)'; }";
Expand All @@ -89,7 +68,7 @@ suite('external resources', function() {
imageCompareFn('test_table_13_4011_3088_svg1.png', done));
});

test("different external resource", function(done) {
it("different external resource", function(done) {

var squareStyle = "#test_table_3 { marker-file: url('http://localhost:" + res_serv_port +
"/square.svg'); marker-transform:'scale(0.2)'; }";
Expand All @@ -99,7 +78,7 @@ suite('external resources', function() {
});

// See http://github.com/CartoDB/Windshaft/issues/107
test("external resources get localized on renderer creation if not locally cached", function(done) {
it("external resources get localized on renderer creation if not locally cached", function(done) {

var options = {
serverOptions: ServerOptions
Expand Down Expand Up @@ -128,7 +107,7 @@ suite('external resources', function() {
});
});

test("referencing unexistant external resources returns an error", function(done) {
it("referencing unexistant external resources returns an error", function(done) {
var url = "http://localhost:" + res_serv_port + "/notfound.png";
var style = "#test_table_3{marker-file: url('" + url + "'); marker-transform:'scale(0.2)'; }";

Expand All @@ -143,32 +122,11 @@ suite('external resources', function() {
});


suiteTeardown(function(done) {

// Close the resources server
res_serv.close();

var errors = [];

// Check that we left the redis db empty
redis_client.keys("*", function(err, matches) {
if ( err ) {
errors.push(err);
}
try {
assert.equal(matches.length, 0, "Left over redis keys:\n" + matches.join("\n"));
} catch (err) {
errors.push(err);
}

var cachedir = global.environment.millstone.cache_basedir;
rmdir_recursive_sync(cachedir);

redis_client.flushall(function() {
done(errors.length ? new Error(errors) : null);
});
});
after(function(done) {
rmdir_recursive_sync(global.environment.millstone.cache_basedir);

// Close the resources server
res_serv.close(done);
});
});

0 comments on commit 1eb7e5c

Please sign in to comment.