Skip to content

Commit c83d71e

Browse files
committed
Add test coverage for listAllObjects
1 parent e90848e commit c83d71e

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/unit/lib/s3-test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,50 @@ describe('s3', function() {
284284
assert.equal(headParams.Key, expectedKey);
285285
});
286286
});
287+
288+
it('correctly pages s3#listObjects calls when necessary', function() {
289+
290+
var revisions = [
291+
{ Key: 'test.html:111', LastModified: new Date('September 27, 2015 01:00:00'), ETag: '111' },
292+
{ Key: 'test.html:222', LastModified: new Date('September 27, 2015 02:00:00') , ETag: '222' },
293+
{ Key: 'test.html:333', LastModified: new Date('September 27, 2015 03:00:00') , ETag: '333' },
294+
{ Key: 'test.html:444', LastModified: new Date('September 27, 2015 04:00:00') , ETag: '444' },
295+
{ Key: 'test.html:555', LastModified: new Date('September 27, 2015 05:00:00') , ETag: '555' },
296+
{ Key: 'test.html:666', LastModified: new Date('September 27, 2015 06:00:00') , ETag: '666' },
297+
{ Key: 'test.html:777', LastModified: new Date('September 27, 2015 07:00:00') , ETag: '777' },
298+
{ Key: 'test.html:888', LastModified: new Date('September 27, 2015 08:00:00') , ETag: '888' },
299+
{ Key: 'test.html:999', LastModified: new Date('September 27, 2015 09:00:00') , ETag: '999' },
300+
{ Key: 'test.html:000', LastModified: new Date('September 27, 2015 10:00:00') , ETag: '000' },
301+
];
302+
303+
var resultsPerPage = 4;
304+
var listObjectCalls = [];
305+
306+
s3Client.listObjects = function(params, cb) {
307+
listObjectCalls.push(params.Marker);
308+
var offset = 0;
309+
offset = revisions.map(function(revision) {
310+
return revision.Key;
311+
}).indexOf(params.Marker) + 1;
312+
var lastResult = offset + resultsPerPage;
313+
314+
cb(undefined, {
315+
Contents: revisions.slice(offset, lastResult),
316+
IsTruncated: lastResult < revisions.length,
317+
});
318+
};
319+
320+
var promise = subject.fetchRevisions(options);
321+
322+
return assert.isFulfilled(promise)
323+
.then(function(revisionsData) {
324+
assert.equal(revisionsData.length, revisions.length, 'All revisions are available');
325+
assert.equal(listObjectCalls.length, 3, 'listObjects was called 3 times');
326+
assert.equal(listObjectCalls[0], undefined, 'the first call to listObjects had the expected marker');
327+
assert.equal(listObjectCalls[1], 'test.html:444', 'the second call to listObjects had the expected marker');
328+
assert.equal(listObjectCalls[2], 'test.html:888', 'the third call to listObjects had the expected marker');
329+
});
330+
});
287331
});
288332

289333
describe('#activate', function() {

0 commit comments

Comments
 (0)