Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/data/external/AwsClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ class AwsClient {
completeObjData.eTag = completeMpuRes.ETag
.substring(1, completeMpuRes.ETag.length - 1);
completeObjData.dataStoreVersionId = completeMpuRes.VersionId;
completeObjData.contentLength = objHeaders.ContentLength;
completeObjData.contentLength =
Number.parseInt(objHeaders.ContentLength, 10);
return callback(null, completeObjData);
});
});
Expand Down
3 changes: 2 additions & 1 deletion lib/data/external/GcpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ class GcpClient extends AwsClient {
// remove quotes from eTag because they're added later
completeObjData.eTag = removeQuotes(completeMpuRes.ETag);
completeObjData.dataStoreVersionId = completeMpuRes.VersionId;
completeObjData.contentLength = completeMpuRes.ContentLength;
completeObjData.contentLength =
Number.parseInt(completeMpuRes.ContentLength, 10);
return callback(null, completeObjData);
});
}
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/DummyService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const uuid = require('uuid/v4');

class DummyService {
headObject(params, callback) {
const retObj = {
ContentLength: `${1024 * 1024 * 1024}`,
};
return callback(null, retObj);
}
completeMultipartUpload(params, callback) {
const retObj = {
Bucket: params.Bucket,
Key: params.Key,
VersionId: uuid().replace(/-/g, ''),
ETag: `"${uuid().replace(/-/g, '')}"`,
ContentLength: `${1024 * 1024 * 1024}`,
};
return callback(null, retObj);
}
// To-Do: add tests for other methods
}

module.exports = DummyService;
74 changes: 74 additions & 0 deletions tests/unit/multipleBackend/ExternalBackendClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const assert = require('assert');
const AwsClient = require('../../../lib/data/external/AwsClient');
const GcpClient = require('../../../lib/data/external/GcpClient');
const DummyService = require('../DummyService');
const { DummyRequestLogger } = require('../helpers');

const backendClients = [
{
Class: AwsClient,
name: 'AwsClient',
config: {
s3Params: {},
bucketName: 'awsTestBucketName',
dataStoreName: 'awsDataStore',
serverSideEncryption: false,
type: 'aws',
},
},
{
Class: GcpClient,
name: 'GcpClient',
config: {
s3Params: {},
bucketName: 'gcpTestBucketName',
mpuBucket: 'gcpTestMpuBucketName',
dataStoreName: 'gcpDataStore',
type: 'gcp',
},
},
];

backendClients.forEach(backend => {
let testClient;

before(() => {
testClient = new backend.Class(backend.config);
testClient._client = new DummyService(backend.config);
});

describe(`${backend.name} completeMPU:`, () => {
it('should return correctly typed mpu results', done => {
const jsonList = {
Part: [
{
PartNumber: [1],
ETag: ['testpart0001etag'],
},
{
PartNumber: [2],
ETag: ['testpart0002etag'],
},
{
PartNumber: [3],
ETag: ['testpart0003etag'],
},
],
};
const key = 'externalBackendTestKey';
const bucketName = 'externalBackendTestBucket';
const uploadId = 'externalBackendTestUploadId';
const log = new DummyRequestLogger();

testClient.completeMPU(jsonList, null, key, uploadId, bucketName,
log, (err, res) => {
assert.strictEqual(typeof res.key, 'string');
assert.strictEqual(typeof res.eTag, 'string');
assert.strictEqual(typeof res.dataStoreVersionId, 'string');
assert.strictEqual(typeof res.contentLength, 'number');
return done();
});
});
});
// To-Do: test the other external client methods
});