1
1
'use strict' ;
2
- var common = require ( '../common' ) ;
3
- var fs = require ( 'fs' ) ;
4
- var net = require ( 'net' ) ;
5
- var path = require ( 'path' ) ;
6
- var assert = require ( 'assert' ) ;
7
-
8
- var accessErrorFired = false ;
2
+ const common = require ( '../common' ) ;
3
+ const fs = require ( 'fs' ) ;
4
+ const net = require ( 'net' ) ;
5
+ const path = require ( 'path' ) ;
6
+ const assert = require ( 'assert' ) ;
9
7
10
8
// Test if ENOTSOCK is fired when trying to connect to a file which is not
11
9
// a socket.
@@ -28,8 +26,7 @@ if (common.isWindows) {
28
26
try {
29
27
fs . unlinkSync ( emptyTxt ) ;
30
28
} catch ( e ) {
31
- if ( e . code != 'ENOENT' )
32
- throw e ;
29
+ assert . strictEqual ( e . code , 'ENOENT' ) ;
33
30
}
34
31
}
35
32
process . on ( 'exit' , cleanup ) ;
@@ -38,7 +35,7 @@ if (common.isWindows) {
38
35
}
39
36
40
37
var notSocketClient = net . createConnection ( emptyTxt , function ( ) {
41
- assert . ok ( false ) ;
38
+ common . fail ( 'connection callback should not run' ) ;
42
39
} ) ;
43
40
44
41
notSocketClient . on ( 'error' , common . mustCall ( function ( err ) {
@@ -49,39 +46,30 @@ notSocketClient.on('error', common.mustCall(function(err) {
49
46
50
47
// Trying to connect to not-existing socket should result in ENOENT error
51
48
var noEntSocketClient = net . createConnection ( 'no-ent-file' , function ( ) {
52
- assert . ok ( false ) ;
49
+ common . fail ( 'connection to non-existent socket, callback should not run' ) ;
53
50
} ) ;
54
51
55
52
noEntSocketClient . on ( 'error' , common . mustCall ( function ( err ) {
56
- assert . equal ( err . code , 'ENOENT' ) ;
53
+ assert . strictEqual ( err . code , 'ENOENT' ) ;
57
54
} ) ) ;
58
55
59
56
60
57
// On Windows or when running as root, a chmod has no effect on named pipes
61
58
if ( ! common . isWindows && process . getuid ( ) !== 0 ) {
62
59
// Trying to connect to a socket one has no access to should result in EACCES
63
- var accessServer = net . createServer ( function ( ) {
64
- assert . ok ( false ) ;
60
+ const accessServer = net . createServer ( function ( ) {
61
+ common . fail ( 'server callback should not run' ) ;
65
62
} ) ;
66
- accessServer . listen ( common . PIPE , function ( ) {
63
+ accessServer . listen ( common . PIPE , common . mustCall ( function ( ) {
67
64
fs . chmodSync ( common . PIPE , 0 ) ;
68
65
69
66
var accessClient = net . createConnection ( common . PIPE , function ( ) {
70
- assert . ok ( false ) ;
67
+ common . fail ( 'connection should get EACCES, callback should not run' ) ;
71
68
} ) ;
72
69
73
- accessClient . on ( 'error' , function ( err ) {
74
- assert . equal ( err . code , 'EACCES' ) ;
75
- accessErrorFired = true ;
70
+ accessClient . on ( 'error' , common . mustCall ( function ( err ) {
71
+ assert . strictEqual ( err . code , 'EACCES' ) ;
76
72
accessServer . close ( ) ;
77
- } ) ;
78
- } ) ;
73
+ } ) ) ;
74
+ } ) ) ;
79
75
}
80
-
81
-
82
- // Assert that all error events were fired
83
- process . on ( 'exit' , function ( ) {
84
- if ( ! common . isWindows && process . getuid ( ) !== 0 ) {
85
- assert . ok ( accessErrorFired ) ;
86
- }
87
- } ) ;
0 commit comments