Skip to content

Commit 88aa12e

Browse files
author
Emman
committed
add test case for clone function
1 parent f76272e commit 88aa12e

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

test/strategies.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var request = require('../');
4+
const http = require('http');
45
var t = require('chai').assert;
56

67
describe('RetryStrategies', function () {
@@ -43,6 +44,38 @@ describe('RetryStrategies', function () {
4344
});
4445
});
4546

47+
it('should not clone `options.agent`', function (done) {
48+
const agent = new http.Agent({ keepAlive: true });
49+
const cloneable = { a: true };
50+
var strategy = function (err, response, body, options) {
51+
options.url = 'http://www.filltext.com/?rows=1&err=200'; //overwrite url to return 200
52+
t.strictEqual(agent, options.agent);
53+
t.deepEqual(cloneable, options.cloneable);
54+
t.notEqual(cloneable, options.cloneable);
55+
return {
56+
mustRetry: true,
57+
options: options,
58+
};
59+
};
60+
61+
request({
62+
url: 'http://www.filltext.com/?rows=1&err=500', // returns a 500 status
63+
maxAttempts: 3,
64+
agent: agent,
65+
retryDelay: 100,
66+
cloneable: cloneable,
67+
retryStrategy: strategy
68+
}, function(err, response, body) {
69+
if(err) done(err);
70+
71+
t.strictEqual(200, response.statusCode);
72+
t.strictEqual(agent, this.options.agent);
73+
t.deepEqual(cloneable, this.options.cloneable);
74+
t.notEqual(cloneable, this.options.cloneable);
75+
done();
76+
});
77+
});
78+
4679
it('should not overwrite `options` object if strategy did not returned it', function (done) {
4780
var strategy = function (err, response, body, options) {
4881
options.url = 'http://www.filltext.com/?rows=1&err=200'; //overwrite url to return 200

0 commit comments

Comments
 (0)