Skip to content

Commit 76ed7ac

Browse files
upgrade mocha + reorder tests
1 parent 6877cc1 commit 76ed7ac

3 files changed

Lines changed: 23 additions & 22 deletions

File tree

lib/storage/file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ File.prototype.createWriteStream = function(metadata) {
341341
method: 'POST',
342342
uri: util.format('{base}/{bucket}/o', {
343343
base: STORAGE_UPLOAD_BASE_URL,
344-
bucket: encodeURIComponent(that.bucket.name)
344+
bucket: that.bucket.name
345345
}),
346346
qs: {
347347
name: that.name,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"dox": "^0.4.6",
6464
"istanbul": "^0.3.0",
6565
"jshint": "^2.5.2",
66-
"mocha": "^1.21.3",
66+
"mocha": "^2.0.1",
6767
"sandboxed-module": "^1.0.1",
6868
"tmp": "0.0.24"
6969
},

test/storage/file.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ describe('File', function() {
350350
it('should start a new upload when written to', function(done) {
351351
file.bucket.storage.makeAuthorizedRequest_ = function(reqOpts) {
352352
var uri = 'https://www.googleapis.com/upload/storage/v1/b/' +
353-
encodeURIComponent(file.bucket.name) + '/o';
353+
file.bucket.name + '/o';
354354

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

376+
// respond to creation POST.
377+
if (requestCount === 1) {
378+
cb(null, null, { headers: { location: RESUMABLE_URI }});
379+
assert.deepEqual(configStoreData[file.name].uri, RESUMABLE_URI);
380+
return;
381+
}
382+
383+
// create an authorized request for the first PUT.
376384
if (requestCount === 2) {
377-
// respond to first upload PUT.
378385
assert.equal(reqOpts.method, 'PUT');
379386
assert.equal(reqOpts.uri, RESUMABLE_URI);
380387

381388
cb.onAuthorized(null, { headers: {} });
382389
}
383-
384-
if (requestCount === 1) {
385-
// respond to creation POST.
386-
cb(null, null, { headers: { location: RESUMABLE_URI }});
387-
388-
assert.deepEqual(configStoreData[file.name], {
389-
uri: RESUMABLE_URI
390-
});
391-
}
392390
};
393391

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

405404
file.createWriteStream()
405+
.on('error', done)
406406
.on('complete', function(data) {
407407
assert.deepEqual(data, metadata);
408408

@@ -412,7 +412,6 @@ describe('File', function() {
412412
done();
413413
});
414414
})
415-
.on('error', done)
416415
.emit('writing');
417416
});
418417
});
@@ -431,13 +430,6 @@ describe('File', function() {
431430
file.bucket.storage.makeAuthorizedRequest_ = function(reqOpts, cb) {
432431
requestCount++;
433432

434-
if (requestCount === 2) {
435-
assert.equal(reqOpts.method, 'PUT');
436-
assert.equal(reqOpts.uri, RESUMABLE_URI);
437-
438-
cb.onAuthorized(null, { headers: {} });
439-
}
440-
441433
if (requestCount === 1) {
442434
assert.equal(reqOpts.method, 'PUT');
443435
assert.equal(reqOpts.uri, RESUMABLE_URI);
@@ -447,9 +439,18 @@ describe('File', function() {
447439
});
448440

449441
cb({
450-
code: 308,
442+
code: 308, // resumable upload status code
451443
response: { headers: { range: '0-' + lastByte } }
452444
});
445+
446+
return;
447+
}
448+
449+
if (requestCount === 2) {
450+
assert.equal(reqOpts.method, 'PUT');
451+
assert.equal(reqOpts.uri, RESUMABLE_URI);
452+
453+
cb.onAuthorized(null, { headers: {} });
453454
}
454455
};
455456

0 commit comments

Comments
 (0)