Skip to content

Commit a9d2500

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-specHantingZhang2
authored
Use request data for undo operations in tests when response empty (#1396)
* Regenerate client from commit 89f9f50d of spec repo * change undo behavior * change undefined equals * Regenerate client from commit f57ca8ef of spec repo --------- Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com> Co-authored-by: HantingZhang2 <hanting.zhang@datadoghq.com> Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com>
1 parent e08ce25 commit a9d2500

File tree

9 files changed

+151
-14
lines changed

9 files changed

+151
-14
lines changed

.apigentools-info

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.6",
7-
"regenerated": "2023-11-20 19:20:12.872303",
8-
"spec_repo_commit": "55cf29a4"
7+
"regenerated": "2023-11-21 11:52:06.579056",
8+
"spec_repo_commit": "f57ca8ef"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.6",
12-
"regenerated": "2023-11-20 19:20:12.886429",
13-
"spec_repo_commit": "55cf29a4"
12+
"regenerated": "2023-11-21 11:52:06.594355",
13+
"spec_repo_commit": "f57ca8ef"
1414
}
1515
}
1616
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"2023-11-13T14:17:01.291Z"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{
2+
"log": {
3+
"_recordingName": "AWS Integration/Create an AWS integration returns \"OK\" response",
4+
"creator": {
5+
"comment": "persister:fs",
6+
"name": "Polly.JS",
7+
"version": "6.0.5"
8+
},
9+
"entries": [
10+
{
11+
"_id": "b345fb9c3709338914a9210da4d600fd",
12+
"_order": 0,
13+
"cache": {},
14+
"request": {
15+
"bodySize": 340,
16+
"cookies": [],
17+
"headers": [
18+
{
19+
"_fromType": "array",
20+
"name": "accept",
21+
"value": "application/json"
22+
},
23+
{
24+
"_fromType": "array",
25+
"name": "content-type",
26+
"value": "application/json"
27+
}
28+
],
29+
"headersSize": 566,
30+
"httpVersion": "HTTP/1.1",
31+
"method": "POST",
32+
"postData": {
33+
"mimeType": "application/json",
34+
"params": [],
35+
"text": "{\"account_id\":\"169988502100\",\"account_specific_namespace_rules\":{\"auto_scaling\":false},\"cspm_resource_collection_enabled\":true,\"excluded_regions\":[\"us-east-1\",\"us-west-2\"],\"filter_tags\":[\"$KEY:$VALUE\"],\"host_tags\":[\"$KEY:$VALUE\"],\"metrics_collection_enabled\":false,\"resource_collection_enabled\":true,\"role_name\":\"DatadogAWSIntegrationRole\"}"
36+
},
37+
"queryString": [],
38+
"url": "https://api.datadoghq.com/api/v1/integration/aws"
39+
},
40+
"response": {
41+
"bodySize": 51,
42+
"content": {
43+
"mimeType": "application/json",
44+
"size": 51,
45+
"text": "{\"external_id\":\"9668e281c0ef4cc8be01710ef7a0ae4c\"}\n"
46+
},
47+
"cookies": [],
48+
"headers": [
49+
{
50+
"name": "content-type",
51+
"value": "application/json"
52+
}
53+
],
54+
"headersSize": 516,
55+
"httpVersion": "HTTP/1.1",
56+
"redirectURL": "",
57+
"status": 200,
58+
"statusText": "OK"
59+
},
60+
"startedDateTime": "2023-11-13T14:17:01.302Z",
61+
"time": 1169
62+
},
63+
{
64+
"_id": "f88366bd5b70614a86ac275fdf744321",
65+
"_order": 0,
66+
"cache": {},
67+
"request": {
68+
"bodySize": 69,
69+
"cookies": [],
70+
"headers": [
71+
{
72+
"_fromType": "array",
73+
"name": "accept",
74+
"value": "application/json"
75+
},
76+
{
77+
"_fromType": "array",
78+
"name": "content-type",
79+
"value": "application/json"
80+
}
81+
],
82+
"headersSize": 567,
83+
"httpVersion": "HTTP/1.1",
84+
"method": "DELETE",
85+
"postData": {
86+
"mimeType": "application/json",
87+
"params": [],
88+
"text": "{\"account_id\":\"169988502100\",\"role_name\":\"DatadogAWSIntegrationRole\"}"
89+
},
90+
"queryString": [],
91+
"url": "https://api.datadoghq.com/api/v1/integration/aws"
92+
},
93+
"response": {
94+
"bodySize": 3,
95+
"content": {
96+
"mimeType": "application/json",
97+
"size": 3,
98+
"text": "{}\n"
99+
},
100+
"cookies": [],
101+
"headers": [
102+
{
103+
"name": "content-type",
104+
"value": "application/json"
105+
}
106+
],
107+
"headersSize": 492,
108+
"httpVersion": "HTTP/1.1",
109+
"redirectURL": "",
110+
"status": 200,
111+
"statusText": "OK"
112+
},
113+
"startedDateTime": "2023-11-13T14:17:02.482Z",
114+
"time": 745
115+
}
116+
],
117+
"pages": [],
118+
"version": "1.2"
119+
}
120+
}

examples/v1/aws-integration/CreateAWSAccount.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ const apiInstance = new v1.AWSIntegrationApi(configuration);
99

1010
const params: v1.AWSIntegrationApiCreateAWSAccountRequest = {
1111
body: {
12-
accountId: "123456789012",
12+
accountId: "163662907100",
1313
accountSpecificNamespaceRules: {
1414
auto_scaling: false,
15-
opswork: false,
1615
},
1716
cspmResourceCollectionEnabled: true,
1817
excludedRegions: ["us-east-1", "us-west-2"],

features/step_definitions/request_steps.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ When("the request is sent", async function (this: World) {
143143
this.apiVersion,
144144
undoAction,
145145
this.operationId,
146-
this.response
146+
this.response,
147+
this.opts,
147148
)
148149
);
149150
}

features/support/given.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ for (const apiVersion of Versions) {
121121
// register undo method
122122
if (undoAction.undo.type == "unsafe") {
123123
this.undo.push(
124-
buildUndoFor(apiVersion, undoAction, operationName, result)
124+
buildUndoFor(apiVersion, undoAction, operationName, result, opts)
125125
);
126126
}
127127

features/support/undo.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ logger.setLevel(process.env.DEBUG ? logger.levels.DEBUG : logger.levels.INFO);
1010

1111
interface iOperationParameter {
1212
name: string;
13+
origin: string;
1314
source: string;
1415
template: string;
1516
}
@@ -42,7 +43,8 @@ function buildUndoFor(
4243
apiVersion: string,
4344
operationUndo: iUndoAction,
4445
operationOrig: string,
45-
response: any
46+
response: any,
47+
request: any
4648
): { (): void } {
4749
return async function () {
4850
var apiName = operationUndo.tag.replace(/\s/g, "");
@@ -85,10 +87,18 @@ function buildUndoFor(
8587
// perform operation
8688
const opts: { [key: string]: any } = {};
8789
for (const p of operationUndo.undo.parameters) {
90+
var dataSource: { [key: string]: any; };
91+
if (p.origin === undefined) {
92+
dataSource = response;
93+
} else if (p.origin === "request") {
94+
dataSource = request.body;
95+
} else {
96+
dataSource = response;
97+
}
8898
if (p.source !== undefined) {
89-
opts[p.name.toAttributeName()] = pathLookup(response, p.source);
99+
opts[p.name.toAttributeName()] = pathLookup(dataSource, p.source);
90100
} else if (p.template !== undefined) {
91-
const data = JSON.parse(p.template.templated(response));
101+
const data = JSON.parse(p.template.templated(dataSource));
92102
const param: { [key: string]: any } = {};
93103
for (const [key, value] of Object.entries(data)) {
94104
param[key.toAttributeName()] = value;

features/v1/aws_integration.feature

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ Feature: AWS Integration
2323
When the request is sent
2424
Then the response status is 409 Conflict Error
2525

26-
@generated @skip @team:DataDog/cloud-integrations
26+
@team:DataDog/cloud-integrations
2727
Scenario: Create an AWS integration returns "OK" response
2828
Given new "CreateAWSAccount" request
29-
And body with value {"account_id": "123456789012", "account_specific_namespace_rules": {"auto_scaling": false, "opswork": false}, "cspm_resource_collection_enabled": true, "excluded_regions": ["us-east-1", "us-west-2"], "filter_tags": ["$KEY:$VALUE"], "host_tags": ["$KEY:$VALUE"], "metrics_collection_enabled": false, "resource_collection_enabled": true, "role_name": "DatadogAWSIntegrationRole"}
29+
And body with value {"account_id": "{{ timestamp("now") }}00", "account_specific_namespace_rules": {"auto_scaling": false}, "cspm_resource_collection_enabled": true, "excluded_regions": ["us-east-1", "us-west-2"], "filter_tags": ["$KEY:$VALUE"], "host_tags": ["$KEY:$VALUE"], "metrics_collection_enabled": false, "resource_collection_enabled": true, "role_name": "DatadogAWSIntegrationRole"}
3030
When the request is sent
3131
Then the response status is 200 OK
3232

features/v1/undo.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,13 @@
356356
"tag": "AWS Integration",
357357
"undo": {
358358
"operationId": "DeleteAWSAccount",
359-
"parameters": [],
359+
"parameters": [
360+
{
361+
"name": "body",
362+
"origin": "request",
363+
"template": "{\"account_id\": \"{{account_id}}\", \"role_name\": \"{{role_name}}\"}"
364+
}
365+
],
360366
"type": "unsafe"
361367
}
362368
},

0 commit comments

Comments
 (0)