test remote zip files

This commit is contained in:
Konstantin Käfer 2011-01-25 10:56:00 -05:00
parent 02b0aedb1b
commit 8bd0442794
2 changed files with 49 additions and 32 deletions

View File

@ -1,7 +1,8 @@
var External = require('mess/external');
var path = require('path'),
assert = require('assert'),
fs = require('fs');
fs = require('fs'),
helper = require('./support/helper');
var env = {
data_dir: path.join(__dirname, 'data'),
@ -9,7 +10,7 @@ var env = {
};
// Delete the data directory first to start with a clean slate.
rmrf(env.data_dir);
helper.rmrf(env.data_dir);
exports['test External with local file'] = function(beforeExit) {
@ -19,7 +20,7 @@ exports['test External with local file'] = function(beforeExit) {
new External(env, 'style.mss', function(err, external) {
if (err) throw err;
assert.ok(external instanceof External)
isFile(external.path(), context);
helper.isFile(external.path(), context);
});
};
@ -30,38 +31,25 @@ exports['test External with local zipfile'] = function(beforeExit) {
new External(env, 'shapes.zip', function(err, external) {
if (err) throw err;
assert.ok(external instanceof External)
isDirectory(external.path(), context);
isFile(path.join(external.path(), 'world_borders.dbf'), context);
isFile(path.join(external.path(), 'world_borders.prj'), context);
isFile(path.join(external.path(), 'world_borders.shp'), context);
isFile(path.join(external.path(), 'world_borders.shx'), context);
helper.isDirectory(external.path(), context);
helper.isFile(path.join(external.path(), 'world_borders.dbf'), context);
helper.isFile(path.join(external.path(), 'world_borders.prj'), context);
helper.isFile(path.join(external.path(), 'world_borders.shp'), context);
helper.isFile(path.join(external.path(), 'world_borders.shx'), context);
});
}
function isDirectory(dir, context) {
fs.stat(dir, function(err, stats) {
exports['test External with remote zipfile'] = function(beforeExit) {
var context = { tests: 0 };
beforeExit(function() { assert.equal(context.tests, 5); });
new External(env, 'http://cascadenik-sampledata.s3.amazonaws.com/world_borders.zip', function(err, external) {
if (err) throw err;
assert.ok(stats.isDirectory());
context.tests++;
assert.ok(external instanceof External)
helper.isDirectory(external.path(), context);
helper.isFile(path.join(external.path(), 'world_borders.dbf'), context);
helper.isFile(path.join(external.path(), 'world_borders.prj'), context);
helper.isFile(path.join(external.path(), 'world_borders.shp'), context);
helper.isFile(path.join(external.path(), 'world_borders.shx'), context);
});
}
function isFile(file, context) {
fs.stat(file, function(err, stats) {
if (err) throw err;
assert.ok(stats.isFile());
context.tests++;
});
}
function rmrf(p) {
try {
if (fs.statSync(p).isDirectory()) {
fs.readdirSync(p).forEach(function(file) { rmrf(path.join(p, file)); });
fs.rmdirSync(p);
}
else fs.unlinkSync(p);
} catch(err) {
if (err.errno !== process.ENOENT) throw err;
}
}

View File

@ -79,3 +79,32 @@ exports.stylize = function(str, style) {
return '\033[' + styles[style][0] + 'm' + str +
'\033[' + styles[style][1] + 'm';
};
exports.isDirectory = function(dir, context) {
fs.stat(dir, function(err, stats) {
if (err) throw err;
assert.ok(stats.isDirectory());
context.tests++;
});
};
exports.isFile = function(file, context) {
fs.stat(file, function(err, stats) {
if (err) throw err;
assert.ok(stats.isFile());
context.tests++;
});
};
exports.rmrf = function rmrf(p) {
try {
if (fs.statSync(p).isDirectory()) {
fs.readdirSync(p).forEach(function(file) { rmrf(path.join(p, file)); });
fs.rmdirSync(p);
}
else fs.unlinkSync(p);
} catch(err) {
if (err.errno !== process.ENOENT) throw err;
}
};