Skip to content

Commit

Permalink
Use request data for undo operations in tests when response empty (#2256
Browse files Browse the repository at this point in the history
)

* Regenerate client from commit 89f9f50d of spec repo

* Use request body for undo when response empty

* Add json lib

* minor change

* Regenerate client from commit f57ca8ef of spec repo

---------

Co-authored-by: ci.datadog-api-spec <[email protected]>
Co-authored-by: HantingZhang2 <[email protected]>
Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 21, 2023
1 parent 9c8349d commit a9a5a24
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 11 deletions.
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2023-11-20 19:20:23.293173",
"spec_repo_commit": "55cf29a4"
"regenerated": "2023-11-21 11:52:10.459380",
"spec_repo_commit": "f57ca8ef"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2023-11-20 19:20:23.326162",
"spec_repo_commit": "55cf29a4"
"regenerated": "2023-11-21 11:52:10.476020",
"spec_repo_commit": "f57ca8ef"
}
}
}
3 changes: 1 addition & 2 deletions examples/v1/aws-integration/CreateAWSAccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import (

func main() {
body := datadogV1.AWSAccount{
AccountId: datadog.PtrString("123456789012"),
AccountId: datadog.PtrString("163662907100"),
AccountSpecificNamespaceRules: map[string]bool{
"auto_scaling": false,
"opswork": false,
},
CspmResourceCollectionEnabled: datadog.PtrBool(true),
ExcludedRegions: []string{
Expand Down
22 changes: 20 additions & 2 deletions tests/scenarios/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type UndoAction struct {
Name string `json:"name"`
Source *string `json:"source"`
Template *string `json:"template"`
Origin *string `json:origin`
} `json:"parameters"`
} `json:"undo"`
}
Expand Down Expand Up @@ -307,16 +308,33 @@ func GetRequestsUndo(ctx gobdd.Context, version string, operationID string) (fun
}

for i := 1; i < numArgs && i <= len(undo.Undo.Parameters); i++ {
var sourceJSONData interface{}
if undo.Undo.Parameters[i-1].Origin == nil {
sourceJSONData = responseJSON
} else if *undo.Undo.Parameters[i-1].Origin == "request" {
requestParams := GetRequestParameters(ctx)
requestJSON := make(map[string]interface{})
if requestParams["body"] != nil {
requestData := requestParams["body"].(string)
if err := datadog.Unmarshal([]byte(requestData), &requestJSON); err != nil {
t.Fatalf("Error unmarshalling request: %v", err)
return
}
}
sourceJSONData = requestJSON
} else if *undo.Undo.Parameters[i-1].Origin == "response" {
sourceJSONData = responseJSON
}
if undo.Undo.Parameters[i-1].Template != nil {
data := Templated(t, responseJSON.(map[string]interface{}), *undo.Undo.Parameters[i-1].Template)
data := Templated(t, sourceJSONData.(map[string]interface{}), *undo.Undo.Parameters[i-1].Template)
object := reflect.New(undoOperation.Type().In(i))
err := datadog.Unmarshal([]byte(data), object.Interface())
if err != nil {
t.Fatalf("%v", err)
}
in[i] = object.Elem()
} else if undo.Undo.Parameters[i-1].Source != nil {
source, err := tests.LookupStringI(responseJSON, *undo.Undo.Parameters[i-1].Source)
source, err := tests.LookupStringI(sourceJSONData, *undo.Undo.Parameters[i-1].Source)
if err != nil {
t.Fatalf("%v", err)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-11-13T14:17:01.291Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
interactions:
- request:
body: |
{"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"}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
method: POST
url: https://api.datadoghq.com/api/v1/integration/aws
response:
body: '{"external_id":"9668e281c0ef4cc8be01710ef7a0ae4c"}
'
code: 200
duration: ''
headers:
Content-Type:
- application/json
status: 200 OK
- request:
body: |
{"account_id":"169988502100","role_name":"DatadogAWSIntegrationRole"}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
method: DELETE
url: https://api.datadoghq.com/api/v1/integration/aws
response:
body: '{}
'
code: 200
duration: ''
headers:
Content-Type:
- application/json
status: 200 OK
version: 1
4 changes: 2 additions & 2 deletions tests/scenarios/features/v1/aws_integration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ Feature: AWS Integration
When the request is sent
Then the response status is 409 Conflict Error

@generated @skip @team:DataDog/cloud-integrations
@team:DataDog/cloud-integrations
Scenario: Create an AWS integration returns "OK" response
Given new "CreateAWSAccount" request
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"}
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"}
When the request is sent
Then the response status is 200 OK

Expand Down
8 changes: 7 additions & 1 deletion tests/scenarios/features/v1/undo.json
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,13 @@
"tag": "AWS Integration",
"undo": {
"operationId": "DeleteAWSAccount",
"parameters": [],
"parameters": [
{
"name": "body",
"origin": "request",
"template": "{\"account_id\": \"{{account_id}}\", \"role_name\": \"{{role_name}}\"}"
}
],
"type": "unsafe"
}
},
Expand Down

0 comments on commit a9a5a24

Please sign in to comment.