-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #570 from tessel/jon-expose-api
Exposes the CLI as an API
- Loading branch information
Showing
6 changed files
with
151 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// The controller is used for standard Tessel commands | ||
// like Tessel.get, Tessel.list, Tessel.deploy, etc. | ||
module.exports = require('./lib/controller'); | ||
// Commands give deeper access to all the standard shell commands | ||
// that we run to execute larger sequences | ||
module.exports.commands = require('./lib/tessel/commands'); | ||
// Exporting Tessel allows consumers to compose their own | ||
// functions onto the prototype | ||
module.exports.Tessel = require('./lib/tessel/tessel'); | ||
// The seeker allows consumers to have a long running discovery | ||
// process and take action as Tessels are connected/disconnected | ||
module.exports.discovery = require('./lib/discover').TesselSeeker; | ||
// The USBConnection libray lets consumers turn arbitrary USB devices | ||
// into USBConnection objects to be used in Tessel creation. | ||
module.exports.USBConnection = require('./lib/usb_connection').USBConnection; | ||
// The LANConnection libray lets consumers turn arbitrary LAN devices | ||
// into LANConnection objects to be used in Tessel creation. | ||
module.exports.LANConnection = require('./lib/lan_connection').LANConnection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
var api = require('../../index'); | ||
|
||
exports['API Surface'] = { | ||
setUp: function(done) { | ||
done(); | ||
}, | ||
tearDown: function(done) { | ||
done(); | ||
}, | ||
ensureExistence: function(test) { | ||
test.ok(api === controller); | ||
test.ok(api === controller); | ||
test.ok(api.commands === commands); | ||
test.ok(api.Tessel === Tessel); | ||
test.ok(api.USBConnection === USB.Connection); | ||
test.ok(api.LANConnection === LAN.Connection); | ||
test.done(); | ||
} | ||
}; | ||
|
||
exports['CLI.list'] = { | ||
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.closeConnections = this.sandbox.stub(controller, 'closeTesselConnections').returns(Promise.resolve()); | ||
var test = this; | ||
this.seeker = this.sandbox.stub(discover, 'TesselSeeker', function Seeker() { | ||
this.start = (options) => { | ||
test.activeSeeker = this; | ||
setTimeout(() => this.stop(), options.timeout); | ||
return this; | ||
}; | ||
this.stop = function() { | ||
this.emit('end'); | ||
return this; | ||
}; | ||
}); | ||
|
||
util.inherits(this.seeker, Emitter); | ||
done(); | ||
}, | ||
tearDown: function(done) { | ||
this.sandbox.restore(); | ||
done(); | ||
}, | ||
rejectWithNoTessels: function(test) { | ||
test.expect(1); | ||
api.list({ | ||
timeout: 0.0001, | ||
usb: true | ||
}) | ||
.then(() => { | ||
test.fail('Should not have returned any Tessels'); | ||
test.done(); | ||
}) | ||
.catch((err) => { | ||
test.ok(err); | ||
test.done(); | ||
}); | ||
}, | ||
resolveWithOneTessel: function(test) { | ||
// Create a new Tessel | ||
var tessel = new Tessel({ | ||
connectionType: 'USB' | ||
}); | ||
tessel.name = 'TestTessel'; | ||
|
||
api.list({ | ||
timeout: 0.1, | ||
usb: true | ||
}) | ||
.then((tessels) => { | ||
test.ok(tessels.length === 1); | ||
test.ok(tessels[0].name === tessel.name); | ||
test.done(); | ||
}) | ||
.catch(() => { | ||
test.fail('Should not have rejected with one Tessel available'); | ||
test.done(); | ||
}); | ||
|
||
// Emit the Tessel | ||
setImmediate(() => { | ||
this.activeSeeker.emit('tessel', tessel); | ||
}); | ||
}, | ||
|
||
resolveWithMultipleTessels: function(test) { | ||
// Create a new Tessel | ||
var tessel1 = new Tessel({ | ||
connectionType: 'USB' | ||
}); | ||
|
||
tessel1.name = 'TestTessel1'; | ||
|
||
// Create a new Tessel | ||
var tessel2 = new Tessel({ | ||
connectionType: 'LAN' | ||
}); | ||
|
||
tessel2.name = 'TestTessel2'; | ||
|
||
api.list({ | ||
timeout: 0.1 | ||
}) | ||
.then((tessels) => { | ||
test.ok(tessels.length === 2); | ||
test.ok(tessels[0].name === tessel1.name); | ||
test.ok(tessels[1].name === tessel2.name); | ||
test.done(); | ||
}) | ||
.catch(() => { | ||
test.fail('Should not have rejected with one Tessel available'); | ||
test.done(); | ||
}); | ||
|
||
// Emit the Tessel | ||
setImmediate(() => { | ||
this.activeSeeker.emit('tessel', tessel1); | ||
this.activeSeeker.emit('tessel', tessel2); | ||
}); | ||
} | ||
}; |