|
1 | 1 | import assert from 'assert'; |
2 | 2 | import { Then, When } from '@cucumber/cucumber'; |
3 | | -import { parseStringPromise } from 'xml2js'; |
4 | | -import { Identity } from 'cli-testing'; |
| 3 | +import { ListObjectsV2ExtendedCommand } from '@scality/cloudserverclient'; |
5 | 4 | import Zenko from '../../world/Zenko'; |
6 | 5 | import { safeJsonParse } from '../../common/utils'; |
7 | 6 |
|
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, |
10 | 9 | optionalAttributes: string, |
11 | 10 | ) { |
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(); |
19 | 12 |
|
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()); |
35 | 15 |
|
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 | +} |
38 | 21 |
|
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); |
58 | 27 | }); |
59 | 28 |
|
60 | 29 | Then('the ListObjectsV2 response should contain {string}', function ( |
|
0 commit comments