|
| 1 | +var caronte = require('../'), |
| 2 | + WebSocket = require('../lib/caronte/streams/websocket'); |
| 3 | + expect = require('expect.js'), |
| 4 | + Duplex = require('stream').Duplex, |
| 5 | + http = require('http'); |
| 6 | + |
| 7 | + |
| 8 | +describe('lib/caronte/streams/websocket.js', function () { |
| 9 | + describe('WebSocket stream constructor', function () { |
| 10 | + it('should be an instance of Duplex stream and get the correct options and methods', function () { |
| 11 | + var stubOptions = { |
| 12 | + key: 'value' |
| 13 | + }; |
| 14 | + var WebSocketStream = new WebSocket(stubOptions); |
| 15 | + |
| 16 | + expect(WebSocketStream).to.be.a(Duplex); |
| 17 | + expect(WebSocketStream.options).to.eql({ key: 'value' }); |
| 18 | + expect(WebSocketStream.onPipe).to.be.a('function'); |
| 19 | + expect(WebSocketStream.onFinish).to.be.a('function'); |
| 20 | + expect(WebSocketStream._events).to.have.property('pipe'); |
| 21 | + expect(WebSocketStream._events).to.have.property('finish'); |
| 22 | + }); |
| 23 | + }); |
| 24 | + |
| 25 | + describe('caronte createWebSocketServer() method', function () { |
| 26 | + // it('should make the request on pipe and finish it', function(done) { |
| 27 | + // var proxy = caronte.createProxyServer({ |
| 28 | + // target: 'http://127.0.0.1:8080' |
| 29 | + // }).listen('8081'); |
| 30 | + |
| 31 | + // var source = http.createServer(function(req, res) { |
| 32 | + // expect(req.headers['x-forwarded-for']).to.eql('127.0.0.1'); |
| 33 | + // source.close(); |
| 34 | + // proxy.close(); |
| 35 | + // done(); |
| 36 | + // }); |
| 37 | + |
| 38 | + // source.listen('8080'); |
| 39 | + |
| 40 | + // http.request({ |
| 41 | + // hostname: '127.0.0.1', |
| 42 | + // port: '8081', |
| 43 | + // method: 'POST', |
| 44 | + // headers: { |
| 45 | + // 'x-forwarded-for': '127.0.0.1' |
| 46 | + // } |
| 47 | + // }, function() {}).end(); |
| 48 | + // }); |
| 49 | + }); |
| 50 | + |
| 51 | + describe('caronte createProxyServer() method with response', function () { |
| 52 | + // it('should make the request, handle response and finish it', function(done) { |
| 53 | + // var proxy = caronte.createProxyServer({ |
| 54 | + // target: 'http://127.0.0.1:8080' |
| 55 | + // }).listen('8081'); |
| 56 | + |
| 57 | + // var source = http.createServer(function(req, res) { |
| 58 | + // expect(req.method).to.eql('GET'); |
| 59 | + // res.writeHead(200, {'Content-Type': 'text/plain'}) |
| 60 | + // res.end('Hello from ' + source.address().port); |
| 61 | + // }); |
| 62 | + |
| 63 | + // source.listen('8080'); |
| 64 | + |
| 65 | + // http.request({ |
| 66 | + // hostname: '127.0.0.1', |
| 67 | + // port: '8081', |
| 68 | + // method: 'GET', |
| 69 | + // }, function(res) { |
| 70 | + // expect(res.statusCode).to.eql(200); |
| 71 | + |
| 72 | + // res.on('data', function (data) { |
| 73 | + // expect(data.toString()).to.eql('Hello from 8080'); |
| 74 | + // }); |
| 75 | + |
| 76 | + // res.on('end', function () { |
| 77 | + // source.close(); |
| 78 | + // proxy.close(); |
| 79 | + // done(); |
| 80 | + // }); |
| 81 | + // }).end(); |
| 82 | + // }); |
| 83 | + }); |
| 84 | + |
| 85 | + describe('caronte createProxyServer() method with error response', function () { |
| 86 | + // it('should make the request and response with error', function(done) { |
| 87 | + // var proxy = caronte.createProxyServer({ |
| 88 | + // target: 'http://127.0.0.1:8080' |
| 89 | + // }).listen('8081'); |
| 90 | + |
| 91 | + // http.request({ |
| 92 | + // hostname: '127.0.0.1', |
| 93 | + // port: '8081', |
| 94 | + // method: 'GET', |
| 95 | + // }, function(res) { |
| 96 | + // expect(res.statusCode).to.eql(500); |
| 97 | + |
| 98 | + // res.on('data', function (data) { |
| 99 | + // expect(data.toString()).to.eql('Internal Server Error'); |
| 100 | + // }); |
| 101 | + |
| 102 | + // res.on('end', function () { |
| 103 | + // proxy.close(); |
| 104 | + // done(); |
| 105 | + // }); |
| 106 | + // }).end(); |
| 107 | + // }); |
| 108 | + }); |
| 109 | +}); |
0 commit comments