Permalink
Browse files

Merge branch 'master' of http://github.com/cliffano/nestor

  • Loading branch information...
2 parents 9aef64a + 0703246 commit 325ce86df87d9103aaaa2f9b5abef2294551a1e1 @cliffano committed Feb 16, 2013
Showing with 24 additions and 30 deletions.
  1. +1 −1 CHANGELOG.md
  2. +7 −10 lib/jenkins.js
  3. +4 −4 package.json
  4. +12 −15 test/jenkins.js
View
2 CHANGELOG.md
@@ -1,5 +1,5 @@
### 0.1.2-pre
-*
+* Move proxy environment variable handling to bag.http.requuest and bag.http.proxy
### 0.1.1
* Move status colouring to cli so that when lib/jenkins is used programatically then it gets plain uncoloured text
View
17 lib/jenkins.js
@@ -10,11 +10,8 @@ var _ = require('underscore'),
* class Jenkins
*
* @param {String} url: Jenkins URL, fallback to JENKINS_URL environment variable, otherwise default to http://localhost:8080
- * @param {Object} opts: optional
- * - proxy: proxy server URL in format http://user:pass@host:port
*/
-function Jenkins(url, opts) {
- opts = opts || {};
+function Jenkins(url) {
function _authFail(result, cb) {
cb(new Error('Authentication failed - incorrect username and/or password in JENKINS_URL'));
@@ -26,7 +23,6 @@ function Jenkins(url, opts) {
this.url = url || process.env.JENKINS_URL || 'http://localhost:8080';
this.opts = {
- proxy: opts.proxy || process.env.http_proxy,
handlers: {
401: _authFail,
403: _authRequire
@@ -107,11 +103,12 @@ Jenkins.prototype.console = function (jobName, opts, cb) {
},
function (cb) {
var params = {
- url: url,
- qs: { start: parseInt(result.headers['x-text-size'], 10) }
- };
- if (self.opts.proxy) {
- params.proxy = self.opts.proxy;
+ url: url,
+ qs: { start: parseInt(result.headers['x-text-size'], 10) }
+ },
+ envProxy = bag.http.proxy(url);
+ if (envProxy) {
+ params.proxy = envProxy;
}
request.get(params, function (err, _result) {
if (err) {
View
8 package.json
@@ -30,13 +30,13 @@
"test": "./test"
},
"dependencies": {
- "async": "0.1.22",
- "bagofholding": "0.1.0",
+ "async": "0.2.5",
+ "bagofholding": "0.1.1",
"colors": "0.6.0-1",
"irc": "0.3.6",
"request": "2.12.0",
"underscore": "1.4.4",
- "xml2js": "0.2.3"
+ "xml2js": "0.2.4"
},
"devDependencies": {
"buster": "0.6.12",
@@ -52,4 +52,4 @@
"url": "http://github.com/cliffano/nestor/raw/master/LICENSE"
}
]
-}
+}
View
27 test/jenkins.js
@@ -5,38 +5,36 @@ var bag = require('bagofholding'),
request = require('request');
buster.testCase('jenkins - jenkins', {
- 'should use url and optional proxy when specified': function (done) {
+ setUp: function () {
+ this.stub(process, 'env', {});
+ },
+ 'should use url when specified': function (done) {
var mockRequest = function (method, url, opts, cb) {
assert.equals(url, 'http://jenkins-ci.org:8080/job/job1/build');
- assert.equals(opts.proxy, 'http://someproxy');
opts.handlers[401]({ statusCode: 401 }, cb);
};
this.stub(bag, 'http', { request: mockRequest });
- var jenkins = new Jenkins('http://jenkins-ci.org:8080', { proxy: 'http://someproxy' });
+ var jenkins = new Jenkins('http://jenkins-ci.org:8080');
jenkins.build('job1', undefined, function (err, result) {
done();
});
},
- 'should use default url and no optional proxy when not specified': function (done) {
+ 'should use default url when no url specified': function (done) {
var mockRequest = function (method, url, opts, cb) {
assert.equals(url, 'http://localhost:8080/job/job1/build');
- assert.equals(opts.proxy, undefined);
opts.handlers[401]({ statusCode: 401 }, cb);
};
- this.stub(process, 'env', {}); // simulate no http_proxy environment variable
- this.stub(bag, 'http', { request: mockRequest });
+ this.stub(bag, 'http', { request: mockRequest, proxy: undefined });
var jenkins = new Jenkins();
jenkins.build('job1', undefined, function (err, result) {
done();
});
},
- 'should use http_proxy when optional proxy is not specified and env variable http_proxy is set': function (done) {
+ 'should use proxy when proxy is set': function (done) {
var mockRequest = function (method, url, opts, cb) {
assert.equals(url, 'http://localhost:8080/job/job1/build');
- assert.equals(opts.proxy, 'http://someproxy');
opts.handlers[401]({ statusCode: 401 }, cb);
};
- this.stub(process, 'env', { http_proxy: 'http://someproxy' });
this.stub(bag, 'http', { request: mockRequest });
var jenkins = new Jenkins();
jenkins.build('job1', undefined, function (err, result) {
@@ -205,8 +203,8 @@ buster.testCase('jenkins - console', {
body: 'Console output 2',
headers: { 'x-more-data': 'false', 'x-text-size': 20 }
});
- this.stub(bag, 'http', { request: mockBagRequest });
- var jenkins = new Jenkins('http://localhost:8080', { proxy: 'http://someproxy' });
+ this.stub(bag, 'http', { request: mockBagRequest, proxy: function(url) { return 'http://someproxy'; }});
+ var jenkins = new Jenkins('http://localhost:8080');
jenkins.console('job1', { interval: 1 }, function (err, result) {
assert.equals(err, undefined);
assert.equals(result, undefined);
@@ -232,8 +230,7 @@ buster.testCase('jenkins - console', {
statusCode: 200,
headers: { 'x-more-data': 'false', 'x-text-size': 20 }
});
- this.stub(process, 'env', {}); // simulate no http_proxy environment variable
- this.stub(bag, 'http', { request: mockBagRequest });
+ this.stub(bag, 'http', { request: mockBagRequest, proxy: function () { return undefined; }});
var jenkins = new Jenkins('http://localhost:8080');
jenkins.console('job1', { interval: 1 }, function (err, result) {
assert.equals(err, undefined);
@@ -257,7 +254,7 @@ buster.testCase('jenkins - console', {
// the subsequent request uses request module
var mockRequest = this.mock(request);
mockRequest.expects('get').once().callsArgWith(1, new Error('someerror'));
- this.stub(bag, 'http', { request: mockBagRequest });
+ this.stub(bag, 'http', { request: mockBagRequest, proxy: function () { return undefined; }});
var jenkins = new Jenkins('http://localhost:8080');
jenkins.console('job1', { interval: 1 }, function (err, result) {
assert.equals(err.message, 'someerror');

0 comments on commit 325ce86

Please sign in to comment.