Skip to content

Commit

Permalink
test: refactor test to use the fixtures module
Browse files Browse the repository at this point in the history
PR-URL: #15934
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
  • Loading branch information
stropitek authored and MylesBorins committed Oct 11, 2017
1 parent dd23140 commit 633772a
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions test/parallel/test-http2-serve-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,32 @@
'use strict';

const common = require('../common');
const fixtures = require('../common/fixtures');

if (!common.hasCrypto)
common.skip('missing crypto');

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 });
Expand Down

0 comments on commit 633772a

Please sign in to comment.