-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new:
appendPath
to supports appending to client base url (#171)
- Loading branch information
1 parent
df707ea
commit 1edd6da
Showing
5 changed files
with
178 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
'use strict'; | ||
|
||
// external files | ||
var assert = require('chai').assert; | ||
var bunyan = require('bunyan'); | ||
var restify = require('restify'); | ||
|
||
// local files | ||
var clients = require('../lib'); | ||
|
||
|
||
describe('`appendPath` option', function () { | ||
|
||
var SERVER; | ||
var CLIENT; | ||
var LOG = bunyan.createLogger({ | ||
name: 'clientlog' | ||
}); | ||
|
||
beforeEach(function (done) { | ||
SERVER = restify.createServer({ | ||
name: 'unittest', | ||
log: LOG | ||
}); | ||
SERVER.use(restify.plugins.queryParser()); | ||
SERVER.listen(3000, done); | ||
}); | ||
|
||
afterEach(function (done) { | ||
CLIENT.close(); | ||
SERVER.close(done); | ||
}); | ||
|
||
|
||
describe('constructor time appendPath', function () { | ||
|
||
it('should append to existing constructor time path', function (done) { | ||
SERVER.get('/foo/bar', function (req, res, next) { | ||
assert.deepEqual(req.path(), '/foo/bar'); | ||
res.send(200); | ||
return next(); | ||
}); | ||
|
||
CLIENT = clients.createJsonClient({ | ||
url: 'http://localhost:3000/foo', | ||
appendPath: true | ||
}); | ||
CLIENT.get('/bar', done); | ||
}); | ||
|
||
it('should append to bare host', function (done) { | ||
SERVER.get('/foo', function (req, res, next) { | ||
assert.deepEqual(req.path(), '/foo'); | ||
res.send(200); | ||
return next(); | ||
}); | ||
|
||
CLIENT = clients.createJsonClient({ | ||
url: 'http://localhost:3000', | ||
appendPath: true | ||
}); | ||
CLIENT.get('/foo', done); | ||
}); | ||
|
||
it('should dedupe url slashes', function (done) { | ||
SERVER.get('/foo', function (req, res, next) { | ||
assert.deepEqual(req.path(), '/foo'); | ||
res.send(200); | ||
return next(); | ||
}); | ||
|
||
CLIENT = clients.createJsonClient({ | ||
url: 'http://localhost:3000//', | ||
appendPath: true | ||
}); | ||
CLIENT.get('//foo', done); | ||
}); | ||
}); | ||
|
||
describe('verb time appendPath', function () { | ||
|
||
it('should append to existing constructor time path', function (done) { | ||
SERVER.get('/foo/bar', function (req, res, next) { | ||
assert.deepEqual(req.path(), '/foo/bar'); | ||
res.send(200); | ||
return next(); | ||
}); | ||
|
||
CLIENT = clients.createJsonClient({ | ||
url: 'http://localhost:3000/foo' | ||
}); | ||
CLIENT.get({ | ||
path: '/bar', | ||
appendPath: true | ||
}, done); | ||
}); | ||
|
||
it('should append to bare host', function (done) { | ||
SERVER.get('/foo', function (req, res, next) { | ||
assert.deepEqual(req.path(), '/foo'); | ||
res.send(200); | ||
return next(); | ||
}); | ||
|
||
CLIENT = clients.createJsonClient({ | ||
url: 'http://localhost:3000' | ||
}); | ||
CLIENT.get({ | ||
path: '/foo', | ||
appendPath: true | ||
}, done); | ||
}); | ||
|
||
it('should dedupe url slashes', function (done) { | ||
SERVER.get('/foo', function (req, res, next) { | ||
assert.deepEqual(req.path(), '/foo'); | ||
res.send(200); | ||
return next(); | ||
}); | ||
|
||
CLIENT = clients.createJsonClient({ | ||
url: 'http://localhost:3000//' | ||
}); | ||
CLIENT.get({ | ||
path: '//foo', | ||
appendPath: true | ||
}, done); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters