Skip to content

Commit

Permalink
t2 run/push: stub gunzip & extract in remote binary request tests. Fixes
Browse files Browse the repository at this point in the history
 gh-711 (#712)

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Apr 27, 2016
1 parent e889c74 commit bc23cca
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
2 changes: 2 additions & 0 deletions test/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"provision": true,
"RemoteProcessSimulator": true,
"request": true,
"Request": true,
"sinon": true,
"ssh": true,
"sshpk": true,
Expand All @@ -62,6 +63,7 @@
"Tessel": true,
"TesselSeeker": true,
"TesselSimulator": true,
"Transform": true,
"uglify": true,
"updates": true,
"usb": true,
Expand Down
7 changes: 6 additions & 1 deletion test/common/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ global.events = require('events');
global.path = require('path');
global.stream = require('stream');
global.util = require('util');
global.zlib = require('zlib');

global.Emitter = events.EventEmitter;
global.Duplex = stream.Duplex;
global.Stream = stream.Stream;
global.Transform = stream.Transform;


// Third Party Dependencies
Expand All @@ -31,7 +34,6 @@ global.ssh = require('ssh2');
global.tags = require('common-tags');
global.tar = require('tar');
global.uglify = require('uglify-js');
global.zlib = require('zlib');


// Internal
Expand Down Expand Up @@ -68,3 +70,6 @@ global.cli = require('../../bin/tessel-2');
global.LAN = lan.LAN;
global.TesselSeeker = discover.TesselSeeker;
global.USB = usb.USB;

global.Request = function Request() {};
util.inherits(global.Request, global.Stream);
43 changes: 31 additions & 12 deletions test/unit/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2008,9 +2008,6 @@ exports['deploy.sendBundle, error handling'] = {
},
};

function Request() {}
util.inherits(Request, stream.Stream);

exports['deploy.resolveBinaryModules'] = {
setUp: function(done) {

Expand Down Expand Up @@ -2331,19 +2328,39 @@ exports['deploy.resolveBinaryModules'] = {
},

requestsRemote: function(test) {
test.expect(10);
test.expect(12);

this.exists = sandbox.stub(fs, 'existsSync', () => false);
this.mkdirp = sandbox.spy(fs, 'mkdirp');
this.pipe = sandbox.spy(stream.Stream.prototype, 'pipe');
this.mkdirp = sandbox.stub(fs, 'mkdirp', (dir, handler) => {
handler();
});

this.createGunzip = sandbox.spy(zlib, 'createGunzip');
this.Extract = sandbox.spy(tar, 'Extract');
this.request = sandbox.stub(request, 'Request', (opts) => {
var stream = new Request(opts);
this.transform = new Transform();
this.transform.stubsUsed = [];
this.rstream = null;

process.nextTick(() => stream.emit('end'));
return stream;
this.pipe = sandbox.stub(stream.Stream.prototype, 'pipe', () => {
// After the second transform is piped, emit the end
// event on the request stream;
if (this.pipe.callCount === 2) {
process.nextTick(() => this.rstream.emit('end'));
}
return this.rstream;
});

this.createGunzip = sandbox.stub(zlib, 'createGunzip', () => {
this.transform.stubsUsed.push('createGunzip');
return this.transform;
});

this.Extract = sandbox.stub(tar, 'Extract', () => {
this.transform.stubsUsed.push('Extract');
return this.transform;
});

this.request = sandbox.stub(request, 'Request', (opts) => {
this.rstream = new Request(opts);
return this.rstream;
});

deploy.resolveBinaryModules({
Expand All @@ -2363,6 +2380,8 @@ exports['deploy.resolveBinaryModules'] = {
test.equal(this.pipe.callCount, 2);
test.equal(this.createGunzip.callCount, 1);
test.equal(this.Extract.callCount, 1);
test.equal(this.transform.stubsUsed.length, 2);
test.deepEqual(this.transform.stubsUsed, ['createGunzip', 'Extract']);

test.done();
}).catch(error => {
Expand Down

0 comments on commit bc23cca

Please sign in to comment.