This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
102 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
'use strict'; | ||
var RAIL = require('./rail'); | ||
var globalClient = new RAIL(); | ||
|
||
module.exports = exports = require('./rail'); | ||
module.exports = exports = RAIL; | ||
|
||
exports.Call = require('./call'); | ||
exports.plugins = require('./plugins'); | ||
|
||
globalClient.use('buffer'); | ||
globalClient.use('json'); | ||
globalClient.use('redirect'); | ||
globalClient.use('cookies'); | ||
|
||
exports.globalClient = globalClient; | ||
|
||
|
||
function call(urlOrOptions, responseListener) { | ||
return globalClient.call(urlOrOptions, responseListener); | ||
} | ||
exports.call = call; |
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,86 @@ | ||
'use strict'; | ||
/* global suite: false, setup: false, test: false, | ||
teardown: false, suiteSetup: false, suiteTeardown: false */ | ||
var assert = require('assert'); | ||
var common = require('./common'); | ||
var https = require('https'); | ||
var RAIL = require('../'); | ||
|
||
|
||
suite('global', function() { | ||
var server; | ||
var onrequest; | ||
|
||
var listener = function(request, response) { | ||
if (typeof onrequest === 'function') { | ||
onrequest(request, response); | ||
} | ||
}; | ||
|
||
|
||
suiteSetup(function(done) { | ||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; | ||
|
||
var options = { | ||
key: common.serverKey, | ||
cert: common.serverCert | ||
}; | ||
|
||
server = https.createServer(options, listener); | ||
server.listen(common.port, done); | ||
}); | ||
|
||
|
||
test('call(url)', function(done) { | ||
var path = '/some/path/on/the/service'; | ||
var url = 'https://localhost:' + common.port + path; | ||
|
||
onrequest = function(request, response) { | ||
assert.strictEqual(request.url, path); | ||
response.end('pong'); | ||
}; | ||
|
||
RAIL.call(url, function(response) { | ||
var body = []; | ||
|
||
response.on('readable', function() { | ||
var data = response.read(); | ||
body.push(data); | ||
}); | ||
|
||
response.on('end', function() { | ||
assert.strictEqual(response.statusCode, 200); | ||
assert.strictEqual(Buffer.concat(body).toString(), 'pong'); | ||
done(); | ||
}); | ||
}).end(); | ||
}); | ||
|
||
|
||
test('call(options-with-url)', function(done) { | ||
var path = '/some/other/path/on/the/service'; | ||
var url = 'https://localhost:' + common.port + path; | ||
|
||
onrequest = function(request, response) { | ||
assert.strictEqual(request.url, path); | ||
response.end('pong'); | ||
}; | ||
|
||
RAIL.call({ | ||
url: url, | ||
buffer: true | ||
}, function(response) { | ||
assert.strictEqual(response.statusCode, 200); | ||
assert(response.buffer); | ||
assert.strictEqual(response.buffer.toString(), 'pong'); | ||
done(); | ||
}).end(); | ||
}); | ||
|
||
|
||
suiteTeardown(function(done) { | ||
delete process.env.NODE_TLS_REJECT_UNAUTHORIZED; | ||
|
||
server.close(done); | ||
}); | ||
}); |