Skip to content

Commit

Permalink
[datadog_synthetics_test] Support the bodyHash assertion. (#2431)
Browse files Browse the repository at this point in the history
* Support bodyHash.

* Remove unused fields.

* Update go client.

* Add test.

* Update docs.

* Update test.

* Fix test.

* Fix tests.
  • Loading branch information
jack-edmonds-dd authored Jun 11, 2024
1 parent 8552cf3 commit 835587c
Show file tree
Hide file tree
Showing 15 changed files with 261 additions and 241 deletions.
18 changes: 15 additions & 3 deletions datadog/resource_datadog_synthetics_test_.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func syntheticsAPIAssertion() *schema.Schema {
"type": {
Description: "Type of assertion. **Note** Only some combinations of `type` and `operator` are valid (please refer to [Datadog documentation](https://docs.datadoghq.com/api/latest/synthetics/#create-a-test)).",
Type: schema.TypeString,
ValidateDiagFunc: validators.ValidateEnumValue(datadogV1.NewSyntheticsAssertionTypeFromValue),
ValidateDiagFunc: validators.ValidateEnumValue(datadogV1.NewSyntheticsAssertionTypeFromValue, datadogV1.NewSyntheticsAssertionBodyHashTypeFromValue),
Required: true,
},
"operator": {
Expand Down Expand Up @@ -2595,6 +2595,17 @@ func buildLocalAssertions(actualAssertions []datadogV1.SyntheticsAssertion) (loc
if v, ok := assertionTarget.GetTypeOk(); ok {
localAssertion["type"] = string(*v)
}
} else if assertion.SyntheticsAssertionBodyHashTarget != nil {
assertionTarget := assertion.SyntheticsAssertionBodyHashTarget
if v, ok := assertionTarget.GetOperatorOk(); ok {
localAssertion["operator"] = string(*v)
}
if target := assertionTarget.GetTarget(); target != nil {
localAssertion["target"] = convertToString(target)
}
if v, ok := assertionTarget.GetTypeOk(); ok {
localAssertion["type"] = string(*v)
}
}
localAssertions[i] = localAssertion
}
Expand Down Expand Up @@ -3395,11 +3406,12 @@ func validateSyntheticsAssertionOperator(val interface{}, key string) (warns []s
if err != nil {
_, err2 := datadogV1.NewSyntheticsAssertionJSONPathOperatorFromValue(val.(string))
_, err3 := datadogV1.NewSyntheticsAssertionXPathOperatorFromValue(val.(string))
_, err4 := datadogV1.NewSyntheticsAssertionBodyHashOperatorFromValue(val.(string))

if err2 == nil || err3 == nil {
if err2 == nil || err3 == nil || err4 == nil {
return
} else {
errs = append(errs, err, err2)
errs = append(errs, err, err2, err3, err4)
}
}
return
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-05-03T15:38:42.643125-04:00
2024-06-11T09:12:35.53009-04:00
70 changes: 35 additions & 35 deletions datadog/tests/cassettes/TestAccDatadogSyntheticsAPITest_Basic.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-05-03T15:38:42.643126-04:00
2024-06-11T09:12:35.529963-04:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-05-03T15:38:31.296513-04:00
2024-06-11T09:12:49.827629-04:00
120 changes: 60 additions & 60 deletions datadog/tests/cassettes/TestAccDatadogSyntheticsAPITest_Updated.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-05-03T15:38:31.296496-04:00
2024-06-11T09:12:49.828853-04:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-05-03T15:37:58.818744-04:00
2024-06-10T16:49:39.132063-04:00

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions datadog/tests/resource_datadog_synthetics_test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func TestAccDatadogSyntheticsAPITest_importBasic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: createSyntheticsAPITestConfig(testName, variableName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"datadog_synthetics_test.foo", "assertion.4.operator", "md5"),
),
},
{
ResourceName: "datadog_synthetics_test.foo",
Expand Down Expand Up @@ -730,7 +734,7 @@ func createSyntheticsAPITestStep(ctx context.Context, accProvider func() (*schem
resource.TestCheckResourceAttr(
"datadog_synthetics_test.foo", "variables_from_script", "dd.variable.set('FOO', 'hello');"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.foo", "assertion.#", "4"),
"datadog_synthetics_test.foo", "assertion.#", "5"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.foo", "assertion.0.type", "header"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -884,7 +888,11 @@ resource "datadog_synthetics_test" "foo" {
operator = "doesNotContain"
target = "terraform"
}
assertion {
type = "bodyHash"
operator = "md5"
target = "a"
}
locations = [ "aws:eu-central-1" ]
options_list {
Expand Down
4 changes: 2 additions & 2 deletions docs/resources/synthetics_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ Optional:
Required:

- `operator` (String) Assertion operator. **Note** Only some combinations of `type` and `operator` are valid (please refer to [Datadog documentation](https://docs.datadoghq.com/api/latest/synthetics/#create-a-test)).
- `type` (String) Type of assertion. **Note** Only some combinations of `type` and `operator` are valid (please refer to [Datadog documentation](https://docs.datadoghq.com/api/latest/synthetics/#create-a-test)). Valid values are `body`, `header`, `statusCode`, `certificate`, `responseTime`, `property`, `recordEvery`, `recordSome`, `tlsVersion`, `minTlsVersion`, `latency`, `packetLossPercentage`, `packetsReceived`, `networkHop`, `receivedMessage`, `grpcHealthcheckStatus`, `grpcMetadata`, `grpcProto`, `connection`.
- `type` (String) Type of assertion. **Note** Only some combinations of `type` and `operator` are valid (please refer to [Datadog documentation](https://docs.datadoghq.com/api/latest/synthetics/#create-a-test)). Valid values are `body`, `header`, `statusCode`, `certificate`, `responseTime`, `property`, `recordEvery`, `recordSome`, `tlsVersion`, `minTlsVersion`, `latency`, `packetLossPercentage`, `packetsReceived`, `networkHop`, `receivedMessage`, `grpcHealthcheckStatus`, `grpcMetadata`, `grpcProto`, `connection`, `bodyHash`.

Optional:

Expand Down Expand Up @@ -673,7 +673,7 @@ Optional:
Required:

- `operator` (String) Assertion operator. **Note** Only some combinations of `type` and `operator` are valid (please refer to [Datadog documentation](https://docs.datadoghq.com/api/latest/synthetics/#create-a-test)).
- `type` (String) Type of assertion. **Note** Only some combinations of `type` and `operator` are valid (please refer to [Datadog documentation](https://docs.datadoghq.com/api/latest/synthetics/#create-a-test)). Valid values are `body`, `header`, `statusCode`, `certificate`, `responseTime`, `property`, `recordEvery`, `recordSome`, `tlsVersion`, `minTlsVersion`, `latency`, `packetLossPercentage`, `packetsReceived`, `networkHop`, `receivedMessage`, `grpcHealthcheckStatus`, `grpcMetadata`, `grpcProto`, `connection`.
- `type` (String) Type of assertion. **Note** Only some combinations of `type` and `operator` are valid (please refer to [Datadog documentation](https://docs.datadoghq.com/api/latest/synthetics/#create-a-test)). Valid values are `body`, `header`, `statusCode`, `certificate`, `responseTime`, `property`, `recordEvery`, `recordSome`, `tlsVersion`, `minTlsVersion`, `latency`, `packetLossPercentage`, `packetsReceived`, `networkHop`, `receivedMessage`, `grpcHealthcheckStatus`, `grpcMetadata`, `grpcProto`, `connection`, `bodyHash`.

Optional:

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.20240607153051-dcbfc17c9179
github.com/DataDog/datadog-api-client-go/v2 v2.26.1-0.20240610185644-7125535457c2
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.20240607153051-dcbfc17c9179 h1:1JhH7F3V89jun91SgR0LwpR+ExyML4lOgG5zb4ggo/I=
github.com/DataDog/datadog-api-client-go/v2 v2.26.1-0.20240607153051-dcbfc17c9179/go.mod h1:QKOu6vscsh87fMY1lHfLEmNSunyXImj8BUaUWJXOehc=
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-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

0 comments on commit 835587c

Please sign in to comment.