Skip to content

Commit d2b6b66

Browse files
TrottFishrock123
authored andcommitted
test: refactor test-net-pipe-connect-errors
* var -> const * try/catch -> assert.throws() * assert.ok(fail) -> common.fail() * assert.equal() -> assert.strictEqual() * replace `exit` handler with `common.mustCall()` PR-URL: #8473 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 92acff8 commit d2b6b66

File tree

1 file changed

+17
-29
lines changed

1 file changed

+17
-29
lines changed
Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
'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');
97

108
// Test if ENOTSOCK is fired when trying to connect to a file which is not
119
// a socket.
@@ -28,8 +26,7 @@ if (common.isWindows) {
2826
try {
2927
fs.unlinkSync(emptyTxt);
3028
} catch (e) {
31-
if (e.code != 'ENOENT')
32-
throw e;
29+
assert.strictEqual(e.code, 'ENOENT');
3330
}
3431
}
3532
process.on('exit', cleanup);
@@ -38,7 +35,7 @@ if (common.isWindows) {
3835
}
3936

4037
var notSocketClient = net.createConnection(emptyTxt, function() {
41-
assert.ok(false);
38+
common.fail('connection callback should not run');
4239
});
4340

4441
notSocketClient.on('error', common.mustCall(function(err) {
@@ -49,39 +46,30 @@ notSocketClient.on('error', common.mustCall(function(err) {
4946

5047
// Trying to connect to not-existing socket should result in ENOENT error
5148
var noEntSocketClient = net.createConnection('no-ent-file', function() {
52-
assert.ok(false);
49+
common.fail('connection to non-existent socket, callback should not run');
5350
});
5451

5552
noEntSocketClient.on('error', common.mustCall(function(err) {
56-
assert.equal(err.code, 'ENOENT');
53+
assert.strictEqual(err.code, 'ENOENT');
5754
}));
5855

5956

6057
// On Windows or when running as root, a chmod has no effect on named pipes
6158
if (!common.isWindows && process.getuid() !== 0) {
6259
// 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');
6562
});
66-
accessServer.listen(common.PIPE, function() {
63+
accessServer.listen(common.PIPE, common.mustCall(function() {
6764
fs.chmodSync(common.PIPE, 0);
6865

6966
var accessClient = net.createConnection(common.PIPE, function() {
70-
assert.ok(false);
67+
common.fail('connection should get EACCES, callback should not run');
7168
});
7269

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');
7672
accessServer.close();
77-
});
78-
});
73+
}));
74+
}));
7975
}
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

Comments
 (0)