-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the function around so it can be tested and add a regression test. As a policy vs. mechanism thing, change the control flow to handle exceptions at the call site, not inside the download function. PR-URL: #837 Reviewed-By: Rod Vagg <rod@vagg.org>
- Loading branch information
1 parent
89692c9
commit b3ad434
Showing
2 changed files
with
94 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict' | ||
|
||
var http = require('http') | ||
var test = require('tape') | ||
var install = require('../lib/install') | ||
|
||
test('download over http', function (t) { | ||
t.plan(2) | ||
|
||
var server = http.createServer(function (req, res) { | ||
t.strictEqual(req.headers['user-agent'], | ||
'node-gyp v42 (node ' + process.version + ')') | ||
res.end('ok') | ||
server.close() | ||
}) | ||
|
||
var host = '127.0.0.1' | ||
server.listen(0, host, function () { | ||
var port = this.address().port | ||
var gyp = { | ||
opts: {}, | ||
version: '42', | ||
} | ||
var url = 'http://' + host + ':' + port | ||
var req = install.test.download(gyp, {}, url) | ||
req.on('response', function (res) { | ||
var body = '' | ||
res.setEncoding('utf8') | ||
res.on('data', function(data) { | ||
body += data | ||
}) | ||
res.on('end', function() { | ||
t.strictEqual(body, 'ok') | ||
}) | ||
}) | ||
}) | ||
}) |