Skip to content

Commit

Permalink
upgrade mocha + reorder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Nov 13, 2014
1 parent 6877cc1 commit 76ed7ac
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ File.prototype.createWriteStream = function(metadata) {
method: 'POST',
uri: util.format('{base}/{bucket}/o', {
base: STORAGE_UPLOAD_BASE_URL,
bucket: encodeURIComponent(that.bucket.name)
bucket: that.bucket.name
}),
qs: {
name: that.name,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"dox": "^0.4.6",
"istanbul": "^0.3.0",
"jshint": "^2.5.2",
"mocha": "^1.21.3",
"mocha": "^2.0.1",
"sandboxed-module": "^1.0.1",
"tmp": "0.0.24"
},
Expand Down
41 changes: 21 additions & 20 deletions test/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ describe('File', function() {
it('should start a new upload when written to', function(done) {
file.bucket.storage.makeAuthorizedRequest_ = function(reqOpts) {
var uri = 'https://www.googleapis.com/upload/storage/v1/b/' +
encodeURIComponent(file.bucket.name) + '/o';
file.bucket.name + '/o';

assert.equal(reqOpts.method, 'POST');
assert.equal(reqOpts.uri, uri);
Expand All @@ -373,24 +373,23 @@ describe('File', function() {
file.bucket.storage.makeAuthorizedRequest_ = function(reqOpts, cb) {
requestCount++;

// respond to creation POST.
if (requestCount === 1) {
cb(null, null, { headers: { location: RESUMABLE_URI }});
assert.deepEqual(configStoreData[file.name].uri, RESUMABLE_URI);
return;
}

// create an authorized request for the first PUT.
if (requestCount === 2) {
// respond to first upload PUT.
assert.equal(reqOpts.method, 'PUT');
assert.equal(reqOpts.uri, RESUMABLE_URI);

cb.onAuthorized(null, { headers: {} });
}

if (requestCount === 1) {
// respond to creation POST.
cb(null, null, { headers: { location: RESUMABLE_URI }});

assert.deepEqual(configStoreData[file.name], {
uri: RESUMABLE_URI
});
}
};

// respond to first upload PUT request.
var metadata = { a: 'b', c: 'd' };
request_Override = function(reqOpts) {
assert.equal(reqOpts.headers['Content-Range'], 'bytes 0-*/*');
Expand All @@ -403,6 +402,7 @@ describe('File', function() {
};

file.createWriteStream()
.on('error', done)
.on('complete', function(data) {
assert.deepEqual(data, metadata);

Expand All @@ -412,7 +412,6 @@ describe('File', function() {
done();
});
})
.on('error', done)
.emit('writing');
});
});
Expand All @@ -431,13 +430,6 @@ describe('File', function() {
file.bucket.storage.makeAuthorizedRequest_ = function(reqOpts, cb) {
requestCount++;

if (requestCount === 2) {
assert.equal(reqOpts.method, 'PUT');
assert.equal(reqOpts.uri, RESUMABLE_URI);

cb.onAuthorized(null, { headers: {} });
}

if (requestCount === 1) {
assert.equal(reqOpts.method, 'PUT');
assert.equal(reqOpts.uri, RESUMABLE_URI);
Expand All @@ -447,9 +439,18 @@ describe('File', function() {
});

cb({
code: 308,
code: 308, // resumable upload status code
response: { headers: { range: '0-' + lastByte } }
});

return;
}

if (requestCount === 2) {
assert.equal(reqOpts.method, 'PUT');
assert.equal(reqOpts.uri, RESUMABLE_URI);

cb.onAuthorized(null, { headers: {} });
}
};

Expand Down

0 comments on commit 76ed7ac

Please sign in to comment.