Skip to content

Commit 1cb967b

Browse files
committed
[tests] fixed according new refactor and added test to common.setupSocket()
1 parent 5bb83b9 commit 1cb967b

File tree

1 file changed

+61
-5
lines changed

1 file changed

+61
-5
lines changed

Diff for: test/lib-caronte-common-test.js

+61-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
var common = require('../lib/caronte/common'),
22
expect = require('expect.js');
33

4-
describe('lib/caronte/common.js', function() {
5-
describe('#setupOutgoing', function() {
6-
it('should setup the right headers', function() {
4+
describe('lib/caronte/common.js', function () {
5+
describe('#setupOutgoing', function () {
6+
it('should setup the correct headers', function () {
77
var outgoing = {};
88
common.setupOutgoing(outgoing,
99
{
@@ -17,19 +17,75 @@ describe('lib/caronte/common.js', function() {
1717
},
1818
{
1919
method : 'i',
20-
path : 'am',
20+
url : 'am',
2121
headers : 'proxy'
2222
});
2323

2424
expect(outgoing.host).to.eql('hey');
2525
expect(outgoing.hostname).to.eql('how');
2626
expect(outgoing.socketPath).to.eql('are');
2727
expect(outgoing.port).to.eql('you');
28-
//expect(outgoing.agent).to.eql('?');
28+
expect(outgoing.agent).to.eql('?');
2929

3030
expect(outgoing.method).to.eql('i');
3131
expect(outgoing.path).to.eql('am');
3232
expect(outgoing.headers).to.eql('proxy')
3333
});
34+
35+
it('set the port according to the protocol', function () {
36+
var outgoing = {};
37+
common.setupOutgoing(outgoing,
38+
{
39+
target: {
40+
host : 'how',
41+
hostname : 'are',
42+
socketPath: 'you',
43+
agent : '?',
44+
protocol: 'https:'
45+
}
46+
},
47+
{
48+
method : 'i',
49+
url : 'am',
50+
headers : 'proxy'
51+
});
52+
53+
expect(outgoing.host).to.eql('how');
54+
expect(outgoing.hostname).to.eql('are');
55+
expect(outgoing.socketPath).to.eql('you');
56+
expect(outgoing.agent).to.eql('?');
57+
58+
expect(outgoing.method).to.eql('i');
59+
expect(outgoing.path).to.eql('am');
60+
expect(outgoing.headers).to.eql('proxy')
61+
62+
expect(outgoing.port).to.eql(443);
63+
});
64+
});
65+
66+
describe('#setupSocket', function () {
67+
it('should setup a socket', function () {
68+
var socketConfig = {
69+
timeout: null,
70+
nodelay: false,
71+
keepalive: false
72+
},
73+
stubSocket = {
74+
setTimeout: function (num) {
75+
socketConfig.timeout = num;
76+
},
77+
setNoDelay: function (bol) {
78+
socketConfig.nodelay = bol;
79+
},
80+
setKeepAlive: function (bol) {
81+
socketConfig.keepalive = bol;
82+
}
83+
}
84+
returnValue = common.setupSocket(stubSocket);
85+
86+
expect(socketConfig.timeout).to.eql(0);
87+
expect(socketConfig.nodelay).to.eql(true);
88+
expect(socketConfig.keepalive).to.eql(true);
89+
});
3490
});
3591
});

0 commit comments

Comments
 (0)