Skip to content

Commit d4e029f

Browse files
committed
Update test_chunked_upload.js
Signed-off-by: liranmauda <[email protected]>
1 parent 3e1b2a6 commit d4e029f

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/test/integration_tests/api/s3/test_chunked_upload.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ async function test_put_chunked_object(upload_config) {
122122
dbg.log0('PutObject response:', put_object_response);
123123
assert.ok(put_object_response.ETag);
124124

125-
const get_object_res = await get_object(s3, bucket, key);
126-
assert.equal(get_object_res.body, random_data_buffer.toString());
125+
const get_object_res = await get_object_buffer(s3, bucket, key);
126+
assert.ok(random_data_buffer.equals(get_object_res.body), 'Uploaded and downloaded data differ');
127127
assert.equal(get_object_res.ETag, put_object_response.ETag);
128128

129129
await delete_object(s3, bucket, key);
@@ -155,7 +155,7 @@ async function test_chunked_mpu(mpu_config) {
155155
assert.ok(create_mpu_response.UploadId);
156156

157157
const parts = [];
158-
let original_string = '';
158+
let original_buffer = Buffer.alloc(0);
159159
for (let i = 1; i <= parts_num; i++) {
160160
const random_data_buffer = crypto.randomBytes(size);
161161
const random_data_stream = buffer_utils.buffer_to_read_stream(random_data_buffer);
@@ -171,7 +171,7 @@ async function test_chunked_mpu(mpu_config) {
171171
dbg.log0('MPU upload_part_response:', upload_part_response);
172172
assert.ok(upload_part_response.ETag);
173173
parts.push({ PartNumber: i, ETag: upload_part_response.ETag });
174-
original_string += random_data_buffer.toString();
174+
original_buffer = Buffer.concat([original_buffer, random_data_buffer]);
175175
}
176176

177177
const complete_mpu_input = { Bucket: bucket, Key: key, UploadId: create_mpu_response.UploadId, MultipartUpload: { Parts: parts } };
@@ -180,19 +180,18 @@ async function test_chunked_mpu(mpu_config) {
180180
dbg.log0('MPU complete_mpu_response:', complete_mpu_response);
181181
assert.ok(complete_mpu_response.ETag);
182182

183-
const get_object_res = await get_object(s3, bucket, key);
184-
assert.equal(get_object_res.body, original_string);
183+
const get_object_res = await get_object_buffer(s3, bucket, key);
184+
assert.ok(original_buffer.equals(get_object_res.body), 'Uploaded and downloaded data differ');
185185

186186
await delete_object(s3, bucket, key);
187187
}
188188

189189
/**
190190
* validate_request_headers - Middleware to log and validate request headers
191191
* @param {S3Client} s3
192-
* @returns {Promise<Object>} - Returns the request headers after the middleware is executed
192+
* @returns {Promise<void>} - Returns the S3 client with the middleware added
193193
*/
194194
async function validate_request_headers(s3) {
195-
let request_headers;
196195
s3.middlewareStack.add(
197196
(next, context) => async args => {
198197
const command = context.commandName;
@@ -217,22 +216,21 @@ async function validate_request_headers(s3) {
217216
priority: 'high',
218217
}
219218
);
220-
return request_headers;
221219
}
222220

223221
/**
224-
* get_object - Get an object from S3 bucket
222+
* get_object_buffer - Retrieve an object from S3 bucket and return its content as a Buffer along with its ETag
225223
* @param {S3Client} s3
226224
* @param {String} bucket
227225
* @param {String} key
228-
* @returns {Promise<{body: String, ETag: String}>} - The content of the object as a string
226+
* @returns {Promise<{body: Buffer, ETag: String}>} - The content of the object as a Buffer and its ETag
229227
*/
230-
async function get_object(s3, bucket, key) {
228+
async function get_object_buffer(s3, bucket, key) {
231229
const get_object_command = new GetObjectCommand({ Bucket: bucket, Key: key });
232230
const get_object_response = await s3.send(get_object_command);
233231
dbg.log0('GetObject response:', _.omit(get_object_response, ['Body']));
234-
const body = await get_object_response.Body.transformToString();
235-
return { body, ETag: get_object_response.ETag };
232+
const body = await get_object_response.Body.transformToByteArray();
233+
return { body: Buffer.from(body), ETag: get_object_response.ETag };
236234
}
237235

238236
/**

0 commit comments

Comments
 (0)