@@ -3,49 +3,51 @@ const common = require('../common');
33const assert = require ( 'assert' ) ;
44const dgram = require ( 'dgram' ) ;
55
6- const port = common . PORT ;
76const buf = Buffer . from ( 'test' ) ;
8- const client = dgram . createSocket ( 'udp4' ) ;
97
108const onMessage = common . mustCall ( ( err , bytes ) => {
119 assert . ifError ( err ) ;
1210 assert . strictEqual ( bytes , buf . length ) ;
1311} , 6 ) ;
1412
15- // valid address: false
16- client . send ( buf , port , false , onMessage ) ;
13+ const expectedError =
14+ / ^ 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 : a d d r e s s m u s t b e a n o n e m p t y s t r i n g o r f a l s y $ / ;
1715
18- // valid address: empty string
19- client . send ( buf , port , '' , onMessage ) ;
16+ const client = dgram . createSocket ( 'udp4' ) . bind ( 0 , ( ) => {
17+ const port = client . address ( ) . port ;
2018
21- // valid address: null
22- client . send ( buf , port , null , onMessage ) ;
19+ // valid address: false
20+ client . send ( buf , port , false , onMessage ) ;
2321
24- // valid address: 0
25- client . send ( buf , port , 0 , onMessage ) ;
22+ // valid address: empty string
23+ client . send ( buf , port , '' , onMessage ) ;
2624
27- // valid address: undefined
28- client . send ( buf , port , undefined , onMessage ) ;
25+ // valid address: null
26+ client . send ( buf , port , null , onMessage ) ;
2927
30- // valid address: not provided
31- client . send ( buf , port , onMessage ) ;
28+ // valid address: 0
29+ client . send ( buf , port , 0 , onMessage ) ;
3230
33- const expectedError =
34- / ^ 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 : a d d r e s s m u s t b e a n o n e m p t y s t r i n g o r f a l s y $ / ;
31+ // valid address: undefined
32+ client . send ( buf , port , undefined , onMessage ) ;
33+
34+ // valid address: not provided
35+ client . send ( buf , port , onMessage ) ;
3536
36- // invalid address: object
37- assert . throws ( ( ) => {
38- client . send ( buf , port , [ ] ) ;
39- } , expectedError ) ;
37+ // invalid address: object
38+ assert . throws ( ( ) => {
39+ client . send ( buf , port , [ ] ) ;
40+ } , expectedError ) ;
4041
41- // invalid address: nonzero number
42- assert . throws ( ( ) => {
43- client . send ( buf , port , 1 ) ;
44- } , expectedError ) ;
42+ // invalid address: nonzero number
43+ assert . throws ( ( ) => {
44+ client . send ( buf , port , 1 ) ;
45+ } , expectedError ) ;
4546
46- // invalid address: true
47- assert . throws ( ( ) => {
48- client . send ( buf , port , true ) ;
49- } , expectedError ) ;
47+ // invalid address: true
48+ assert . throws ( ( ) => {
49+ client . send ( buf , port , true ) ;
50+ } , expectedError ) ;
51+ } ) ;
5052
5153client . unref ( ) ;
0 commit comments