Skip to content

Commit

Permalink
test: refactor test-tls-two-cas-one-string
Browse files Browse the repository at this point in the history
* 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: #13896
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
  • Loading branch information
Trott authored and addaleax committed Jul 18, 2017
1 parent 8fe7722 commit 949d1b1
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions test/parallel/test-tls-two-cas-one-string.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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)));

0 comments on commit 949d1b1

Please sign in to comment.