Add CYLON_TEST mode for TDR

This commit is contained in:
deadprogram 2014-02-17 21:03:50 -08:00
parent 387aaa618c
commit 02d0e138bb
2 changed files with 13 additions and 0 deletions

7
dist/robot.js vendored
View File

@ -63,6 +63,7 @@
this.commands = []; this.commands = [];
this.registerAdaptor("./test/loopback", "loopback"); this.registerAdaptor("./test/loopback", "loopback");
this.registerDriver("./test/ping", "ping"); this.registerDriver("./test/ping", "ping");
this.testing = process.env['CYLON_TEST'];
this.initConnections(opts.connection || opts.connections); this.initConnections(opts.connection || opts.connections);
this.initDevices(opts.device || opts.devices); this.initDevices(opts.device || opts.devices);
this.work = opts.work || function() { this.work = opts.work || function() {
@ -204,6 +205,9 @@
}; };
Robot.prototype.requireAdaptor = function(adaptorName) { Robot.prototype.requireAdaptor = function(adaptorName) {
if (this.robot.testing != null) {
return this.robot.adaptors['loopback'];
}
if (this.robot.adaptors[adaptorName] == null) { if (this.robot.adaptors[adaptorName] == null) {
this.robot.registerAdaptor("cylon-" + adaptorName, adaptorName); this.robot.registerAdaptor("cylon-" + adaptorName, adaptorName);
this.robot.adaptors[adaptorName].register(this); this.robot.adaptors[adaptorName].register(this);
@ -229,6 +233,9 @@
}; };
Robot.prototype.requireDriver = function(driverName) { Robot.prototype.requireDriver = function(driverName) {
if (this.robot.testing != null) {
return this.robot.drivers['ping'];
}
if (this.robot.drivers[driverName] == null) { if (this.robot.drivers[driverName] == null) {
this.robot.registerDriver("cylon-" + driverName, driverName); this.robot.registerDriver("cylon-" + driverName, driverName);
this.robot.drivers[driverName].register(this); this.robot.drivers[driverName].register(this);

View File

@ -62,6 +62,8 @@ namespace 'Cylon', ->
@registerAdaptor "./test/loopback", "loopback" @registerAdaptor "./test/loopback", "loopback"
@registerDriver "./test/ping", "ping" @registerDriver "./test/ping", "ping"
@testing = process.env['CYLON_TEST']
@initConnections(opts.connection or opts.connections) @initConnections(opts.connection or opts.connections)
@initDevices(opts.device or opts.devices) @initDevices(opts.device or opts.devices)
@work = opts.work or -> (Logger.info "No work yet") @work = opts.work or -> (Logger.info "No work yet")
@ -184,6 +186,8 @@ namespace 'Cylon', ->
# #
# Returns the module for the adaptor # Returns the module for the adaptor
requireAdaptor: (adaptorName) => requireAdaptor: (adaptorName) =>
return @robot.adaptors['loopback'] if @robot.testing?
unless @robot.adaptors[adaptorName]? unless @robot.adaptors[adaptorName]?
@robot.registerAdaptor "cylon-#{adaptorName}", adaptorName @robot.registerAdaptor "cylon-#{adaptorName}", adaptorName
@robot.adaptors[adaptorName].register this @robot.adaptors[adaptorName].register this
@ -218,6 +222,8 @@ namespace 'Cylon', ->
# #
# Returns the module for driver # Returns the module for driver
requireDriver: (driverName) => requireDriver: (driverName) =>
return @robot.drivers['ping'] if @robot.testing?
unless @robot.drivers[driverName]? unless @robot.drivers[driverName]?
@robot.registerDriver "cylon-#{driverName}", driverName @robot.registerDriver "cylon-#{driverName}", driverName
@robot.drivers[driverName].register this @robot.drivers[driverName].register this