From bf0a274da312a8a646293ddf1837d1b467e68422 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 9 Sep 2016 15:57:51 -0700 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/8473 Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Sakthipriyan Vairamani Reviewed-By: James M Snell --- test/parallel/test-net-pipe-connect-errors.js | 46 +++++++------------ 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/test/parallel/test-net-pipe-connect-errors.js b/test/parallel/test-net-pipe-connect-errors.js index 1c25c47512020d..3e00befc341682 100644 --- a/test/parallel/test-net-pipe-connect-errors.js +++ b/test/parallel/test-net-pipe-connect-errors.js @@ -1,11 +1,9 @@ 'use strict'; -var common = require('../common'); -var fs = require('fs'); -var net = require('net'); -var path = require('path'); -var assert = require('assert'); - -var accessErrorFired = false; +const common = require('../common'); +const fs = require('fs'); +const net = require('net'); +const path = require('path'); +const assert = require('assert'); // Test if ENOTSOCK is fired when trying to connect to a file which is not // a socket. @@ -28,8 +26,7 @@ if (common.isWindows) { try { fs.unlinkSync(emptyTxt); } catch (e) { - if (e.code != 'ENOENT') - throw e; + assert.strictEqual(e.code, 'ENOENT'); } } process.on('exit', cleanup); @@ -38,7 +35,7 @@ if (common.isWindows) { } var notSocketClient = net.createConnection(emptyTxt, function() { - assert.ok(false); + common.fail('connection callback should not run'); }); notSocketClient.on('error', common.mustCall(function(err) { @@ -49,39 +46,30 @@ notSocketClient.on('error', common.mustCall(function(err) { // Trying to connect to not-existing socket should result in ENOENT error var noEntSocketClient = net.createConnection('no-ent-file', function() { - assert.ok(false); + common.fail('connection to non-existent socket, callback should not run'); }); noEntSocketClient.on('error', common.mustCall(function(err) { - assert.equal(err.code, 'ENOENT'); + assert.strictEqual(err.code, 'ENOENT'); })); // On Windows or when running as root, a chmod has no effect on named pipes if (!common.isWindows && process.getuid() !== 0) { // Trying to connect to a socket one has no access to should result in EACCES - var accessServer = net.createServer(function() { - assert.ok(false); + const accessServer = net.createServer(function() { + common.fail('server callback should not run'); }); - accessServer.listen(common.PIPE, function() { + accessServer.listen(common.PIPE, common.mustCall(function() { fs.chmodSync(common.PIPE, 0); var accessClient = net.createConnection(common.PIPE, function() { - assert.ok(false); + common.fail('connection should get EACCES, callback should not run'); }); - accessClient.on('error', function(err) { - assert.equal(err.code, 'EACCES'); - accessErrorFired = true; + accessClient.on('error', common.mustCall(function(err) { + assert.strictEqual(err.code, 'EACCES'); accessServer.close(); - }); - }); + })); + })); } - - -// Assert that all error events were fired -process.on('exit', function() { - if (!common.isWindows && process.getuid() !== 0) { - assert.ok(accessErrorFired); - } -});