Skip to content

Commit

Permalink
test: refactor test-pipe-file-to-http
Browse files Browse the repository at this point in the history
Changing var defs to const/let, changing assert.equal to
assert.strictEqual. Wrapping functions called once with
common.mustCall

PR-URL: #10054
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
Josh Mays authored and evanlucas committed Jan 4, 2017
1 parent 1b9f548 commit 4bfd9c0
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions test/parallel/test-pipe-file-to-http.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var fs = require('fs');
var http = require('http');
var path = require('path');
var cp = require('child_process');
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const http = require('http');
const path = require('path');
const cp = require('child_process');

common.refreshTmpDir();

var filename = path.join(common.tmpDir || '/tmp', 'big');
var clientReqComplete = false;
var count = 0;
const filename = path.join(common.tmpDir || '/tmp', 'big');
let count = 0;

var server = http.createServer(function(req, res) {
var timeoutId;
assert.equal('POST', req.method);
const server = http.createServer(function(req, res) {
let timeoutId;
assert.strictEqual('POST', req.method);
req.pause();

setTimeout(function() {
Expand All @@ -36,27 +35,26 @@ var server = http.createServer(function(req, res) {
server.listen(0);

server.on('listening', function() {
var cmd = common.ddCommand(filename, 10240);
const cmd = common.ddCommand(filename, 10240);

cp.exec(cmd, function(err, stdout, stderr) {
cp.exec(cmd, function(err) {
if (err) throw err;
makeRequest();
});
});

function makeRequest() {
var req = http.request({
const req = http.request({
port: server.address().port,
path: '/',
method: 'POST'
});

var s = fs.ReadStream(filename);
const s = fs.ReadStream(filename);
s.pipe(req);
s.on('close', function(err) {
if (err) throw err;
clientReqComplete = true;
});
s.on('close', common.mustCall((err) => {
assert.ifError(err);
}));

req.on('response', function(res) {
res.resume();
Expand All @@ -67,6 +65,5 @@ function makeRequest() {
}

process.on('exit', function() {
assert.equal(1024 * 10240, count);
assert.ok(clientReqComplete);
assert.strictEqual(1024 * 10240, count);
});

0 comments on commit 4bfd9c0

Please sign in to comment.