Skip to content

Commit

Permalink
Merge cd96dbf into c20807f
Browse files Browse the repository at this point in the history
  • Loading branch information
cortexteam committed Oct 15, 2018
2 parents c20807f + cd96dbf commit 0639655
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
21 changes: 12 additions & 9 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,8 @@ class CommandLine {
}

const jflint = new JFLint(jenkinsUrl, username, password, csrfDisabled);
return jflint.lintJenkinsfile(jenkinsfile).then(res => {
if (res === 'Jenkinsfile successfully validated.\n') {
this._process.stdout.write(res);
this._process.exit(0);
} else {
this._process.stderr.write(res);
this._process.exit(1);
}
}).catch(e => {
return jflint.lintJenkinsfile(jenkinsfile).then(this._interpretResult)
.catch(e => {
this._process.stderr.write(`${e.message}\n`);
this._process.exit(1);
});
Expand Down Expand Up @@ -105,6 +98,16 @@ class CommandLine {
return false;
}
}

_interpretResult(res) {
if (/^Jenkinsfile successfully validated.\r?\n$/.test(res)) {
this._process.stdout.write(res);
this._process.exit(0);
} else {
this._process.stderr.write(res);
this._process.exit(1);
}
}
}

module.exports = CommandLine;
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@
"node-fetch": "^1.6.3"
},
"devDependencies": {
"chai": "^4.2.0",
"coveralls": "^2.11.16",
"intelli-espower-loader": "^1.0.1",
"istanbul": "^0.4.5",
"mocha": "^3.2.0",
"power-assert": "^1.4.2",
"proxyquire": "^1.7.11"
"proxyquire": "^1.7.11",
"sinon": "^7.0.0",
"sinon-chai": "^3.2.0"
}
}
27 changes: 27 additions & 0 deletions test/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const CommandLine = require('../../lib/cli');
const assert = require('assert');
const os = require('os');
const path = require('path');
const sinon = require('sinon');
const chai = require('chai');
chai.use(require('sinon-chai'));

describe('CommandLine', function() {
let sut;
Expand Down Expand Up @@ -33,4 +36,28 @@ describe('CommandLine', function() {
assert(sut._findConfigPath(dir) === path.join(os.homedir(), '.jflintrc'));
});
});

describe('_interpretResult', function() {
beforeEach(function() {
sut._process = {
stdout: { write: sinon.stub() },
stderr: { write: sinon.stub() },
exit: sinon.stub()
};
});

it('should handle success response from Linux node', function() {
const res = 'Jenkinsfile successfully validated.\n';
sut._interpretResult(res);

chai.expect(sut._process.exit).to.be.calledWith(0);
});

it('should handle success response from Windows node', function() {
const res = 'Jenkinsfile successfully validated.\r\n';
sut._interpretResult(res);

chai.expect(sut._process.exit).to.be.calledWith(0);
});
});
});

0 comments on commit 0639655

Please sign in to comment.