Skip to content

Commit

Permalink
Add blink on failure flag to buildlight command #23 .
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffano committed Feb 10, 2014
1 parent df4e13c commit 8303a09
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 0.2.2
* Change test lib to buster-node + referee
* Set min node engine to >= v0.8.0
* Add blink on failure flag to buildlight command #23

### 0.2.1
* BuildLight notifier blinks red on build failure
Expand Down
3 changes: 2 additions & 1 deletion conf/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
{ "arg": "-v, --view <view>", "desc": "Jenkins view name" },
{ "arg": "-s, --schedule <schedule>", "desc": "Cron scheduling definition, default: 0 * * * * * (every minute)" },
{ "arg": "-c, --scheme <scheme>", "desc": "Comma-separated colour scheme, default: red,green,blue" },
{ "arg": "-u, --usbled <usbled>", "desc": "Path to usbled installation, if not specified then it will try to find a usbled installation at /sys/bus/usb/drivers/usbled/" }
{ "arg": "-u, --usbled <usbled>", "desc": "Path to usbled installation, if not specified then it will try to find a usbled installation at /sys/bus/usb/drivers/usbled/" },
{ "arg": "-b, --blink-on-failure", "desc": "Blink light on build failure" }
]
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ function _ninja(args) {
function _buildLight(args) {
var buildLight = new BuildLight({
scheme: args.scheme ? args.scheme.split(',') : undefined,
usbled: args.usbled
usbled: args.usbled,
blinkOnFailure: args.blinkOnFailure
});
__monitor(buildLight, args);
}
Expand Down
7 changes: 4 additions & 3 deletions lib/notifiers/buildlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ var _BuildLight = require('buildlight');
* - usbled: path to usbled installation, if not specified then it will try to
* find a usbled installation at /sys/bus/usb/drivers/usbled/
* - platform: override platform, used by unit tests to override buildlight platform
* - blinkOnFailure: if true then build light will display blinking red, otherwise display red without blinking
*/
function BuildLight(opts) {
opts = opts || {};
this.buildLight = new _BuildLight(opts);
this.opts = opts || {};
this.buildLight = new _BuildLight(this.opts);
}

/**
Expand All @@ -32,7 +33,7 @@ BuildLight.prototype.notify = function (status) {
self = this;

function _colourise() {
if (status === 'FAIL') {
if (self.opts.blinkOnFailure && status === 'FAIL') {
self.buildLight.blink(colour, function (err) {
if (err) {
console.error(err.message);
Expand Down
2 changes: 1 addition & 1 deletion test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ buster.testCase('cli - buildlight', {
},
'should notify buildlight when there is no monitoring error': function (done) {
this.stub(_cli, 'command', function (base, actions) {
actions.commands.buildlight.action({ job: 'somejob', schedule: '* * * * * *', scheme: 'red,green,blue', usbled: '/some/usbled/path' });
actions.commands.buildlight.action({ job: 'somejob', schedule: '* * * * * *', scheme: 'red,green,blue', usbled: '/some/usbled/path', blinkOnFailure: true });
});
this.stub(Jenkins.prototype, 'monitor', function (opts, cb) {
assert.equals(opts.jobName, 'somejob');
Expand Down
24 changes: 24 additions & 0 deletions test/notifiers/buildlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var buster = require('buster-node'),

buster.testCase('buildlight - notify', {
setUp: function () {
this.mockConsole = this.mock(console);
this.mockFs = this.mock(fs);
this.stub(_BuildLight.prototype, 'unblink', function (cb) {
cb();
Expand Down Expand Up @@ -34,5 +35,28 @@ buster.testCase('buildlight - notify', {
this.mockFs.expects('writeFileSync').once().withExactArgs('/some/usbled/path/blue', 1);
var buildLight = new BuildLight({ scheme: ['red', 'green', 'blue'], usbled: '/some/usbled/path/', platform: 'linux' });
buildLight.notify('SOMEUNKNOWNSTATUS');
},
'should switch all colours off then switch red colour on on build light device when status is fail': function () {
this.mockFs.expects('writeFileSync').once().withExactArgs('/some/usbled/path/red', 0);
this.mockFs.expects('writeFileSync').once().withExactArgs('/some/usbled/path/green', 0);
this.mockFs.expects('writeFileSync').once().withExactArgs('/some/usbled/path/blue', 0);
this.mockFs.expects('writeFileSync').once().withExactArgs('/some/usbled/path/red', 1);
var buildLight = new BuildLight({ scheme: ['red', 'green', 'blue'], usbled: '/some/usbled/path/', platform: 'linux' });
buildLight.notify('FAIL');
},
'should blink red colour when status is fail and blinkOnFailure is true': function (done) {
this.stub(_BuildLight.prototype, 'blink', function (colour, cb) {
done();
});
var buildLight = new BuildLight({ scheme: ['red', 'green', 'blue'], usbled: '/some/usbled/path/', platform: 'linux', blinkOnFailure: true });
buildLight.notify('FAIL');
},
'should log error message when an error occurs while blinking failure colour': function () {
this.mockConsole.expects('error').once().withExactArgs('some error');
this.stub(_BuildLight.prototype, 'blink', function (colour, cb) {
cb(new Error('some error'));
});
var buildLight = new BuildLight({ scheme: ['red', 'green', 'blue'], usbled: '/some/usbled/path/', platform: 'linux', blinkOnFailure: true });
buildLight.notify('FAIL');
}
});

0 comments on commit 8303a09

Please sign in to comment.