@@ -5,7 +5,7 @@ const assert = require('assert');
55const dns = require ( 'dns' ) ;
66
77const existing = dns . getServers ( ) ;
8- assert ( existing . length ) ;
8+ assert ( existing . length > 0 ) ;
99
1010// Verify that setServers() handles arrays with holes and other oddities
1111assert . doesNotThrow ( ( ) => {
@@ -42,7 +42,8 @@ const goog = [
4242] ;
4343assert . doesNotThrow ( ( ) => dns . setServers ( goog ) ) ;
4444assert . deepStrictEqual ( dns . getServers ( ) , goog ) ;
45- assert . throws ( ( ) => dns . setServers ( [ 'foobar' ] ) ) ;
45+ assert . throws ( ( ) => dns . setServers ( [ 'foobar' ] ) ,
46+ / ^ E r r o r : I P a d d r e s s i s n o t p r o p e r l y f o r m a t t e d : f o o b a r $ / ) ;
4647assert . deepStrictEqual ( dns . getServers ( ) , goog ) ;
4748
4849const goog6 = [
@@ -77,20 +78,18 @@ assert.throws(() => {
7778} , 'Unexpected error' ) ;
7879
7980// dns.lookup should accept falsey and string values
80- assert . throws ( ( ) => dns . lookup ( { } , noop ) ,
81- 'invalid arguments: hostname must be a string or falsey' ) ;
81+ const errorReg =
82+ / ^ 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 $ / ;
8283
83- assert . throws ( ( ) => dns . lookup ( [ ] , noop ) ,
84- 'invalid arguments: hostname must be a string or falsey' ) ;
84+ assert . throws ( ( ) => dns . lookup ( { } , noop ) , errorReg ) ;
8585
86- assert . throws ( ( ) => dns . lookup ( true , noop ) ,
87- 'invalid arguments: hostname must be a string or falsey' ) ;
86+ assert . throws ( ( ) => dns . lookup ( [ ] , noop ) , errorReg ) ;
8887
89- assert . throws ( ( ) => dns . lookup ( 1 , noop ) ,
90- 'invalid arguments: hostname must be a string or falsey' ) ;
88+ assert . throws ( ( ) => dns . lookup ( true , noop ) , errorReg ) ;
9189
92- assert . throws ( ( ) => dns . lookup ( noop , noop ) ,
93- 'invalid arguments: hostname must be a string or falsey' ) ;
90+ assert . throws ( ( ) => dns . lookup ( 1 , noop ) , errorReg ) ;
91+
92+ assert . throws ( ( ) => dns . lookup ( noop , noop ) , errorReg ) ;
9493
9594assert . doesNotThrow ( ( ) => dns . lookup ( '' , noop ) ) ;
9695
@@ -114,13 +113,13 @@ assert.doesNotThrow(() => dns.lookup(NaN, noop));
114113assert . throws ( ( ) => {
115114 dns . lookup ( 'www.google.com' , { hints : ( dns . V4MAPPED | dns . ADDRCONFIG ) + 1 } ,
116115 noop ) ;
117- } ) ;
116+ } , / ^ 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 $ / ) ;
118117
119118assert . throws ( ( ) => dns . lookup ( 'www.google.com' ) ,
120- 'invalid arguments: callback must be passed' ) ;
119+ / ^ 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 $ / ) ;
121120
122121assert . throws ( ( ) => dns . lookup ( 'www.google.com' , 4 ) ,
123- 'invalid arguments: callback must be passed' ) ;
122+ / ^ 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 $ / ) ;
124123
125124assert . doesNotThrow ( ( ) => dns . lookup ( 'www.google.com' , 6 , noop ) ) ;
126125
@@ -143,26 +142,29 @@ assert.doesNotThrow(() => {
143142 } , noop ) ;
144143} ) ;
145144
146- assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' ) , / I n v a l i d a r g u m e n t s / ) ;
145+ assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' ) ,
146+ / ^ E r r o r : I n v a l i d a r g u m e n t s $ / ) ;
147147
148148assert . throws ( ( ) => dns . lookupService ( 'fasdfdsaf' , 0 , noop ) ,
149- / " 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 / ) ;
149+ / ^ 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 $ / ) ;
150150
151151assert . doesNotThrow ( ( ) => dns . lookupService ( '0.0.0.0' , '0' , noop ) ) ;
152152
153153assert . doesNotThrow ( ( ) => dns . lookupService ( '0.0.0.0' , 0 , noop ) ) ;
154154
155155assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , null , noop ) ,
156- / " 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 " / ) ;
156+ / ^ 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 " $ / ) ;
157157
158- assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , undefined , noop ) ,
159- / " 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 " / ) ;
158+ assert . throws (
159+ ( ) => dns . lookupService ( '0.0.0.0' , undefined , noop ) ,
160+ / ^ 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 " $ /
161+ ) ;
160162
161163assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , 65538 , noop ) ,
162- / " 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 " / ) ;
164+ / ^ 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 " $ / ) ;
163165
164166assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , 'test' , noop ) ,
165- / " 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 " / ) ;
167+ / ^ 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 " $ / ) ;
166168
167169assert . throws ( ( ) => dns . lookupService ( '0.0.0.0' , 80 , null ) ,
168170 / ^ T y p e E r r o r : " c a l l b a c k " a r g u m e n t m u s t b e a f u n c t i o n $ / ) ;
0 commit comments