-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.js
49 lines (35 loc) · 1.12 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*eslint node/no-unpublished-require: 0*/
var http = require('http');
var request = require('request');
var expect = require('chai').expect;
var TEST_PORT = 54674
var PROXY_PORT = process.env.PORT || 3000
var BODY = "Expected message from remote server"
process.env.LISTEN_DOMAIN = `127.0.0.1`
process.env.TARGET_DOMAIN = `127.0.0.1:${TEST_PORT}`
var redbirdProxy = require('./app');
describe("Target with a hostname", function(){
it("Should have the host header passed to the target", function(done){
expect(redbirdProxy.routing).to.be.an("object");
expect(redbirdProxy.routing).to.have.property('127.0.0.1');
testServer().then(function(req){
expect(req.headers['host']).to.be.eql(process.env.LISTEN_DOMAIN)
})
request.get('http://127.0.0.1:' + PROXY_PORT, function(req, res, body) {
expect(body).to.be.equals(BODY)
redbirdProxy.close();
done();
});
})
})
function testServer(){
return new Promise(function(resolve){
var server = http.createServer(function(req, res){
res.write(BODY)
res.end();
resolve(req);
server.close();
});
server.listen(TEST_PORT);
})
}