Skip to content

Commit 9929e7c

Browse files
committed
Refactor ListObjectsV2 CTST tests to use AWS SDK client
Issue: ZENKO-5208
1 parent fbd9232 commit 9929e7c

File tree

1 file changed

+16
-47
lines changed

1 file changed

+16
-47
lines changed

tests/ctst/steps/user-defined-metadata/list-objects-v2.ts

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,29 @@
11
import assert from 'assert';
22
import { Then, When } from '@cucumber/cucumber';
3-
import { parseStringPromise } from 'xml2js';
4-
import { Identity } from 'cli-testing';
3+
import { ListObjectsV2ExtendedCommand } from '@scality/cloudserverclient';
54
import Zenko from '../../world/Zenko';
65
import { safeJsonParse } from '../../common/utils';
76

8-
When('the user calls ListObjectsV2 on the bucket with optional attributes {string}', async function (
9-
this: Zenko,
7+
async function listObjectsV2WithOptionalAttributes(
8+
world: Zenko,
109
optionalAttributes: string,
1110
) {
12-
this.resetCommand();
13-
14-
const bucketName = this.getSaved<string>('bucketName');
15-
const attributesList = optionalAttributes.split(',').map(attr => attr.trim());
16-
const credentials = Identity.getCurrentCredentials();
17-
18-
const path = `/${bucketName}?list-type=2`;
11+
world.resetCommand();
1912

20-
const result = await this.awsS3Request(
21-
'GET',
22-
path,
23-
{ accessKeyId: credentials.accessKeyId, secretAccessKey: credentials.secretAccessKey },
24-
{ 'x-amz-optional-object-attributes': attributesList.join(',') },
25-
);
26-
27-
if (result.err) {
28-
this.setResult({
29-
stdout: '',
30-
err: result.err,
31-
statusCode: result.statusCode,
32-
});
33-
return;
34-
}
13+
const bucketName = world.getSaved<string>('bucketName');
14+
const optionalAttrsList = optionalAttributes.split(',').map(attr => attr.trim());
3515

36-
const rawXml = result.data as string;
37-
const contents: Record<string, unknown>[] = [];
16+
await world.sendS3Command(new ListObjectsV2ExtendedCommand({
17+
Bucket: bucketName,
18+
ObjectAttributes: optionalAttrsList,
19+
}));
20+
}
3821

39-
if (rawXml) {
40-
const parsedXml = await parseStringPromise(rawXml) as Record<string, unknown>;
41-
const listResult = parsedXml?.ListBucketResult as Record<string, unknown> | undefined;
42-
if (listResult?.Contents) {
43-
for (const item of listResult.Contents as Record<string, unknown[]>[]) {
44-
const obj: Record<string, unknown> = {};
45-
for (const k of Object.keys(item)) {
46-
obj[k] = item[k][0];
47-
}
48-
contents.push(obj);
49-
}
50-
}
51-
}
52-
53-
this.setResult({
54-
stdout: JSON.stringify({ Contents: contents }),
55-
err: null,
56-
statusCode: result.statusCode,
57-
});
22+
When('the user calls ListObjectsV2 on the bucket with optional attributes {string}', async function (
23+
this: Zenko,
24+
optionalAttributes: string,
25+
) {
26+
await listObjectsV2WithOptionalAttributes(this, optionalAttributes);
5827
});
5928

6029
Then('the ListObjectsV2 response should contain {string}', function (

0 commit comments

Comments
 (0)