-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
test-agentOptions.js
47 lines (41 loc) 路 1.12 KB
/
test-agentOptions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict'
var request = require('../index')
, http = require('http')
, server = require('./server')
, tape = require('tape')
var s = server.createServer(function (req, resp) {
resp.statusCode = 200
resp.end('')
})
tape('setup', function(t) {
s.listen(s.port, function() {
t.end()
})
})
tape('without agentOptions should use global agent', function(t) {
var r = request(s.url, function(/*err, res, body*/) {
// TODO: figure out why err.code === 'ECONNREFUSED' on Travis?
//if (err) console.log(err)
//t.equal(err, null)
t.deepEqual(r.agent, http.globalAgent)
t.equal(Object.keys(r.pool).length, 0)
t.end()
})
})
tape('with agentOptions should apply to new agent in pool', function(t) {
var r = request(s.url, {
agentOptions: { foo: 'bar' }
}, function(/*err, res, body*/) {
// TODO: figure out why err.code === 'ECONNREFUSED' on Travis?
//if (err) console.log(err)
//t.equal(err, null)
t.equal(r.agent.options.foo, 'bar')
t.equal(Object.keys(r.pool).length, 1)
t.end()
})
})
tape('cleanup', function(t) {
s.close(function() {
t.end()
})
})