Skip to content

Commit eb2ace2

Browse files
committed
object related functional tests adaptation due to aws-sdk migration
1 parent 0ce70fd commit eb2ace2

51 files changed

Lines changed: 5345 additions & 4865 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
"@aws-sdk/client-s3": "^3.908.0",
2323
"@aws-sdk/credential-providers": "^3.864.0",
2424
"@aws-sdk/middleware-retry": "^3.374.0",
25+
"@aws-sdk/s3-request-presigner": "^3.901.0",
2526
"@azure/storage-blob": "^12.28.0",
2627
"@hapi/joi": "^17.1.1",
28+
"@smithy/node-http-handler": "^3.0.0",
2729
"arsenal": "git+https://github.com/scality/Arsenal#8.2.35",
2830
"async": "2.6.4",
2931
"bucketclient": "scality/bucketclient#8.2.7",

tests/functional/aws-node-sdk/lib/utility/checkError.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ const assert = require('assert');
22

33
function checkError(err, code, statusCode) {
44
assert(err, 'Expected error but found none');
5-
assert.strictEqual(err.code, code);
6-
assert.strictEqual(err.statusCode, statusCode);
5+
if (code) {
6+
assert.strictEqual(err.name, code);
7+
}
8+
if (statusCode) {
9+
assert.strictEqual(err.$metadata.httpStatusCode, statusCode);
10+
}
711
}
812

913
module.exports = checkError;

tests/functional/aws-node-sdk/lib/utility/tagging.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ const taggingTests = [
55
it: 'should return tags if value is an empty string' },
66
{ tag: { key: 'w'.repeat(129), value: 'foo' },
77
error: 'InvalidTag',
8+
code: 400,
89
it: 'should return InvalidTag if key length is greater than 128' },
910
{ tag: { key: 'bar', value: 'f'.repeat(257) },
1011
error: 'InvalidTag',
12+
code: 400,
1113
it: 'should return InvalidTag if key length is greater than 256',
1214
},
1315
];

tests/functional/aws-node-sdk/lib/utility/website-util.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ const async = require('async');
33
const fs = require('fs');
44
const path = require('path');
55
const url = require('url');
6+
const { CreateBucketCommand,
7+
DeleteBucketCommand,
8+
PutBucketWebsiteCommand,
9+
DeleteObjectCommand,
10+
PutObjectCommand } = require('@aws-sdk/client-s3');
611

712
const { makeRequest } = require('../../../raw-node/utils/makeRequest');
813

@@ -352,41 +357,31 @@ class WebsiteConfigTester {
352357
}
353358

354359
static createPutBucketWebsite(s3, bucket, bucketACL, objects, done) {
355-
s3.createBucket({ Bucket: bucket, ACL: bucketACL },
356-
err => {
357-
if (err) {
358-
return done(err);
359-
}
360+
s3.send(new CreateBucketCommand({ Bucket: bucket, ACL: bucketACL })).then(() => {
360361
const webConfig = new WebsiteConfigTester('index.html',
361362
'error.html');
362-
return s3.putBucketWebsite({ Bucket: bucket,
363-
WebsiteConfiguration: webConfig }, err => {
364-
if (err) {
365-
return done(err);
366-
}
367-
return async.forEachOf(objects,
363+
return s3.send(new PutBucketWebsiteCommand({ Bucket: bucket,
364+
WebsiteConfiguration: webConfig })).then(() => async.forEachOf(objects,
368365
(acl, object, next) => {
369-
s3.putObject({ Bucket: bucket,
366+
s3.send(new PutObjectCommand({ Bucket: bucket,
370367
Key: `${object}.html`,
371368
ACL: acl,
372369
Body: fs.readFileSync(path.join(__dirname,
373370
`/../../test/object/websiteFiles/${object}.html`)),
374-
},
375-
next);
376-
}, done);
377-
});
378-
});
371+
})).then(() => next()).catch(next);
372+
}, done));
373+
}).catch(err => done(err));
379374
}
380375

381376
static deleteObjectsThenBucket(s3, bucket, objects, done) {
382377
async.forEachOf(objects, (acl, object, next) => {
383-
s3.deleteObject({ Bucket: bucket,
384-
Key: `${object}.html` }, next);
378+
s3.send(new DeleteObjectCommand({ Bucket: bucket,
379+
Key: `${object}.html` })).then(() => next()).catch(next);
385380
}, err => {
386381
if (err) {
387382
return done(err);
388383
}
389-
return s3.deleteBucket({ Bucket: bucket }, done);
384+
return s3.send(new DeleteBucketCommand({ Bucket: bucket })).then(() => done()).catch(done);
390385
});
391386
}
392387
}

tests/functional/aws-node-sdk/test/object/100-continue.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const assert = require('assert');
22
const http = require('http');
33
const https = require('https');
44
const url = require('url');
5+
const { CreateBucketCommand, PutObjectCommand } = require('@aws-sdk/client-s3');
6+
const { getSignedUrl } = require('@aws-sdk/s3-request-presigner');
57

68
const withV4 = require('../support/withV4');
79
const BucketUtility = require('../../lib/utility/bucket-util');
@@ -121,17 +123,19 @@ describeSkipIfE2E('PUT public object with 100-continue header', () => {
121123
let continueRequest;
122124
const invalidSignedURL = `/${bucket}/${key}`;
123125

124-
beforeEach(() => {
126+
beforeEach(async () => {
125127
bucketUtil = new BucketUtility('default', sigCfg);
126128
s3 = bucketUtil.s3;
127129
const params = {
128130
Bucket: bucket,
129131
Key: key,
132+
'Content-Length': 0,
130133
};
131-
const signedUrl = s3.getSignedUrl('putObject', params);
134+
const command = new PutObjectCommand(params);
135+
const signedUrl = await getSignedUrl(s3, command);
132136
const { path } = url.parse(signedUrl);
133137
continueRequest = new ContinueRequestHandler(path);
134-
return s3.createBucket({ Bucket: bucket }).promise();
138+
await s3.send(new CreateBucketCommand({ Bucket: bucket }));
135139
});
136140

137141
afterEach(() =>

0 commit comments

Comments
 (0)