Skip to content

Commit

Permalink
add regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Nov 12, 2014
1 parent 10cbd2d commit f76c406
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"docs": "./scripts/docs.sh",
"lint": "jshint lib/ regression/ test/",
"test": "mocha --recursive",
"regression-test": "mocha regression/* --timeout 15000",
"regression-test": "mocha regression/* --timeout 20000",
"cover": "istanbul cover -x 'regression/*' _mocha -- --timeout 15000 test/* regression/*",
"coveralls": "istanbul cover -x 'regression/*' _mocha --report lcovonly -- --timeout 15000 test/* regression/* -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},
Expand Down
52 changes: 52 additions & 0 deletions regression/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var async = require('async');
var crypto = require('crypto');
var fs = require('fs');
var request = require('request');
var through = require('through2');
var tmp = require('tmp');
var uuid = require('node-uuid');

Expand Down Expand Up @@ -185,6 +186,57 @@ describe('storage', function() {
});
});

it('should resume an upload after an interruption', function(done) {
fs.stat(files.big.path, function(err, metadata) {
if (err) {
done(err);
return;
}

var fileSize = metadata.size;
var file = bucket.file('LargeFile');

upload({ interrupt: true }, function(err) {
if (err) {
done(err);
return;
}

upload({ interrupt: false }, function(err, metadata) {
if (err) {
done(err);
return;
}

assert.equal(metadata.size, fileSize);
file.delete(done);
});
});

function upload(opts, callback) {
var sizeStreamed = 0;

fs.createReadStream(files.big.path)
.pipe(through(function(chunk, enc, next) {
sizeStreamed += chunk.length;

if (opts.interrupt && sizeStreamed >= fileSize / 2) {
// stop sending data half way through.
next();
} else {
this.push(chunk);
next();
}
}))
.pipe(file.createWriteStream())
.on('error', callback)
.on('complete', function(fileObject) {
callback(null, fileObject);
});
}
});
});

it('should write/read/remove from a buffer', function(done) {
tmp.setGracefulCleanup();
tmp.file(function _tempFileCreated(err, tmpFilePath) {
Expand Down

0 comments on commit f76c406

Please sign in to comment.