Browse Source

test: refactor test to use the fixtures module

PR-URL: https://github.com/nodejs/node/pull/15934
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
v9.x-staging
Daniel Kostro 7 years ago
committed by Ruben Bridgewater
parent
commit
96221c2471
No known key found for this signature in database GPG Key ID: F07496B3EB3C1762
  1. 18
      test/parallel/test-http2-serve-file.js

18
test/parallel/test-http2-serve-file.js

@ -1,6 +1,7 @@
'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
if (!common.hasCrypto)
common.skip('missing crypto');
@ -8,31 +9,24 @@ if (!common.hasCrypto)
const assert = require('assert');
const http2 = require('http2');
const fs = require('fs');
const path = require('path');
const tls = require('tls');
const ajs_data = fs.readFileSync(path.resolve(common.fixturesDir, 'a.js'),
'utf8');
const ajs_data = fixtures.readSync('a.js', 'utf8');
const {
HTTP2_HEADER_PATH,
HTTP2_HEADER_STATUS
} = http2.constants;
function loadKey(keyname) {
return fs.readFileSync(
path.join(common.fixturesDir, 'keys', keyname), 'binary');
}
const key = loadKey('agent8-key.pem');
const cert = loadKey('agent8-cert.pem');
const ca = loadKey('fake-startcom-root-cert.pem');
const key = fixtures.readKey('agent8-key.pem', 'binary');
const cert = fixtures.readKey('agent8-cert.pem', 'binary');
const ca = fixtures.readKey('fake-startcom-root-cert.pem', 'binary');
const server = http2.createSecureServer({ key, cert });
server.on('stream', (stream, headers) => {
const name = headers[HTTP2_HEADER_PATH].slice(1);
const file = path.resolve(common.fixturesDir, name);
const file = fixtures.path(name);
fs.stat(file, (err, stat) => {
if (err != null || stat.isDirectory()) {
stream.respond({ [HTTP2_HEADER_STATUS]: 404 });

Loading…
Cancel
Save