@@ -91,34 +91,47 @@ assert.doesNotThrow(() => dns.setServers([]));
91
91
assert . deepStrictEqual ( dns . getServers ( ) , [ ] ) ;
92
92
93
93
assert . throws ( ( ) => {
94
- dns . resolve ( 'test.com' , [ ] , common . noop ) ;
94
+ dns . resolve ( 'test.com' , [ ] , common . mustNotCall ( ) ) ;
95
95
} , function ( err ) {
96
96
return ! ( err instanceof TypeError ) ;
97
97
} , 'Unexpected error' ) ;
98
98
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 $ / ;
102
103
103
- assert . throws ( ( ) => dns . lookup ( { } , common . noop ) , errorReg ) ;
104
+ assert . throws ( ( ) => dns . lookup ( { } , common . mustNotCall ( ) ) , errorReg ) ;
104
105
105
- assert . throws ( ( ) => dns . lookup ( [ ] , common . noop ) , errorReg ) ;
106
+ assert . throws ( ( ) => dns . lookup ( [ ] , common . mustNotCall ( ) ) , errorReg ) ;
106
107
107
- assert . throws ( ( ) => dns . lookup ( true , common . noop ) , errorReg ) ;
108
+ assert . throws ( ( ) => dns . lookup ( true , common . mustNotCall ( ) ) , errorReg ) ;
108
109
109
- assert . throws ( ( ) => dns . lookup ( 1 , common . noop ) , errorReg ) ;
110
+ assert . throws ( ( ) => dns . lookup ( 1 , common . mustNotCall ( ) ) , errorReg ) ;
110
111
111
- assert . throws ( ( ) => dns . lookup ( common . noop , common . noop ) , errorReg ) ;
112
+ assert . throws ( ( ) => dns . lookup ( common . mustNotCall ( ) , common . mustNotCall ( ) ) ,
113
+ errorReg ) ;
114
+ }
112
115
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
+ } ;
114
123
115
- assert . doesNotThrow ( ( ) => dns . lookup ( null , common . noop ) ) ;
124
+ assert . doesNotThrow ( ( ) => dns . lookup ( '' , common . mustCall ( checkCallback ) ) ) ;
116
125
117
- assert . doesNotThrow ( ( ) => dns . lookup ( undefined , common . noop ) ) ;
126
+ assert . doesNotThrow ( ( ) => dns . lookup ( null , common . mustCall ( checkCallback ) ) ) ;
118
127
119
- assert . doesNotThrow ( ( ) => dns . lookup ( 0 , common . noop ) ) ;
128
+ assert . doesNotThrow ( ( ) => dns . lookup ( undefined ,
129
+ common . mustCall ( checkCallback ) ) ) ;
120
130
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
+ }
122
135
123
136
/*
124
137
* 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));
130
143
* flags are either === 1 or even.
131
144
*/
132
145
assert . 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 ( ) ) ;
135
148
} , / ^ 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 $ / ) ;
136
149
137
- assert . throws ( ( ) => dns . lookup ( 'www.google.com ' ) ,
150
+ assert . throws ( ( ) => dns . lookup ( 'nodejs.org ' ) ,
138
151
/ ^ 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 $ / ) ;
139
152
140
- assert . throws ( ( ) => dns . lookup ( 'www.google.com ' , 4 ) ,
153
+ assert . throws ( ( ) => dns . lookup ( 'nodejs.org ' , 4 ) ,
141
154
/ ^ 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 $ / ) ;
142
155
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 ( ) ) ) ;
148
158
149
159
assert . doesNotThrow ( ( ) => {
150
160
dns . lookup ( '' , {
151
161
family : 6 ,
152
162
hints : dns . ADDRCONFIG
153
- } , common . noop ) ;
163
+ } , common . mustCall ( ) ) ;
154
164
} ) ;
155
165
156
- assert . doesNotThrow ( ( ) => dns . lookup ( '' , { hints : dns . V4MAPPED } , common . noop ) ) ;
166
+ assert . doesNotThrow ( ( ) => dns . lookup ( '' , { hints : dns . V4MAPPED } ,
167
+ common . mustCall ( ) ) ) ;
157
168
158
169
assert . doesNotThrow ( ( ) => {
159
170
dns . lookup ( '' , {
160
171
hints : dns . ADDRCONFIG | dns . V4MAPPED
161
- } , common . noop ) ;
172
+ } , common . mustCall ( ) ) ;
162
173
} ) ;
163
174
164
175
assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' ) ,
165
176
/ ^ E r r o r : I n v a l i d a r g u m e n t s $ / ) ;
166
177
167
- assert . throws ( ( ) => dns . lookupService ( 'fasdfdsaf' , 0 , common . noop ) ,
178
+ assert . throws ( ( ) => dns . lookupService ( 'fasdfdsaf' , 0 , common . mustNotCall ( ) ) ,
168
179
/ ^ 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 $ / ) ;
169
180
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 ( ) ) ,
175
182
/ ^ 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 " $ / ) ;
176
183
177
184
assert . throws (
178
- ( ) => dns . lookupService ( '0.0.0.0' , undefined , common . noop ) ,
185
+ ( ) => dns . lookupService ( '0.0.0.0' , undefined , common . mustNotCall ( ) ) ,
179
186
/ ^ 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 " $ /
180
187
) ;
181
188
182
- assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , 65538 , common . noop ) ,
189
+ assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , 65538 , common . mustNotCall ( ) ) ,
183
190
/ ^ 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 " $ / ) ;
184
191
185
- assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , 'test' , common . noop ) ,
192
+ assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , 'test' , common . mustNotCall ( ) ) ,
186
193
/ ^ 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 " $ / ) ;
187
194
188
195
assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , 80 , null ) ,
0 commit comments