Skip to content

Commit 23c12d3

Browse files
committed
test cases for listParts method
1 parent 7f94359 commit 23c12d3

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/unit/storage/data/external/GcpService.spec.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,4 +750,49 @@ describe('GcpService mpu helper behavior', () => {
750750
});
751751
});
752752
});
753+
754+
describe('listParts', () => {
755+
it('should list parts', done => {
756+
const sendSpy = jest.spyOn(client, 'send')
757+
.mockResolvedValue({ Contents: [] });
758+
759+
const params = {
760+
Bucket: 'b',
761+
Key: 'obj',
762+
UploadId: 'upload',
763+
PartNumberMarker: 3,
764+
MaxParts: 10,
765+
};
766+
767+
client.listParts(params, (err, res) => {
768+
assert.ifError(err);
769+
assert(res);
770+
expect(sendSpy).toHaveBeenCalledTimes(1);
771+
const [command] = sendSpy.mock.calls[0];
772+
expect(command).toBeInstanceOf(ListObjectsCommand);
773+
expect(command.input).toEqual({
774+
Bucket: params.Bucket,
775+
Prefix: createMpuKey(params.Key, params.UploadId, 'parts'),
776+
Marker: createMpuKey(params.Key, params.UploadId,
777+
params.PartNumberMarker, 'parts'),
778+
MaxKeys: params.MaxParts,
779+
});
780+
done();
781+
});
782+
});
783+
784+
it('should return error when command rejects', done => {
785+
const listObjectsError = new Error('send(ListObjectsCommand) failed');
786+
jest.spyOn(client, 'send').mockRejectedValue(listObjectsError);
787+
788+
client.listParts({
789+
Bucket: 'b',
790+
Key: 'obj',
791+
UploadId: 'upload',
792+
}, err => {
793+
assert.strictEqual(err, listObjectsError);
794+
done();
795+
});
796+
});
797+
});
753798
});

0 commit comments

Comments
 (0)