@@ -174,10 +174,63 @@ Encode string s using a URL-safe alphabet, which substitutes - instead of + and
174174 } ) ;
175175
176176 describe ( 'getIP(), getIPv6(), getIPv4()' , function ( ) {
177+ afterEach ( mm . restore ) ;
178+
177179 it ( 'should return ip version 4 address' , function ( ) {
180+ mm ( os , 'networkInterfaces' , function ( ) {
181+ return { lo0 :
182+ [ { address : '::1' , family : 'IPv6' , internal : true } ,
183+ { address : 'fe80::1' , family : 'IPv6' , internal : true } ,
184+ { address : '127.0.0.1' , family : 'IPv4' , internal : true } ] ,
185+ en0 :
186+ [ { address : 'fe81::cabc:c8ff:feef:f996' , family : 'IPv6' ,
187+ internal : true } ,
188+ { address : '10.0.1.123' , family : 'IPv4' , internal : false } ] ,
189+ en7 :
190+ [ { address : 'fe80::cabc:c8ff:feef:f996' , family : 'IPv6' ,
191+ internal : false } ,
192+ { address : '10.0.1.123' , family : 'IPv4' , internal : false } ] ,
193+ vmnet1 : [ { address : '10.99.99.254' , family : 'IPv4' , internal : false } ] ,
194+ vmnet8 : [ { address : '10.88.88.1' , family : 'IPv4' , internal : false } ] ,
195+ ppp0 : [ { address : '10.2.0.231' , family : 'IPv4' , internal : false } ]
196+ } ;
197+ } ) ;
198+ mm ( os , 'platform' , function ( ) {
199+ return 'darwin' ;
200+ } ) ;
178201 var address = utils . getIP ( ) ;
202+ should . exists ( address ) ;
203+ address . should . equal ( utils . getIPv4 ( ) ) ;
204+ address . should . match ( / ^ \d { 1 , 3 } \. \d { 1 , 3 } \. \d { 1 , 3 } \. \d { 1 , 3 } $ / ) ;
205+ address . should . equal ( '10.0.1.123' ) ;
206+ mm . restore ( ) ;
207+
208+ mm ( os , 'networkInterfaces' , function ( ) {
209+ return { lo0 :
210+ [ { address : '::1' , family : 'IPv6' , internal : true } ,
211+ { address : 'fe80::1' , family : 'IPv6' , internal : true } ,
212+ { address : '127.0.0.1' , family : 'IPv4' , internal : true } ] ,
213+ eth0 :
214+ [ { address : 'fe81::cabc:c8ff:feef:f996' , family : 'IPv6' ,
215+ internal : true } ,
216+ { address : '10.0.1.124' , family : 'IPv4' , internal : false } ] ,
217+ eth2 :
218+ [ { address : 'fe80::cabc:c8ff:feef:f996' , family : 'IPv6' ,
219+ internal : false } ,
220+ { address : '10.0.1.123' , family : 'IPv4' , internal : false } ] ,
221+ vmnet1 : [ { address : '10.99.99.254' , family : 'IPv4' , internal : false } ] ,
222+ vmnet8 : [ { address : '10.88.88.1' , family : 'IPv4' , internal : false } ] ,
223+ ppp0 : [ { address : '10.2.0.231' , family : 'IPv4' , internal : false } ]
224+ } ;
225+ } ) ;
226+ mm ( os , 'platform' , function ( ) {
227+ return 'linux' ;
228+ } ) ;
229+ address = utils . getIP ( ) ;
230+ should . exists ( address ) ;
179231 address . should . equal ( utils . getIPv4 ( ) ) ;
180232 address . should . match ( / ^ \d { 1 , 3 } \. \d { 1 , 3 } \. \d { 1 , 3 } \. \d { 1 , 3 } $ / ) ;
233+ address . should . equal ( '10.0.1.124' ) ;
181234 } ) ;
182235
183236 it ( 'should return ip version 6 address' , function ( ) {
@@ -186,11 +239,11 @@ Encode string s using a URL-safe alphabet, which substitutes - instead of + and
186239 [ { address : '::1' , family : 'IPv6' , internal : true } ,
187240 { address : 'fe80::1' , family : 'IPv6' , internal : true } ,
188241 { address : '127.0.0.1' , family : 'IPv4' , internal : true } ] ,
189- en0 :
242+ eth0 :
190243 [ { address : 'fe81::cabc:c8ff:feef:f996' , family : 'IPv6' ,
191244 internal : true } ,
192245 { address : '10.0.1.123' , family : 'IPv4' , internal : false } ] ,
193- en7 :
246+ eth7 :
194247 [ { address : 'fe80::cabc:c8ff:feef:f996' , family : 'IPv6' ,
195248 internal : false } ,
196249 { address : '10.0.1.123' , family : 'IPv4' , internal : false } ] ,
@@ -199,6 +252,10 @@ Encode string s using a URL-safe alphabet, which substitutes - instead of + and
199252 ppp0 : [ { address : '10.2.0.231' , family : 'IPv4' , internal : false } ]
200253 } ;
201254 } ) ;
255+ mm ( os , 'platform' , function ( ) {
256+ return 'linux' ;
257+ } ) ;
258+
202259 var address = utils . getIPv6 ( ) ;
203260 should . exists ( address ) ;
204261 address . should . equal ( 'fe80::cabc:c8ff:feef:f996' ) ;
0 commit comments