Skip to content

Commit

Permalink
Fix hueristics and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyman727 committed Oct 5, 2015
1 parent 564ce5f commit 4cdd5cc
Show file tree
Hide file tree
Showing 2 changed files with 189 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ controller.runHeuristics = function(opts, tessels) {
lanFound = true;
}
// We have multiple LAN Tessels which is an issue
else {
// If a USB connection wasn't found, we have too much ambiguity
else if (!usbFound) {
// Return nothing because the user needs to be more specific
return;
}
Expand Down
187 changes: 187 additions & 0 deletions test/unit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,193 @@ exports['controller.closeTesselConnections'] = {
},
};

exports['controller.runHeuristics'] = {
setUp: function(done) {
this.sandbox = sinon.sandbox.create();
this.processOn = this.sandbox.stub(process, 'on');
done();
},

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

oneUSBDevice: function(test) {
test.expect(1);

var a = newTessel({
sandbox: this.sandbox,
authorized: true,
type: 'USB'
});

controller.runHeuristics({}, [a])
.then(function(tessel) {
test.deepEqual(a, tessel);
test.done();
});
},

oneLANDevice: function(test) {
test.expect(1);

var a = newTessel({
sandbox: this.sandbox,
authorized: true,
type: 'LAN'
});

controller.runHeuristics({}, [a])
.then(function(tessel) {
test.deepEqual(a, tessel);
test.done();
});
},

USBAndLANDevices: function(test) {
test.expect(1);

var a = newTessel({
sandbox: this.sandbox,
authorized: true,
type: 'LAN'
});

var b = newTessel({
sandbox: this.sandbox,
authorized: true,
type: 'USB'
});

controller.runHeuristics({}, [a, b])
.then(function(tessel) {
test.deepEqual(b, tessel);
test.done();
});
},

bothConnectionsAndLAN: function(test) {
test.expect(1);

var a = newTessel({
sandbox: this.sandbox,
authorized: true,
type: 'LAN'
});

var b = newTessel({
sandbox: this.sandbox,
authorized: true,
type: 'USB'
});

b.addConnection({
connectionType: 'LAN',
authorized: true
});

controller.runHeuristics({}, [a, b])
.then(function(tessel) {
test.deepEqual(b, tessel);
test.done();
});
},

bothConnectionsAndMultipleLAN: function(test) {
test.expect(1);

var a = newTessel({
sandbox: this.sandbox,
authorized: true,
type: 'LAN'
});

var b = newTessel({
sandbox: this.sandbox,
authorized: true,
type: 'LAN'
});

var c = newTessel({
sandbox: this.sandbox,
authorized: true,
type: 'USB'
});

c.addConnection({
connectionType: 'LAN',
authorized: true
});

controller.runHeuristics({}, [a, b, c])
.then(function(tessel) {
test.deepEqual(c, tessel);
test.done();
});
},

USBAndLANDevicesWithNameOption: function(test) {
test.expect(1);

var a = newTessel({
sandbox: this.sandbox,
authorized: true,
type: 'LAN'
});

a.name = 'Me!';

var b = newTessel({
sandbox: this.sandbox,
authorized: true,
type: 'USB'
});

b.name = 'Not Me!';

controller.runHeuristics({
name: a.name
}, [a, b])
.then(function(tessel) {
test.deepEqual(a, tessel);
test.done();
});
},

USBAndLANDevicesWithEnvVariable: function(test) {
test.expect(1);

var winningName = 'Me!';
process.env['Tessel'] = winningName;

var a = newTessel({
sandbox: this.sandbox,
authorized: true,
type: 'LAN'
});

a.name = winningName;

var b = newTessel({
sandbox: this.sandbox,
authorized: true,
type: 'USB'
});

b.name = 'Not ' + winningName;

controller.runHeuristics({
name: a.name
}, [a, b])
.then(function(tessel) {
test.deepEqual(a, tessel);
process.env['Tessel'] = undefined;
test.done();
});
},
};


exports['Tessel.list'] = {

Expand Down

0 comments on commit 4cdd5cc

Please sign in to comment.