-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathstorageUsageReporting.ts
More file actions
79 lines (68 loc) · 3.23 KB
/
storageUsageReporting.ts
File metadata and controls
79 lines (68 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { When, Then } from '@cucumber/cucumber';
import { strict as assert } from 'assert';
import Zenko from '../../world/Zenko';
import { IdentityEnum } from 'cli-testing';
interface LocationUsage {
bytesTotal: number;
objectsTotal: number;
}
interface ReportingUsageResponse {
isTruncated: boolean;
marker: string | null;
accounts: Record<string, Record<string, LocationUsage>>;
}
When('the user retrieves the storage usage report as {string}', async function (this: Zenko, role: string) {
const result = await this.managementAPIRequest(
'GET',
`/instance/${this.parameters.InstanceID}/reporting/usage`,
{},
{},
role,
);
this.addToSaved('reportingResponse', result);
});
Then('the storage usage report http response code is {int}', function (this: Zenko, expectedStatus: number) {
const response = this.getSaved<{ statusCode: number }>('reportingResponse');
assert.strictEqual(response.statusCode, expectedStatus,
`Expected status ${expectedStatus} but got ${response.statusCode}`);
});
Then('the storage usage report response has a valid structure', function (this: Zenko) {
const response = this.getSaved<{ statusCode: number; data: ReportingUsageResponse }>(
'reportingResponse');
const data = response.data;
assert.strictEqual(typeof data.isTruncated, 'boolean',
'isTruncated should be a boolean');
assert.ok(typeof data.marker === 'string' || data.marker === null,
'marker should be a string or null');
assert.strictEqual(typeof data.accounts, 'object',
'accounts should be an object');
});
Then('the storage usage report contains the additional accounts', async function (this: Zenko) {
const response = this.getSaved<{ statusCode: number; data: ReportingUsageResponse }>(
'reportingResponse');
const accountNames = this.getSavedIdentities()
.filter(id => id.identityType === IdentityEnum.ACCOUNT)
.map(id => id.accountName);
for (const accountName of accountNames) {
assert.ok(accountName in response.data.accounts,
`Account ${accountName} should be present in the report`);
}
});
Then('the report contains the test account with location {string}', async function (this: Zenko, locationName: string) {
const response = this.getSaved<{ statusCode: number; data: ReportingUsageResponse }>(
'reportingResponse');
const accountName = this.getSaved<string>('accountName');
assert.ok(accountName in response.data.accounts,
`Account ${accountName} should be present in the report`);
const accountData = response.data.accounts[accountName];
assert.ok(locationName in accountData,
`Location ${locationName} should be present for account ${accountName}`);
this.addToSaved('reportedLocationUsage', accountData[locationName]);
});
Then('the report shows {int} objects and {int} bytes', function (this: Zenko, objects: number, bytes: number) {
const usage = this.getSaved<LocationUsage>('reportedLocationUsage');
assert.strictEqual(usage.objectsTotal, objects,
`Expected ${objects} objects but got ${usage.objectsTotal}`);
assert.strictEqual(usage.bytesTotal, bytes,
`Expected ${bytes} bytes but got ${usage.bytesTotal}`);
});