mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[test] Updated node-http-proxy tests
This commit is contained in:
parent
e9511eafdf
commit
2f265a23e4
@ -31,7 +31,7 @@ var vows = require('vows'),
|
|||||||
|
|
||||||
require.paths.unshift(require('path').join(__dirname, '../lib/'));
|
require.paths.unshift(require('path').join(__dirname, '../lib/'));
|
||||||
|
|
||||||
var HttpProxy = require('node-http-proxy').HttpProxy;
|
var httpProxy = require('node-http-proxy');
|
||||||
var testServers = {};
|
var testServers = {};
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -77,7 +77,7 @@ var startTargetServer = function (port) {
|
|||||||
//
|
//
|
||||||
var startTest = function (proxy, port) {
|
var startTest = function (proxy, port) {
|
||||||
testServers.noLatency = [];
|
testServers.noLatency = [];
|
||||||
testServers.noLatency.push(startProxyServer('127.0.0.1', port, proxy));
|
testServers.noLatency.push(startProxyServer('localhost', port, proxy));
|
||||||
testServers.noLatency.push(startTargetServer(port));
|
testServers.noLatency.push(startTargetServer(port));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -86,44 +86,48 @@ var startTest = function (proxy, port) {
|
|||||||
//
|
//
|
||||||
var startTestWithLatency = function (proxy, port) {
|
var startTestWithLatency = function (proxy, port) {
|
||||||
testServers.latency = [];
|
testServers.latency = [];
|
||||||
testServers.latency.push(startLatentProxyServer('127.0.0.1', port, proxy, 2000));
|
testServers.latency.push(startLatentProxyServer('localhost', port, proxy, 2000));
|
||||||
testServers.latency.push(startTargetServer(port));
|
testServers.latency.push(startTargetServer(port));
|
||||||
};
|
};
|
||||||
|
|
||||||
vows.describe('node-proxy').addBatch({
|
vows.describe('node-http-proxy').addBatch({
|
||||||
"When an incoming request is proxied to the helloNode server" : {
|
"A node-http-proxy": {
|
||||||
"with no latency" : {
|
"when instantiated directly": {
|
||||||
topic: function () {
|
"and an incoming request is proxied to the helloNode server" : {
|
||||||
var proxy = new (HttpProxy);
|
"with no latency" : {
|
||||||
startTest(proxy, 8082);
|
topic: function () {
|
||||||
proxy.emitter.addListener('end', this.callback);
|
var proxy = new (httpProxy.HttpProxy);
|
||||||
|
startTest(proxy, 8082);
|
||||||
|
proxy.emitter.addListener('end', this.callback);
|
||||||
|
|
||||||
var client = http.createClient(8080, '127.0.0.1');
|
var client = http.createClient(8080, 'localhost');
|
||||||
var request = client.request('GET', '/');
|
var request = client.request('GET', '/');
|
||||||
request.end();
|
request.end();
|
||||||
},
|
},
|
||||||
"it should received 'hello world'": function (err, body) {
|
"it should received 'hello world'": function (err, body) {
|
||||||
assert.equal(body, 'hello world');
|
assert.equal(body, 'hello world');
|
||||||
testServers.noLatency.forEach(function (server) {
|
testServers.noLatency.forEach(function (server) {
|
||||||
server.close();
|
server.close();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"with latency": {
|
"with latency": {
|
||||||
topic: function () {
|
topic: function () {
|
||||||
var proxy = new (HttpProxy);
|
var proxy = new (httpProxy.HttpProxy);
|
||||||
startTestWithLatency(proxy, 8083);
|
startTestWithLatency(proxy, 8083);
|
||||||
proxy.emitter.addListener('end', this.callback);
|
proxy.emitter.addListener('end', this.callback);
|
||||||
|
|
||||||
var client = http.createClient(8081, '127.0.0.1');
|
var client = http.createClient(8081, 'localhost');
|
||||||
var request = client.request('GET', '/');
|
var request = client.request('GET', '/');
|
||||||
request.end();
|
request.end();
|
||||||
},
|
},
|
||||||
"it should receive 'hello world'": function (err, body) {
|
"it should receive 'hello world'": function (err, body) {
|
||||||
assert.equal(body, 'hello world');
|
assert.equal(body, 'hello world');
|
||||||
testServers.latency.forEach(function (server) {
|
testServers.latency.forEach(function (server) {
|
||||||
server.close();
|
server.close();
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user