diff options
author | Rich Trott <rtrott@gmail.com> | 2016-09-09 15:57:51 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2016-09-12 20:45:33 -0700 |
commit | bf0a274da312a8a646293ddf1837d1b467e68422 (patch) | |
tree | 0ffb515411026c3d5d5b8aaeec1bd4cb3974f56c /test/parallel/test-net-pipe-connect-errors.js | |
parent | f1629e78c793a3586f2d034ce76bae99b1df91ac (diff) | |
download | android-node-v8-bf0a274da312a8a646293ddf1837d1b467e68422.tar.gz android-node-v8-bf0a274da312a8a646293ddf1837d1b467e68422.tar.bz2 android-node-v8-bf0a274da312a8a646293ddf1837d1b467e68422.zip |
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 <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-net-pipe-connect-errors.js')
-rw-r--r-- | test/parallel/test-net-pipe-connect-errors.js | 46 |
1 files 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 1c25c47512..3e00befc34 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); - } -}); |