Skip to content

Commit 95197ed

Browse files
committed
test: add checkMethods function for Certificate
This commit adds a checkMethods function so that it can be reused to avoid duplicating the same code for instance methods, and static methods of the Certificate object. PR-URL: #20224 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent c521a20 commit 95197ed

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

test/parallel/test-crypto-certificate.js

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ const spkacValid = fixtures.readSync('spkac.valid');
3434
const spkacFail = fixtures.readSync('spkac.fail');
3535
const spkacPem = fixtures.readSync('spkac.pem');
3636

37-
{
38-
// Test instance methods
39-
const certificate = new Certificate();
37+
function checkMethods(certificate) {
4038

4139
assert.strictEqual(certificate.verifySpkac(spkacValid), true);
4240
assert.strictEqual(certificate.verifySpkac(spkacFail), false);
@@ -55,21 +53,13 @@ const spkacPem = fixtures.readSync('spkac.pem');
5553
}
5654

5755
{
58-
// Test static methods
59-
assert.strictEqual(Certificate.verifySpkac(spkacValid), true);
60-
assert.strictEqual(Certificate.verifySpkac(spkacFail), false);
61-
62-
assert.strictEqual(
63-
stripLineEndings(Certificate.exportPublicKey(spkacValid).toString('utf8')),
64-
stripLineEndings(spkacPem.toString('utf8'))
65-
);
66-
assert.strictEqual(Certificate.exportPublicKey(spkacFail), '');
56+
// Test instance methods
57+
checkMethods(new Certificate());
58+
}
6759

68-
assert.strictEqual(
69-
Certificate.exportChallenge(spkacValid).toString('utf8'),
70-
'fb9ab814-6677-42a4-a60c-f905d1a6924d'
71-
);
72-
assert.strictEqual(Certificate.exportChallenge(spkacFail), '');
60+
{
61+
// Test static methods
62+
checkMethods(Certificate);
7363
}
7464

7565
function stripLineEndings(obj) {

0 commit comments

Comments
 (0)