Skip to content

Commit

Permalink
fix tests and add md5 sums
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaefer committed Jun 21, 2011
1 parent ad35cd2 commit 8083554
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 45 deletions.
4 changes: 2 additions & 2 deletions lib/node-get/node-get.js
Expand Up @@ -206,7 +206,7 @@ Get.prototype.asString = function(callback) {
switch ((response.headers['content-type'] || '').toLowerCase()) {
case 'binary/octet-stream':
case 'application/octet-stream':
return callback(new Error("Can't download binary file"));
return callback(new Error("Can't download binary file as string"));
default:
// TODO: respect Content-Transfer-Encoding header
response.setEncoding(this.guessEncoding(this.uri));
Expand All @@ -232,7 +232,7 @@ Get.prototype.asString = function(callback) {
// - @param {Function} callback.
Get.prototype.asBuffer = function(callback) {
this.perform(function(err, response) {
if (err) { callback(err); return; }
if (err) return callback(err);

// Don't set an encoding.

Expand Down
93 changes: 50 additions & 43 deletions test/basic.test.js
Expand Up @@ -21,49 +21,51 @@ exports['test constructor'] = function(beforeExit) {
var completed = {
perform: 0,
toDisk: 0,
asString: 0
asString: 0,
asBuffer: 0
};

var files = [
{
url: 'http://tilemill-data.s3.amazonaws.com/couchsurf.kml',
bin: false,
md5: '96b31a84f667007a2296edd78fb77c28'
} /*,
{
url: 'http://tilemill-data.s3.amazonaws.com/couchsurf.kml',
bin: false
},
{
url: 'http://tilemill-data.s3.amazonaws.com/images/paperfolds_256.png',
bin: true,
md5: 'a99502016d4e2124cf2dc4775aafc256'
},
{
url: 'http://tilemill-data.s3.amazonaws.com/test_data/ipsum.json',
bin: false
},
{
url: 'http://tilemill-data.s3.amazonaws.com/test_data/README.txt',
bin: false
},
{
url: 'http://tilemill-data.s3.amazonaws.com/test_data/shape_demo.zip',
bin: true
},
{
url: 'http://tilemill-data.s3.amazonaws.com/nasa_raster/lasvegas_tm5_12jan09_crop_geo_merc_small.tif',
bin: true
},
{
url: 'http://dcatlas.dcgis.dc.gov/catalog/download.asp?downloadID=2315&downloadTYPE=ESRI',
bin: true
md5: '96b31a84f667007a2296edd78fb77c28'
},
{
url: 'http://www.gdal.org/ogr/drv_sqlite.html',
bin: false
}
*/
// {
// url: 'http://tilemill-data.s3.amazonaws.com/images/paperfolds_256.png',
// bin: true,
// md5: 'a99502016d4e2124cf2dc4775aafc256'
// },
// {
// url: 'http://tilemill-data.s3.amazonaws.com/test_data/ipsum.json',
// bin: true,
// md5: '651ea0ff31786e9be9012112b21573be'
// },
// {
// url: 'http://tilemill-data.s3.amazonaws.com/test_data/README.txt',
// bin: false,
// md5: '46d883d71e795d7c8a65c9b1a6673dd2'
// },
// {
// url: 'http://tilemill-data.s3.amazonaws.com/test_data/shape_demo.zip',
// bin: true,
// md5: 'b5ff3545922cc9e0c750fb7263a7a3d3'
// },
// {
// url: 'http://tilemill-data.s3.amazonaws.com/nasa_raster/lasvegas_tm5_12jan09_crop_geo_merc_small.tif',
// bin: true,
// md5: '3b97134839042fcab0d0ee8ea76f73c4'
// },
// {
// url: 'http://dcatlas.dcgis.dc.gov/catalog/download.asp?downloadID=2315&downloadTYPE=ESRI',
// bin: true,
// md5: 'ac629823b373e7308087264d9f00ef5c'
// },
// {
// url: 'http://www.gdal.org/ogr/drv_sqlite.html',
// bin: false,
// md5: '65d2a7f9e8bc5b8861a06af6597d7650'
// }
];

files.forEach(function(reference, i) {
Expand All @@ -79,7 +81,7 @@ exports['test constructor'] = function(beforeExit) {
if (reference.error) {
assert.eql(err, reference.error, 'This should have had an error');
} else if (err) {
throw err;
throw new Error(err);
} else {
result.on('data', function(chunk) {
body.push(chunk);
Expand All @@ -96,7 +98,7 @@ exports['test constructor'] = function(beforeExit) {
if (reference.error) {
assert.equal(err.message, reference.error);
} else if (err) {
throw err;
throw new Error(err);
} else {
assert.equal(md5(fs.readFileSync(result)), reference.md5);
}
Expand All @@ -105,20 +107,24 @@ exports['test constructor'] = function(beforeExit) {
new get(req).asString(function(err, result) {
completed.asString++;

if (!reference.bin && err) {
assert.equal(err.message, "Can't download binary file");
if (reference.bin && err) {
assert.equal(err.message, "Can't download binary file as string");
} else if (reference.error) {
assert.equal(err.message, reference.error);
} else if (err) {
throw err;
throw new Error(err);
} else {
assert.equal(md5(result), reference.md5);
}
});

new get(req).asBuffer(function(err, result) {
completed.asBuffer++;

if (reference.error) {
assert.eql(err, reference.error);
assert.equal(err.message, reference.error);
} else if (err) {
throw err;
} else {
assert.equal(md5(result), reference.md5);
}
Expand All @@ -129,7 +135,8 @@ exports['test constructor'] = function(beforeExit) {
assert.deepEqual(completed, {
perform: files.length,
toDisk: files.length,
asString: files.length
asString: files.length,
asBuffer: files.length
});
});
};
Expand Down

0 comments on commit 8083554

Please sign in to comment.