From 62947916b6227b0a41f87b0d49e26586704e8e42 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 23 Jun 2017 22:55:33 -0700 Subject: [PATCH] test: refactor test-tls-two-cas-one-string * order require() statements per test writing guide * add keydir variable to make readFileSync() calls more readable * make `next` argument to test() optional * use common.mustCall() to guarantee second test runs PR-URL: https://github.com/nodejs/node/pull/13896 Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Daniel Bevenius Reviewed-By: James M Snell Reviewed-By: Yuta Hiroto --- test/parallel/test-tls-two-cas-one-string.js | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/parallel/test-tls-two-cas-one-string.js b/test/parallel/test-tls-two-cas-one-string.js index 35d0a01f05..3f948b86a5 100644 --- a/test/parallel/test-tls-two-cas-one-string.js +++ b/test/parallel/test-tls-two-cas-one-string.js @@ -1,22 +1,20 @@ 'use strict'; - const common = require('../common'); + if (!common.hasCrypto) { common.skip('missing crypto'); return; } -const tls = require('tls'); const fs = require('fs'); +const tls = require('tls'); + +const keydir = `${common.fixturesDir}/keys`; -const ca1 = - fs.readFileSync(`${common.fixturesDir}/keys/ca1-cert.pem`, 'utf8'); -const ca2 = - fs.readFileSync(`${common.fixturesDir}/keys/ca2-cert.pem`, 'utf8'); -const cert = - fs.readFileSync(`${common.fixturesDir}/keys/agent3-cert.pem`, 'utf8'); -const key = - fs.readFileSync(`${common.fixturesDir}/keys/agent3-key.pem`, 'utf8'); +const ca1 = fs.readFileSync(`${keydir}/ca1-cert.pem`, 'utf8'); +const ca2 = fs.readFileSync(`${keydir}/ca2-cert.pem`, 'utf8'); +const cert = fs.readFileSync(`${keydir}/agent3-cert.pem`, 'utf8'); +const key = fs.readFileSync(`${keydir}/agent3-key.pem`, 'utf8'); function test(ca, next) { const server = tls.createServer({ ca, cert, key }, function(conn) { @@ -31,9 +29,11 @@ function test(ca, next) { tls.connect({ servername: 'agent3', host, port: this.address().port, ca }); }); - server.once('close', next); + if (next) { + server.once('close', next); + } } const array = [ca1, ca2]; const string = `${ca1}\n${ca2}`; -test(array, () => test(string, common.noop)); +test(array, common.mustCall(() => test(string)));