From 015623f9ae8b3ec2edc6780163f4eff2e2bbac9f Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Fri, 11 Oct 2013 13:50:41 +0400 Subject: [PATCH] making various test cases work --- lib/local-fs.js | 11 ++++++++--- lib/storage.js | 1 + lib/up-storage.js | 1 + test/basic.js | 8 ++++++++ test/config-1.yaml | 2 +- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/local-fs.js b/lib/local-fs.js index 720b84f9b..b1765d8c1 100644 --- a/lib/local-fs.js +++ b/lib/local-fs.js @@ -50,6 +50,7 @@ function write_stream(name) { var tmpname = name + '.tmp-'+String(Math.random()).replace(/^0\./, ''); var file = fs.createWriteStream(tmpname); + var opened = false; stream.pipe(file); stream.done = function() { @@ -69,12 +70,16 @@ function write_stream(name) { } }; stream.abort = function() { - file.on('close', function() { - fs.unlink(tmpname, function(){}); - }); + if (opened) { + opened = false; + file.on('close', function() { + fs.unlink(tmpname, function(){}); + }); + } file.destroySoon(); }; file.on('open', function() { + opened = true; // re-emitting open because it's handled in storage.js stream.emit('open'); }); diff --git a/lib/storage.js b/lib/storage.js index c59841fcb..6a032482a 100644 --- a/lib/storage.js +++ b/lib/storage.js @@ -277,6 +277,7 @@ Storage.prototype.get_tarball = function(name, filename) { var savestream = self.local.add_tarball(name, filename); savestream.on('error', function(err) { + savestream.abort(); stream.emit('error', err); }); savestream.on('open', function() { diff --git a/lib/up-storage.js b/lib/up-storage.js index 3a22c46a6..00bf61002 100644 --- a/lib/up-storage.js +++ b/lib/up-storage.js @@ -49,6 +49,7 @@ Storage.prototype.request = function(options, cb) { if (typeof(options.json) === 'object' && options.json != null) { var json = JSON.stringify(options.json); + headers['content-type'] = headers['content-type'] || 'application/json'; } var req = request({ diff --git a/test/basic.js b/test/basic.js index d6ae17d94..d1613b115 100644 --- a/test/basic.js +++ b/test/basic.js @@ -43,6 +43,14 @@ ex['uploading new tarball'] = function(cb) { }); }; +ex['doubleerr test'] = function(cb) { + server.put_tarball('testfwd2', 'blahblah', readfile('fixtures/binary'), function(res, body) { + assert.equal(res.statusCode, 404); + assert(body.error); + cb(); + }); +}; + ex['downloading newly created tarball'] = function(cb) { server.get_tarball('testpkg', 'blahblah', function(res, body) { assert.equal(res.statusCode, 200); diff --git a/test/config-1.yaml b/test/config-1.yaml index 7e7b0cdd3..0e308affb 100644 --- a/test/config-1.yaml +++ b/test/config-1.yaml @@ -9,7 +9,7 @@ uplinks: url: http://localhost:55552/ packages: - 'testfwd': + 'testfwd*': allow_access: all allow_publish: all proxy_access: server2