Permalink
Browse files

Add blink on failure flag to buildlight command #23 .

  • Loading branch information...
1 parent df4e13c commit 8303a09ccd7419305a2e6d7ab7558fd63a7ef3cc @cliffano committed Feb 10, 2014
Showing with 34 additions and 6 deletions.
  1. +1 −0 CHANGELOG.md
  2. +2 −1 conf/commands.json
  3. +2 −1 lib/cli.js
  4. +4 −3 lib/notifiers/buildlight.js
  5. +1 −1 test/cli.js
  6. +24 −0 test/notifiers/buildlight.js
View
@@ -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
View
@@ -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" }
]
}
}
View
@@ -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);
}
@@ -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);
}
/**
@@ -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);
View
@@ -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');
@@ -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();
@@ -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.