Skip to content

Commit

Permalink
prevent overriding the local state element from the backend response
Browse files Browse the repository at this point in the history
  • Loading branch information
etnbrd committed Jul 5, 2024
1 parent 68574b2 commit 5fb5801
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 131 deletions.
26 changes: 18 additions & 8 deletions datadog/resource_datadog_synthetics_test_.go
Original file line number Diff line number Diff line change
Expand Up @@ -3180,17 +3180,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 @@ -3209,10 +3223,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-03T16:50:01.659618-04:00
2024-07-05T18:52:49.948468+02:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-07-03T16:49:55.105063-04:00
2024-07-05T18:53:24.465731+02:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-07-03T16:50:10.652467-04:00
2024-07-05T18:54:30.599544+02: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","timeout":60,"url":"https://www.datadoghq.com"},"variables":[]},"locations":["aws:eu-central-1"],"message":"Notify @datadog.user","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720039810","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","timeout":60,"url":"https://www.datadoghq.com"},"variables":[]},"locations":["aws:eu-central-1"],"message":"Notify @datadog.user","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720198470","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":"tsd-pef-tdc","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720039810","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-03T20:50:12.346519+00:00","modified_at":"2024-07-03T20:50:12.346519+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","timeout":60,"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":148530480,"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":"v4c-qnn-3xq","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720198470","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-05T16:54:32.578089+00:00","modified_at":"2024-07-05T16:54:32.578089+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","timeout":60,"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":148649365,"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: 434.671584ms
duration: 880.146084ms
- 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/tsd-pef-tdc
url: https://api.datadoghq.com/api/v1/synthetics/tests/browser/v4c-qnn-3xq
method: GET
response:
proto: HTTP/1.1
Expand All @@ -67,13 +67,13 @@ interactions:
content_length: -1
uncompressed: true
body: |
{"public_id":"tsd-pef-tdc","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720039810","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-03T20:50:12.346519+00:00","modified_at":"2024-07-03T20:50:12.346519+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","timeout":60,"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":148530480,"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":"v4c-qnn-3xq","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720198470","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-05T16:54:32.578089+00:00","modified_at":"2024-07-05T16:54:32.578089+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","timeout":60,"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":148649365,"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: 71.293917ms
duration: 156.179ms
- 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/tsd-pef-tdc
url: https://api.datadoghq.com/api/v1/synthetics/tests/v4c-qnn-3xq
method: GET
response:
proto: HTTP/1.1
Expand All @@ -102,13 +102,13 @@ interactions:
content_length: -1
uncompressed: true
body: |
{"public_id":"tsd-pef-tdc","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720039810","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-03T20:50:12.346519+00:00","modified_at":"2024-07-03T20:50:12.346519+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","timeout":60,"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":148530480,"creator":{"name":null,"handle":"[email protected]","email":"[email protected]"}}
{"public_id":"v4c-qnn-3xq","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720198470","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-05T16:54:32.578089+00:00","modified_at":"2024-07-05T16:54:32.578089+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","timeout":60,"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":148649365,"creator":{"name":null,"handle":"[email protected]","email":"[email protected]"}}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: 93.8525ms
duration: 156.543833ms
- 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/tsd-pef-tdc
url: https://api.datadoghq.com/api/v1/synthetics/tests/v4c-qnn-3xq
method: GET
response:
proto: HTTP/1.1
Expand All @@ -137,13 +137,13 @@ interactions:
content_length: -1
uncompressed: true
body: |
{"public_id":"tsd-pef-tdc","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720039810","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-03T20:50:12.346519+00:00","modified_at":"2024-07-03T20:50:12.346519+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","timeout":60,"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":148530480,"creator":{"name":null,"handle":"[email protected]","email":"[email protected]"}}
{"public_id":"v4c-qnn-3xq","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720198470","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-05T16:54:32.578089+00:00","modified_at":"2024-07-05T16:54:32.578089+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","timeout":60,"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":148649365,"creator":{"name":null,"handle":"[email protected]","email":"[email protected]"}}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: 113.186292ms
duration: 193.197833ms
- 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/tsd-pef-tdc
url: https://api.datadoghq.com/api/v1/synthetics/tests/browser/v4c-qnn-3xq
method: GET
response:
proto: HTTP/1.1
Expand All @@ -172,13 +172,13 @@ interactions:
content_length: -1
uncompressed: true
body: |
{"public_id":"tsd-pef-tdc","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720039810","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-03T20:50:12.346519+00:00","modified_at":"2024-07-03T20:50:12.346519+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","timeout":60,"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":148530480,"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":"v4c-qnn-3xq","name":"tf-TestAccDatadogSyntheticsTestBrowserUserLocator_NoElement-local-1720198470","status":"paused","type":"browser","tags":["foo:bar"],"created_at":"2024-07-05T16:54:32.578089+00:00","modified_at":"2024-07-05T16:54:32.578089+00:00","config":{"assertions":[],"configVariables":[],"request":{"method":"GET","timeout":60,"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":148649365,"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: 72.61625ms
duration: 156.243084ms
- id: 5
request:
proto: HTTP/1.1
Expand All @@ -191,7 +191,7 @@ interactions:
remote_addr: ""
request_uri: ""
body: |
{"public_ids":["tsd-pef-tdc"]}
{"public_ids":["v4c-qnn-3xq"]}
form: {}
headers:
Accept:
Expand All @@ -210,13 +210,13 @@ interactions:
content_length: -1
uncompressed: true
body: |
{"deleted_tests":[{"public_id":"tsd-pef-tdc","deleted_at":"2024-07-03T20:50:15.099977+00:00"}]}
{"deleted_tests":[{"public_id":"v4c-qnn-3xq","deleted_at":"2024-07-05T16:54:35.202662+00:00"}]}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: 1.317489666s
duration: 524.742625ms
- 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/tsd-pef-tdc
url: https://api.datadoghq.com/api/v1/synthetics/tests/v4c-qnn-3xq
method: GET
response:
proto: HTTP/1.1
Expand All @@ -250,4 +250,4 @@ interactions:
- application/json
status: 404 Not Found
code: 404
duration: 79.737125ms
duration: 138.394417ms

0 comments on commit 5fb5801

Please sign in to comment.