1
1
var common = require ( '../lib/caronte/common' ) ,
2
2
expect = require ( 'expect.js' ) ;
3
3
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 ( ) {
7
7
var outgoing = { } ;
8
8
common . setupOutgoing ( outgoing ,
9
9
{
@@ -17,19 +17,75 @@ describe('lib/caronte/common.js', function() {
17
17
} ,
18
18
{
19
19
method : 'i' ,
20
- path : 'am' ,
20
+ url : 'am' ,
21
21
headers : 'proxy'
22
22
} ) ;
23
23
24
24
expect ( outgoing . host ) . to . eql ( 'hey' ) ;
25
25
expect ( outgoing . hostname ) . to . eql ( 'how' ) ;
26
26
expect ( outgoing . socketPath ) . to . eql ( 'are' ) ;
27
27
expect ( outgoing . port ) . to . eql ( 'you' ) ;
28
- // expect(outgoing.agent).to.eql('?');
28
+ expect ( outgoing . agent ) . to . eql ( '?' ) ;
29
29
30
30
expect ( outgoing . method ) . to . eql ( 'i' ) ;
31
31
expect ( outgoing . path ) . to . eql ( 'am' ) ;
32
32
expect ( outgoing . headers ) . to . eql ( 'proxy' )
33
33
} ) ;
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
+ } ) ;
34
90
} ) ;
35
91
} ) ;
0 commit comments