1
+ var nock = require ( '../' ) ;
2
+ var test = require ( 'tap' ) . test ;
3
+ var http = require ( 'http' ) ;
4
+
5
+ test ( "IPV6 URL in http.get get gets mocked" , function ( t ) {
6
+ var dataCalled = false ;
7
+
8
+ var scope = nock ( 'http://[2607:f0d0:1002:51::4]:8080' )
9
+ . get ( '/' )
10
+ . reply ( 200 , "Hello World!" ) ;
11
+
12
+ http . get ( 'http://[2607:f0d0:1002:51::4]:8080/' , function ( res ) {
13
+ t . equal ( res . statusCode , 200 , "Status code is 200" ) ;
14
+ res . on ( 'end' , function ( ) {
15
+ t . ok ( dataCalled , "data handler was called" ) ;
16
+ scope . done ( ) ;
17
+ t . end ( ) ;
18
+ } ) ;
19
+ res . on ( 'data' , function ( data ) {
20
+ dataCalled = true ;
21
+ t . ok ( data instanceof Buffer , "data should be buffer" ) ;
22
+ t . equal ( data . toString ( ) , "Hello World!" , "response should match" ) ;
23
+ } ) ;
24
+
25
+ } ) ;
26
+ } ) ;
27
+
28
+ test ( "IPV6 hostname in http.request get gets mocked" , function ( t ) {
29
+ var dataCalled = false ;
30
+
31
+ var scope = nock ( 'http://[2607:f0d0:1002:51::5]:8080' )
32
+ . get ( '/' )
33
+ . reply ( 200 , "Hello World!" ) ;
34
+
35
+ http . request ( {
36
+ hostname : '2607:f0d0:1002:51::5' ,
37
+ path : '/' ,
38
+ method : 'GET' ,
39
+ port : 8080 ,
40
+ } , function ( res ) {
41
+ t . equal ( res . statusCode , 200 , "Status code is 200" ) ;
42
+ res . on ( 'end' , function ( ) {
43
+ t . ok ( dataCalled , "data handler was called" ) ;
44
+ scope . done ( ) ;
45
+ t . end ( ) ;
46
+ } ) ;
47
+ res . on ( 'data' , function ( data ) {
48
+ dataCalled = true ;
49
+ t . ok ( data instanceof Buffer , "data should be buffer" ) ;
50
+ t . equal ( data . toString ( ) , "Hello World!" , "response should match" ) ;
51
+ } ) ;
52
+ } ) . end ( ) ;
53
+ } ) ;
0 commit comments