Skip to content

Commit

Permalink
Add Node version output to t2 version command (#679)
Browse files Browse the repository at this point in the history
Fixes #667
  • Loading branch information
wyze authored and rwaldron committed Apr 16, 2016
1 parent 944114c commit 83c47d3
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 8 deletions.
28 changes: 20 additions & 8 deletions lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -938,20 +938,32 @@ controller.updateTesselWithVersion = function(opts, tessel, currentVersion, buil
});
};

controller.tesselFirmwareVerion = function(opts) {
controller.tesselFirmwareVerion = opts => {
opts.authorized = true;
return controller.standardTesselCommand(opts, function(tessel) {
return controller.standardTesselCommand(opts, tessel => {
var output = (thing, version) => `Tessel [${tessel.name}] ${thing} version: ${version}`;

// Grab the version information
return tessel.fetchCurrentBuildInfo()
.then(function(versionSha) {
return updates.requestBuildList().then(function(builds) {
.then(versionSha => {
return updates.requestBuildList().then(builds => {
// Figure out what commit SHA is running on it
var version = updates.findBuild(builds, 'sha', versionSha).version;
logs.info('Tessel [' + tessel.name + '] version: ' + version);
var firmwareVersion = updates.findBuild(builds, 'sha', versionSha).version;

return tessel.fetchCurrentNodeVersion()
.then(nodeVersion => {
logs.info(output('Firmware', firmwareVersion));
logs.info(output('Node', nodeVersion));
})
.catch(() => {
logs.info(output('Firmware', firmwareVersion));
logs.info(output('Node', 'unknown'));
});
});
})
.catch(function() {
logs.info('Tessel [' + tessel.name + '] version: unknown');
.catch(() => {
logs.info(output('Firmware', 'unknown'));
logs.info(output('Node', 'unknown'));
});
});
};
Expand Down
1 change: 1 addition & 0 deletions lib/tessel/tessel.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,5 @@ require('./erase');
require('./name');
require('./provision');
require('./update');
require('./version');
require('./wifi');
19 changes: 19 additions & 0 deletions lib/tessel/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// System Objects
// ...

// Third Party Dependencies
// ...

// Internal
var Tessel = require('./tessel');

/*
Gathers node version.
*/
Tessel.prototype.fetchCurrentNodeVersion = function() {
return this.simpleExec(['node', '--version'])
.then(version => {
// strip the `v` preceding the version
return version.trim().substring(1);
});
};
139 changes: 139 additions & 0 deletions test/unit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,145 @@ exports['controller.runHeuristics'] = {
}
};

exports['controller.tesselFirmwareVerion'] = {
setUp: function(done) {
this.sandbox = sinon.sandbox.create();
this.logsWarn = this.sandbox.stub(logs, 'warn', function() {});
this.logsInfo = this.sandbox.stub(logs, 'info', function() {});
this.logsBasic = this.sandbox.stub(logs, 'basic', function() {});

this.tessel = TesselSimulator({
name: 'TestTessel'
});

this.standardTesselCommand = this.sandbox.stub(controller, 'standardTesselCommand', (opts, callback) => {
return callback(this.tessel);
});

this.fetchCurrentBuildInfo = this.sandbox.stub(Tessel.prototype, 'fetchCurrentBuildInfo', () => {
return Promise.resolve('9a85c84f5a03c715908921baaaa9e7397985bc7f');
});

this.fetchCurrentNodeVersion = this.sandbox.stub(Tessel.prototype, 'fetchCurrentNodeVersion', () => {
return Promise.resolve('4.2.1');
});

done();
},

tearDown: function(done) {
this.sandbox.restore();
done();
},

properVersionsReturned: function(test) {
test.expect(6);

var opts = {};

controller.tesselFirmwareVerion(opts)
.then(() => {
// Version command was sent
test.equal(this.standardTesselCommand.callCount, 1);
// Get the firmware version
test.equal(this.fetchCurrentBuildInfo.callCount, 1);
// Execute `node --version` command on tessel
test.equal(this.fetchCurrentNodeVersion.callCount, 1);
// Make sure we have some output
test.equal(this.logsInfo.callCount, 2);

// Output of firmware version to console
test.equal(this.logsInfo.firstCall.args[0], 'Tessel [TestTessel] Firmware version: 0.0.1');
// Output of Node version to console
test.equal(this.logsInfo.secondCall.args[0], 'Tessel [TestTessel] Node version: 4.2.1');
test.done();
});
},

nodeVersionFailed: function(test) {
test.expect(6);

this.logsInfo.restore();
this.logsInfo = this.sandbox.stub(logs, 'info', function() {});

this.standardTesselCommand.restore();
this.standardTesselCommand = this.sandbox.stub(controller, 'standardTesselCommand', (opts, callback) => {
return callback(this.tessel);
});

this.fetchCurrentBuildInfo.restore();
this.fetchCurrentBuildInfo = this.sandbox.stub(Tessel.prototype, 'fetchCurrentBuildInfo', () => {
return Promise.resolve('9a85c84f5a03c715908921baaaa9e7397985bc7f');
});

this.fetchCurrentNodeVersion.restore();
this.fetchCurrentNodeVersion = this.sandbox.stub(Tessel.prototype, 'fetchCurrentNodeVersion', () => {
return Promise.reject();
});

var opts = {};

controller.tesselFirmwareVerion(opts)
.then(() => {
// Version command was sent
test.equal(this.standardTesselCommand.callCount, 1);
// Get the firmware version
test.equal(this.fetchCurrentBuildInfo.callCount, 1);
// Execute `node --version` command on tessel
test.equal(this.fetchCurrentNodeVersion.callCount, 1);
// Make sure we have some output
test.equal(this.logsInfo.callCount, 2);

// Output of firmware version to console
test.equal(this.logsInfo.firstCall.args[0], 'Tessel [TestTessel] Firmware version: 0.0.1');
// Output of Node version to console
test.equal(this.logsInfo.secondCall.args[0], 'Tessel [TestTessel] Node version: unknown');
test.done();
});
},

firmwareVersionFailed: function(test) {
test.expect(6);

this.logsInfo.restore();
this.logsInfo = this.sandbox.stub(logs, 'info', function() {});

this.standardTesselCommand.restore();
this.standardTesselCommand = this.sandbox.stub(controller, 'standardTesselCommand', (opts, callback) => {
return callback(this.tessel);
});

this.fetchCurrentBuildInfo.restore();
this.fetchCurrentBuildInfo = this.sandbox.stub(Tessel.prototype, 'fetchCurrentBuildInfo', () => {
return Promise.reject();
});

this.fetchCurrentNodeVersion.restore();
this.fetchCurrentNodeVersion = this.sandbox.stub(Tessel.prototype, 'fetchCurrentNodeVersion', () => {
return Promise.resolve('4.2.1');
});

var opts = {};

controller.tesselFirmwareVerion(opts)
.then(() => {
// Version command was sent
test.equal(this.standardTesselCommand.callCount, 1);
// Get the firmware version
test.equal(this.fetchCurrentBuildInfo.callCount, 1);
// Execute `node --version` command on tessel
test.equal(this.fetchCurrentNodeVersion.callCount, 0);
// Make sure we have some output
test.equal(this.logsInfo.callCount, 2);

// Output of firmware version to console
test.equal(this.logsInfo.firstCall.args[0], 'Tessel [TestTessel] Firmware version: unknown');
// Output of Node version to console
test.equal(this.logsInfo.secondCall.args[0], 'Tessel [TestTessel] Node version: unknown');
test.done();
});
}
};

exports['Tessel.list'] = {

Expand Down
40 changes: 40 additions & 0 deletions test/unit/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Test dependencies are required and exposed in common/bootstrap.js

exports['Tessel.prototype.fetchCurrentNodeVersion'] = {
setUp: function(done) {
this.sandbox = sinon.sandbox.create();
this.logsWarn = this.sandbox.stub(logs, 'warn', function() {});
this.logsInfo = this.sandbox.stub(logs, 'info', function() {});
this.logsBasic = this.sandbox.stub(logs, 'basic', function() {});
this.tessel = TesselSimulator();

this.simpleExec = this.sandbox.stub(Tessel.prototype, 'simpleExec', () => {
return Promise.resolve('v4.2.1');
});

done();
},

tearDown: function(done) {
this.sandbox.restore();
this.tessel.mockClose();

done();
},

properVersionReturned: function(test) {
test.expect(3);

this.tessel.fetchCurrentNodeVersion()
.then(version => {
test.equal(this.simpleExec.callCount, 1);
test.equal(this.simpleExec.calledWith(['node', '--version']), true);
test.equal(version, '4.2.1');
test.done();
})
.catch(error => {
test.ok(false, `properVersionReturned failed: ${error.toString()}`);
test.done();
});
}
};

0 comments on commit 83c47d3

Please sign in to comment.