Skip to content

Commit

Permalink
add test case for clone function
Browse files Browse the repository at this point in the history
  • Loading branch information
Emman committed Nov 9, 2020
1 parent f76272e commit 88aa12e
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/strategies.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var request = require('../');
const http = require('http');
var t = require('chai').assert;

describe('RetryStrategies', function () {
Expand Down Expand Up @@ -43,6 +44,38 @@ describe('RetryStrategies', function () {
});
});

it('should not clone `options.agent`', function (done) {
const agent = new http.Agent({ keepAlive: true });
const cloneable = { a: true };
var strategy = function (err, response, body, options) {
options.url = 'http://www.filltext.com/?rows=1&err=200'; //overwrite url to return 200
t.strictEqual(agent, options.agent);
t.deepEqual(cloneable, options.cloneable);
t.notEqual(cloneable, options.cloneable);
return {
mustRetry: true,
options: options,
};
};

request({
url: 'http://www.filltext.com/?rows=1&err=500', // returns a 500 status
maxAttempts: 3,
agent: agent,
retryDelay: 100,
cloneable: cloneable,
retryStrategy: strategy
}, function(err, response, body) {
if(err) done(err);

t.strictEqual(200, response.statusCode);
t.strictEqual(agent, this.options.agent);
t.deepEqual(cloneable, this.options.cloneable);
t.notEqual(cloneable, this.options.cloneable);
done();
});
});

it('should not overwrite `options` object if strategy did not returned it', function (done) {
var strategy = function (err, response, body, options) {
options.url = 'http://www.filltext.com/?rows=1&err=200'; //overwrite url to return 200
Expand Down

0 comments on commit 88aa12e

Please sign in to comment.