@@ -91,34 +91,47 @@ assert.doesNotThrow(() => dns.setServers([]));
9191assert . deepStrictEqual ( dns . getServers ( ) , [ ] ) ;
9292
9393assert . throws ( ( ) => {
94- dns . resolve ( 'test.com' , [ ] , common . noop ) ;
94+ dns . resolve ( 'test.com' , [ ] , common . mustNotCall ( ) ) ;
9595} , function ( err ) {
9696 return ! ( err instanceof TypeError ) ;
9797} , 'Unexpected error' ) ;
9898
99- // dns.lookup should accept falsey and string values
100- const errorReg =
101- / ^ T y p e E r r o r : I n v a l i d a r g u m e n t s : h o s t n a m e m u s t b e a s t r i n g o r f a l s e y $ / ;
99+ // dns.lookup should accept only falsey and string values
100+ {
101+ const errorReg =
102+ / ^ T y p e E r r o r : I n v a l i d a r g u m e n t s : h o s t n a m e m u s t b e a s t r i n g o r f a l s e y $ / ;
102103
103- assert . throws ( ( ) => dns . lookup ( { } , common . noop ) , errorReg ) ;
104+ assert . throws ( ( ) => dns . lookup ( { } , common . mustNotCall ( ) ) , errorReg ) ;
104105
105- assert . throws ( ( ) => dns . lookup ( [ ] , common . noop ) , errorReg ) ;
106+ assert . throws ( ( ) => dns . lookup ( [ ] , common . mustNotCall ( ) ) , errorReg ) ;
106107
107- assert . throws ( ( ) => dns . lookup ( true , common . noop ) , errorReg ) ;
108+ assert . throws ( ( ) => dns . lookup ( true , common . mustNotCall ( ) ) , errorReg ) ;
108109
109- assert . throws ( ( ) => dns . lookup ( 1 , common . noop ) , errorReg ) ;
110+ assert . throws ( ( ) => dns . lookup ( 1 , common . mustNotCall ( ) ) , errorReg ) ;
110111
111- assert . throws ( ( ) => dns . lookup ( common . noop , common . noop ) , errorReg ) ;
112+ assert . throws ( ( ) => dns . lookup ( common . mustNotCall ( ) , common . mustNotCall ( ) ) ,
113+ errorReg ) ;
114+ }
112115
113- assert . doesNotThrow ( ( ) => dns . lookup ( '' , common . noop ) ) ;
116+ // dns.lookup should accept falsey values
117+ {
118+ const checkCallback = ( err , address , family ) => {
119+ assert . ifError ( err ) ;
120+ assert . strictEqual ( address , null ) ;
121+ assert . strictEqual ( family , 4 ) ;
122+ } ;
114123
115- assert . doesNotThrow ( ( ) => dns . lookup ( null , common . noop ) ) ;
124+ assert . doesNotThrow ( ( ) => dns . lookup ( '' , common . mustCall ( checkCallback ) ) ) ;
116125
117- assert . doesNotThrow ( ( ) => dns . lookup ( undefined , common . noop ) ) ;
126+ assert . doesNotThrow ( ( ) => dns . lookup ( null , common . mustCall ( checkCallback ) ) ) ;
118127
119- assert . doesNotThrow ( ( ) => dns . lookup ( 0 , common . noop ) ) ;
128+ assert . doesNotThrow ( ( ) => dns . lookup ( undefined ,
129+ common . mustCall ( checkCallback ) ) ) ;
120130
121- assert . doesNotThrow ( ( ) => dns . lookup ( NaN , common . noop ) ) ;
131+ assert . doesNotThrow ( ( ) => dns . lookup ( 0 , common . mustCall ( checkCallback ) ) ) ;
132+
133+ assert . doesNotThrow ( ( ) => dns . lookup ( NaN , common . mustCall ( checkCallback ) ) ) ;
134+ }
122135
123136/*
124137 * Make sure that dns.lookup throws if hints does not represent a valid flag.
@@ -130,59 +143,53 @@ assert.doesNotThrow(() => dns.lookup(NaN, common.noop));
130143 * flags are either === 1 or even.
131144 */
132145assert . throws ( ( ) => {
133- dns . lookup ( 'www.google.com ' , { hints : ( dns . V4MAPPED | dns . ADDRCONFIG ) + 1 } ,
134- common . noop ) ;
146+ dns . lookup ( 'nodejs.org ' , { hints : ( dns . V4MAPPED | dns . ADDRCONFIG ) + 1 } ,
147+ common . mustNotCall ( ) ) ;
135148} , / ^ T y p e E r r o r : I n v a l i d a r g u m e n t : h i n t s m u s t u s e v a l i d f l a g s $ / ) ;
136149
137- assert . throws ( ( ) => dns . lookup ( 'www.google.com ' ) ,
150+ assert . throws ( ( ) => dns . lookup ( 'nodejs.org ' ) ,
138151 / ^ T y p e E r r o r : I n v a l i d a r g u m e n t s : c a l l b a c k m u s t b e p a s s e d $ / ) ;
139152
140- assert . throws ( ( ) => dns . lookup ( 'www.google.com ' , 4 ) ,
153+ assert . throws ( ( ) => dns . lookup ( 'nodejs.org ' , 4 ) ,
141154 / ^ T y p e E r r o r : I n v a l i d a r g u m e n t s : c a l l b a c k m u s t b e p a s s e d $ / ) ;
142155
143- assert . doesNotThrow ( ( ) => dns . lookup ( 'www.google.com' , 6 , common . noop ) ) ;
144-
145- assert . doesNotThrow ( ( ) => dns . lookup ( 'www.google.com' , { } , common . noop ) ) ;
146-
147- assert . doesNotThrow ( ( ) => dns . lookup ( '' , { family : 4 , hints : 0 } , common . noop ) ) ;
156+ assert . doesNotThrow ( ( ) => dns . lookup ( '' , { family : 4 , hints : 0 } ,
157+ common . mustCall ( ) ) ) ;
148158
149159assert . doesNotThrow ( ( ) => {
150160 dns . lookup ( '' , {
151161 family : 6 ,
152162 hints : dns . ADDRCONFIG
153- } , common . noop ) ;
163+ } , common . mustCall ( ) ) ;
154164} ) ;
155165
156- assert . doesNotThrow ( ( ) => dns . lookup ( '' , { hints : dns . V4MAPPED } , common . noop ) ) ;
166+ assert . doesNotThrow ( ( ) => dns . lookup ( '' , { hints : dns . V4MAPPED } ,
167+ common . mustCall ( ) ) ) ;
157168
158169assert . doesNotThrow ( ( ) => {
159170 dns . lookup ( '' , {
160171 hints : dns . ADDRCONFIG | dns . V4MAPPED
161- } , common . noop ) ;
172+ } , common . mustCall ( ) ) ;
162173} ) ;
163174
164175assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' ) ,
165176 / ^ E r r o r : I n v a l i d a r g u m e n t s $ / ) ;
166177
167- assert . throws ( ( ) => dns . lookupService ( 'fasdfdsaf' , 0 , common . noop ) ,
178+ assert . throws ( ( ) => dns . lookupService ( 'fasdfdsaf' , 0 , common . mustNotCall ( ) ) ,
168179 / ^ T y p e E r r o r : " h o s t " a r g u m e n t n e e d s t o b e a v a l i d I P a d d r e s s $ / ) ;
169180
170- assert . doesNotThrow ( ( ) => dns . lookupService ( '0.0.0.0' , '0' , common . noop ) ) ;
171-
172- assert . doesNotThrow ( ( ) => dns . lookupService ( '0.0.0.0' , 0 , common . noop ) ) ;
173-
174- assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , null , common . noop ) ,
181+ assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , null , common . mustNotCall ( ) ) ,
175182 / ^ T y p e E r r o r : " p o r t " s h o u l d b e > = 0 a n d < 6 5 5 3 6 , g o t " n u l l " $ / ) ;
176183
177184assert . throws (
178- ( ) => dns . lookupService ( '0.0.0.0' , undefined , common . noop ) ,
185+ ( ) => dns . lookupService ( '0.0.0.0' , undefined , common . mustNotCall ( ) ) ,
179186 / ^ T y p e E r r o r : " p o r t " s h o u l d b e > = 0 a n d < 6 5 5 3 6 , g o t " u n d e f i n e d " $ /
180187) ;
181188
182- assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , 65538 , common . noop ) ,
189+ assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , 65538 , common . mustNotCall ( ) ) ,
183190 / ^ T y p e E r r o r : " p o r t " s h o u l d b e > = 0 a n d < 6 5 5 3 6 , g o t " 6 5 5 3 8 " $ / ) ;
184191
185- assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , 'test' , common . noop ) ,
192+ assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , 'test' , common . mustNotCall ( ) ) ,
186193 / ^ T y p e E r r o r : " p o r t " s h o u l d b e > = 0 a n d < 6 5 5 3 6 , g o t " t e s t " $ / ) ;
187194
188195assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , 80 , null ) ,
0 commit comments