Skip to content

Commit 949d1b1

Browse files
Trottaddaleax
authored andcommitted
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: #13896 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]>
1 parent 8fe7722 commit 949d1b1

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed
+12-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
'use strict';
2-
32
const common = require('../common');
3+
44
if (!common.hasCrypto) {
55
common.skip('missing crypto');
66
return;
77
}
88

9-
const tls = require('tls');
109
const fs = require('fs');
10+
const tls = require('tls');
11+
12+
const keydir = `${common.fixturesDir}/keys`;
1113

12-
const ca1 =
13-
fs.readFileSync(`${common.fixturesDir}/keys/ca1-cert.pem`, 'utf8');
14-
const ca2 =
15-
fs.readFileSync(`${common.fixturesDir}/keys/ca2-cert.pem`, 'utf8');
16-
const cert =
17-
fs.readFileSync(`${common.fixturesDir}/keys/agent3-cert.pem`, 'utf8');
18-
const key =
19-
fs.readFileSync(`${common.fixturesDir}/keys/agent3-key.pem`, 'utf8');
14+
const ca1 = fs.readFileSync(`${keydir}/ca1-cert.pem`, 'utf8');
15+
const ca2 = fs.readFileSync(`${keydir}/ca2-cert.pem`, 'utf8');
16+
const cert = fs.readFileSync(`${keydir}/agent3-cert.pem`, 'utf8');
17+
const key = fs.readFileSync(`${keydir}/agent3-key.pem`, 'utf8');
2018

2119
function test(ca, next) {
2220
const server = tls.createServer({ ca, cert, key }, function(conn) {
@@ -31,9 +29,11 @@ function test(ca, next) {
3129
tls.connect({ servername: 'agent3', host, port: this.address().port, ca });
3230
});
3331

34-
server.once('close', next);
32+
if (next) {
33+
server.once('close', next);
34+
}
3535
}
3636

3737
const array = [ca1, ca2];
3838
const string = `${ca1}\n${ca2}`;
39-
test(array, () => test(string, common.noop));
39+
test(array, common.mustCall(() => test(string)));

0 commit comments

Comments
 (0)