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] support elementsOperator in JSONPath assertions #2444

Merged
merged 4 commits into from
Jun 18, 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
12 changes: 12 additions & 0 deletions datadog/resource_datadog_synthetics_test_.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,12 @@ func syntheticsAPIAssertion() *schema.Schema {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"elementsoperator": {
Description: "The element from the list of results to assert on. Select from `firstElementMatches` (the first element in the list), `everyElementMatches` (every element in the list), `atLeastOneElementMatches` (at least one element in the list), or `serializationMatches` (the serialized value of the list). Defaults to `firstElementMatches`.",
Type: schema.TypeString,
Optional: true,
Default: "firstElementMatches",
},
"operator": {
Description: "The specific operator to use on the path.",
Type: schema.TypeString,
Expand Down Expand Up @@ -1983,6 +1989,9 @@ func buildAssertions(attr []interface{}) []datadogV1.SyntheticsAssertion {
subTarget.SetTargetValue(v)
}
}
if v, ok := targetMap["elementsoperator"]; ok {
subTarget.SetElementsOperator(v.(string))
}
assertionJSONPathTarget.SetTarget(*subTarget)
}
if _, ok := assertionMap["target"]; ok {
Expand Down Expand Up @@ -2622,6 +2631,9 @@ func buildLocalAssertions(actualAssertions []datadogV1.SyntheticsAssertion) (loc
return localAssertions, fmt.Errorf("unrecognized targetvalue type %v", v)
}
}
if v, ok := target.GetElementsOperatorOk(); ok {
localTarget["elementsoperator"] = string(*v)
}
localAssertion["targetjsonpath"] = []map[string]string{localTarget}
}
if v, ok := assertionTarget.GetTypeOk(); ok {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-06-13T11:40:00.03983+02:00
2024-06-17T17:47:29.27811+02:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-06-13T11:48:41.904633+02:00
2024-06-17T16:29:49.250133+02:00

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions datadog/tests/resource_datadog_synthetics_test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,8 @@ func updateSyntheticsAPITestStepNewAssertionsOptions(ctx context.Context, accPro
"datadog_synthetics_test.bar", "assertion.0.targetjsonpath.0.operator", "isNot"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.bar", "assertion.0.targetjsonpath.0.targetvalue", "0"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.bar", "assertion.0.targetjsonpath.0.elementsoperator", "everyElementMatches"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.bar", "locations.#", "1"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -1836,6 +1838,7 @@ resource "datadog_synthetics_test" "bar" {
type = "body"
operator = "validatesJSONPath"
targetjsonpath {
elementsoperator = "everyElementMatches"
operator = "isNot"
targetvalue = "0"
jsonpath = "topKey"
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/synthetics_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ Required:

Optional:

- `elementsoperator` (String) The element from the list of results to assert on. Select from `firstElementMatches` (the first element in the list), `everyElementMatches` (every element in the list), `atLeastOneElementMatches` (at least one element in the list), or `serializationMatches` (the serialized value of the list). Defaults to `firstElementMatches`. Defaults to `"firstElementMatches"`.
- `targetvalue` (String) Expected matching value.


Expand Down Expand Up @@ -707,6 +708,7 @@ Required:

Optional:

- `elementsoperator` (String) The element from the list of results to assert on. Select from `firstElementMatches` (the first element in the list), `everyElementMatches` (every element in the list), `atLeastOneElementMatches` (at least one element in the list), or `serializationMatches` (the serialized value of the list). Defaults to `firstElementMatches`. Defaults to `"firstElementMatches"`.
- `targetvalue` (String) Expected matching value.


Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/terraform-providers/terraform-provider-datadog

require (
github.com/DataDog/datadog-api-client-go/v2 v2.26.1-0.20240610185644-7125535457c2
github.com/DataDog/datadog-api-client-go/v2 v2.26.1-0.20240614210232-cc3cd19ea44f
github.com/DataDog/dd-sdk-go-testing v0.0.0-20211116174033-1cd082e322ad
github.com/google/uuid v1.5.0
github.com/hashicorp/go-cleanhttp v0.5.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/datadog-api-client-go/v2 v2.26.1-0.20240610185644-7125535457c2 h1:MiYvP649Bbpd9sr2KWhgcRqA45erNJAHHh4smfDobos=
github.com/DataDog/datadog-api-client-go/v2 v2.26.1-0.20240610185644-7125535457c2/go.mod h1:QKOu6vscsh87fMY1lHfLEmNSunyXImj8BUaUWJXOehc=
github.com/DataDog/datadog-api-client-go/v2 v2.26.1-0.20240614210232-cc3cd19ea44f h1:GClzSWYeKzzzqyWHGKW5qYcXfdVSyq4K/YKNyDJe4F0=
github.com/DataDog/datadog-api-client-go/v2 v2.26.1-0.20240614210232-cc3cd19ea44f/go.mod h1:QKOu6vscsh87fMY1lHfLEmNSunyXImj8BUaUWJXOehc=
github.com/DataDog/datadog-go v4.4.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/datadog-go v4.8.3+incompatible h1:fNGaYSuObuQb5nzeTQqowRAd9bpDIRRV4/gUtIBjh8Q=
github.com/DataDog/datadog-go v4.8.3+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
Expand Down
Loading