Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[datadog_synthetics_test] prevent overriding the local state element from the backend response #2460

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions datadog/resource_datadog_synthetics_test_.go
Original file line number Diff line number Diff line change
Expand Up @@ -3179,17 +3179,31 @@ func updateSyntheticsBrowserTestLocalState(d *schema.ResourceData, syntheticsTes
}

localParams := make(map[string]interface{})

forceElementUpdate, ok := d.GetOk(fmt.Sprintf("browser_step.%d.force_element_update", stepIndex))
if ok {
localStep["force_element_update"] = forceElementUpdate
}

params := step.GetParams()
paramsMap := params.(map[string]interface{})

for key, value := range paramsMap {
localParams[convertStepParamsKey(key)] = convertStepParamsValueForState(convertStepParamsKey(key), value)
if key == "element" && forceElementUpdate == true {
// prevent overriding `element` in the local state with the one received from the backend, and
// keep the element from the local state instead
element := d.Get(fmt.Sprintf("browser_step.%d.params.0.element", stepIndex))
localParams["element"] = element
} else {
localParams[convertStepParamsKey(key)] = convertStepParamsValueForState(convertStepParamsKey(key), value)
}
}

if elementParams, ok := localParams["element"]; ok {
// If received an element from the backend, extract the user locator part to update the local state
if elementParams, ok := paramsMap["element"]; ok {
serializedElementParams := convertStepParamsValueForState("element", elementParams)
var stepElement interface{}
utils.GetMetadataFromJSON([]byte(elementParams.(string)), &stepElement)

utils.GetMetadataFromJSON([]byte(serializedElementParams.(string)), &stepElement)
if elementUserLocator, ok := stepElement.(map[string]interface{})["userLocator"]; ok {
userLocator := elementUserLocator.(map[string]interface{})
values := userLocator["values"]
Expand All @@ -3208,10 +3222,6 @@ func updateSyntheticsBrowserTestLocalState(d *schema.ResourceData, syntheticsTes

localStep["params"] = []interface{}{localParams}

if forceElementUpdate, ok := d.GetOk(fmt.Sprintf("browser_step.%d.force_element_update", stepIndex)); ok {
localStep["force_element_update"] = forceElementUpdate
}

localSteps = append(localSteps, localStep)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-07-05T10:48:23.870126-04:00
2024-07-05T15:11:08.555393-04:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-07-05T10:48:23.867415-04:00
2024-07-05T15:11:08.555371-04:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-07-05T10:48:23.88129-04:00
2024-07-05T15:11:08.555355-04:00
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interactions:
remote_addr: ""
request_uri: ""
body: |
{"config":{"assertions":[],"configVariables":[],"request":{"method":"GET","url":"https://www.datadoghq.com"},"variables":[]},"locations":["aws:eu-central-1"],"message":"Notify @datadog.user","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720190903","options":{"device_ids":["laptop_large"],"httpVersion":"any","min_location_failed":1,"tick_every":900},"status":"paused","steps":[{"allowFailure":false,"isCritical":false,"name":"click step","noScreenshot":false,"params":{"element":{"userLocator":{"failTestOnCannotLocate":true,"values":[{"type":"css","value":"user-locator-test"}]}}},"timeout":0,"type":"click"}],"tags":["foo:bar"],"type":"browser"}
{"config":{"assertions":[],"configVariables":[],"request":{"method":"GET","url":"https://www.datadoghq.com"},"variables":[]},"locations":["aws:eu-central-1"],"message":"Notify @datadog.user","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720206668","options":{"device_ids":["laptop_large"],"httpVersion":"any","min_location_failed":1,"tick_every":900},"status":"paused","steps":[{"allowFailure":false,"isCritical":false,"name":"click step","noScreenshot":false,"params":{"element":{"userLocator":{"failTestOnCannotLocate":true,"values":[{"type":"css","value":"user-locator-test"}]}}},"timeout":0,"type":"click"}],"tags":["foo:bar"],"type":"browser"}
form: {}
headers:
Accept:
Expand All @@ -32,13 +32,13 @@ interactions:
content_length: -1
uncompressed: true
body: |
{"public_id":"6as-u4m-2b6","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720190903","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-05T14:48:27.767626+00:00","modified_at":"2024-07-05T14:48:27.767626+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","url":"https://www.datadoghq.com"},"variables":[]},"message":"Notify @datadog.user","options":{"device_ids":["laptop_large"],"httpVersion":"any","min_location_failed":1,"tick_every":900},"locations":["aws:eu-central-1"],"created_by":{"name":null,"handle":"[email protected]","email":"[email protected]"},"deleted_at":null,"monitor_id":148641983,"org_id":321813,"modified_by":{"name":null,"handle":"[email protected]","email":"[email protected]"},"steps":[{"name":"click step","params":{"element":{"userLocator":{"failTestOnCannotLocate":true,"values":[{"type":"css","value":"user-locator-test"}]}}},"timeout":0,"type":"click","allowFailure":false,"isCritical":false,"noScreenshot":false}],"stepCount":{"assertions":0,"subtests":0,"total":1}}
{"public_id":"8bm-p6w-wvq","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720206668","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-05T19:11:11.888115+00:00","modified_at":"2024-07-05T19:11:11.888115+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","url":"https://www.datadoghq.com"},"variables":[]},"message":"Notify @datadog.user","options":{"device_ids":["laptop_large"],"httpVersion":"any","min_location_failed":1,"tick_every":900},"locations":["aws:eu-central-1"],"created_by":{"name":null,"handle":"[email protected]","email":"[email protected]"},"deleted_at":null,"monitor_id":148654934,"org_id":321813,"modified_by":{"name":null,"handle":"[email protected]","email":"[email protected]"},"steps":[{"name":"click step","params":{"element":{"userLocator":{"failTestOnCannotLocate":true,"values":[{"type":"css","value":"user-locator-test"}]}}},"timeout":0,"type":"click","allowFailure":false,"isCritical":false,"noScreenshot":false}],"stepCount":{"assertions":0,"subtests":0,"total":1}}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: 672.233333ms
duration: 1.310798167s
- id: 1
request:
proto: HTTP/1.1
Expand All @@ -55,7 +55,7 @@ interactions:
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v1/synthetics/tests/browser/6as-u4m-2b6
url: https://api.datadoghq.com/api/v1/synthetics/tests/browser/8bm-p6w-wvq
method: GET
response:
proto: HTTP/1.1
Expand All @@ -67,13 +67,13 @@ interactions:
content_length: -1
uncompressed: true
body: |
{"public_id":"6as-u4m-2b6","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720190903","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-05T14:48:27.767626+00:00","modified_at":"2024-07-05T14:48:27.767626+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","url":"https://www.datadoghq.com"},"variables":[]},"message":"Notify @datadog.user","options":{"device_ids":["laptop_large"],"httpVersion":"any","min_location_failed":1,"tick_every":900},"locations":["aws:eu-central-1"],"monitor_id":148641983,"creator":{"name":null,"handle":"[email protected]","email":"[email protected]"},"steps":[{"name":"click step","params":{"element":{"userLocator":{"failTestOnCannotLocate":true,"values":[{"type":"css","value":"user-locator-test"}]}}},"timeout":0,"type":"click","allowFailure":false,"isCritical":false,"noScreenshot":false}]}
{"public_id":"8bm-p6w-wvq","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720206668","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-05T19:11:11.888115+00:00","modified_at":"2024-07-05T19:11:11.888115+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","url":"https://www.datadoghq.com"},"variables":[]},"message":"Notify @datadog.user","options":{"device_ids":["laptop_large"],"httpVersion":"any","min_location_failed":1,"tick_every":900},"locations":["aws:eu-central-1"],"monitor_id":148654934,"creator":{"name":null,"handle":"[email protected]","email":"[email protected]"},"steps":[{"name":"click step","params":{"element":{"userLocator":{"failTestOnCannotLocate":true,"values":[{"type":"css","value":"user-locator-test"}]}}},"timeout":0,"type":"click","allowFailure":false,"isCritical":false,"noScreenshot":false}]}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: 84.627875ms
duration: 88.181625ms
- id: 2
request:
proto: HTTP/1.1
Expand All @@ -90,7 +90,7 @@ interactions:
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v1/synthetics/tests/6as-u4m-2b6
url: https://api.datadoghq.com/api/v1/synthetics/tests/8bm-p6w-wvq
method: GET
response:
proto: HTTP/1.1
Expand All @@ -102,13 +102,13 @@ interactions:
content_length: -1
uncompressed: true
body: |
{"public_id":"6as-u4m-2b6","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720190903","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-05T14:48:27.767626+00:00","modified_at":"2024-07-05T14:48:27.767626+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","url":"https://www.datadoghq.com"},"variables":[]},"message":"Notify @datadog.user","options":{"device_ids":["laptop_large"],"httpVersion":"any","min_location_failed":1,"tick_every":900},"locations":["aws:eu-central-1"],"monitor_id":148641983,"creator":{"name":null,"handle":"[email protected]","email":"[email protected]"}}
{"public_id":"8bm-p6w-wvq","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720206668","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-05T19:11:11.888115+00:00","modified_at":"2024-07-05T19:11:11.888115+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","url":"https://www.datadoghq.com"},"variables":[]},"message":"Notify @datadog.user","options":{"device_ids":["laptop_large"],"httpVersion":"any","min_location_failed":1,"tick_every":900},"locations":["aws:eu-central-1"],"monitor_id":148654934,"creator":{"name":null,"handle":"[email protected]","email":"[email protected]"}}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: 77.759125ms
duration: 200.367792ms
- id: 3
request:
proto: HTTP/1.1
Expand All @@ -125,7 +125,7 @@ interactions:
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v1/synthetics/tests/6as-u4m-2b6
url: https://api.datadoghq.com/api/v1/synthetics/tests/8bm-p6w-wvq
method: GET
response:
proto: HTTP/1.1
Expand All @@ -137,13 +137,13 @@ interactions:
content_length: -1
uncompressed: true
body: |
{"public_id":"6as-u4m-2b6","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720190903","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-05T14:48:27.767626+00:00","modified_at":"2024-07-05T14:48:27.767626+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","url":"https://www.datadoghq.com"},"variables":[]},"message":"Notify @datadog.user","options":{"device_ids":["laptop_large"],"httpVersion":"any","min_location_failed":1,"tick_every":900},"locations":["aws:eu-central-1"],"monitor_id":148641983,"creator":{"name":null,"handle":"[email protected]","email":"[email protected]"}}
{"public_id":"8bm-p6w-wvq","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720206668","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-05T19:11:11.888115+00:00","modified_at":"2024-07-05T19:11:11.888115+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","url":"https://www.datadoghq.com"},"variables":[]},"message":"Notify @datadog.user","options":{"device_ids":["laptop_large"],"httpVersion":"any","min_location_failed":1,"tick_every":900},"locations":["aws:eu-central-1"],"monitor_id":148654934,"creator":{"name":null,"handle":"[email protected]","email":"[email protected]"}}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: 92.701625ms
duration: 95.034041ms
- id: 4
request:
proto: HTTP/1.1
Expand All @@ -160,7 +160,7 @@ interactions:
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v1/synthetics/tests/browser/6as-u4m-2b6
url: https://api.datadoghq.com/api/v1/synthetics/tests/browser/8bm-p6w-wvq
method: GET
response:
proto: HTTP/1.1
Expand All @@ -172,13 +172,13 @@ interactions:
content_length: -1
uncompressed: true
body: |
{"public_id":"6as-u4m-2b6","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720190903","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-05T14:48:27.767626+00:00","modified_at":"2024-07-05T14:48:27.767626+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","url":"https://www.datadoghq.com"},"variables":[]},"message":"Notify @datadog.user","options":{"device_ids":["laptop_large"],"httpVersion":"any","min_location_failed":1,"tick_every":900},"locations":["aws:eu-central-1"],"monitor_id":148641983,"creator":{"name":null,"handle":"[email protected]","email":"[email protected]"},"steps":[{"name":"click step","params":{"element":{"userLocator":{"failTestOnCannotLocate":true,"values":[{"type":"css","value":"user-locator-test"}]}}},"timeout":0,"type":"click","allowFailure":false,"isCritical":false,"noScreenshot":false}]}
{"public_id":"8bm-p6w-wvq","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720206668","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-05T19:11:11.888115+00:00","modified_at":"2024-07-05T19:11:11.888115+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","url":"https://www.datadoghq.com"},"variables":[]},"message":"Notify @datadog.user","options":{"device_ids":["laptop_large"],"httpVersion":"any","min_location_failed":1,"tick_every":900},"locations":["aws:eu-central-1"],"monitor_id":148654934,"creator":{"name":null,"handle":"[email protected]","email":"[email protected]"},"steps":[{"name":"click step","params":{"element":{"userLocator":{"failTestOnCannotLocate":true,"values":[{"type":"css","value":"user-locator-test"}]}}},"timeout":0,"type":"click","allowFailure":false,"isCritical":false,"noScreenshot":false}]}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: 90.119ms
duration: 89.453667ms
- id: 5
request:
proto: HTTP/1.1
Expand All @@ -191,7 +191,7 @@ interactions:
remote_addr: ""
request_uri: ""
body: |
{"public_ids":["6as-u4m-2b6"]}
{"public_ids":["8bm-p6w-wvq"]}
form: {}
headers:
Accept:
Expand All @@ -210,13 +210,13 @@ interactions:
content_length: -1
uncompressed: true
body: |
{"deleted_tests":[{"public_id":"6as-u4m-2b6","deleted_at":"2024-07-05T14:48:30.721712+00:00"}]}
{"deleted_tests":[{"public_id":"8bm-p6w-wvq","deleted_at":"2024-07-05T19:11:14.868201+00:00"}]}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: 572.471917ms
duration: 694.15175ms
- id: 6
request:
proto: HTTP/1.1
Expand All @@ -233,7 +233,7 @@ interactions:
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v1/synthetics/tests/6as-u4m-2b6
url: https://api.datadoghq.com/api/v1/synthetics/tests/8bm-p6w-wvq
method: GET
response:
proto: HTTP/1.1
Expand All @@ -250,4 +250,4 @@ interactions:
- application/json
status: 404 Not Found
code: 404
duration: 104.525916ms
duration: 56.676375ms
Loading