From fabed326bf2f8cc79a7ed6f810b97a6a9309e1b3 Mon Sep 17 00:00:00 2001 From: "ci.datadog-api-spec" Date: Fri, 17 Nov 2023 12:07:33 +0000 Subject: [PATCH] Regenerate client from commit 0686849c of spec repo --- .apigentools-info | 8 +- .generator/schemas/v1/openapi.yaml | 105 +++++++++- api/datadogV1/api_synthetics.go | 74 +++++++ api/datadogV1/doc.go | 1 + .../model_synthetics_patch_test_body.go | 102 ++++++++++ .../model_synthetics_patch_test_operation.go | 182 ++++++++++++++++++ ...el_synthetics_patch_test_operation_name.go | 74 +++++++ examples/v1/synthetics/PatchTest.go | 45 +++++ ..._Synthetic_test_returns_OK_response.freeze | 1 + ..._a_Synthetic_test_returns_OK_response.yaml | 64 ++++++ .../scenarios/features/v1/synthetics.feature | 25 +++ tests/scenarios/features/v1/undo.json | 6 + 12 files changed, 682 insertions(+), 5 deletions(-) create mode 100644 api/datadogV1/model_synthetics_patch_test_body.go create mode 100644 api/datadogV1/model_synthetics_patch_test_operation.go create mode 100644 api/datadogV1/model_synthetics_patch_test_operation_name.go create mode 100644 examples/v1/synthetics/PatchTest.go create mode 100644 tests/scenarios/cassettes/TestScenarios/v1/Feature_Synthetics/Scenario_Patch_a_Synthetic_test_returns_OK_response.freeze create mode 100644 tests/scenarios/cassettes/TestScenarios/v1/Feature_Synthetics/Scenario_Patch_a_Synthetic_test_returns_OK_response.yaml diff --git a/.apigentools-info b/.apigentools-info index ec6e0c55d6b..3e2a5b10cb8 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2023-11-17 11:20:28.325496", - "spec_repo_commit": "04139dfa" + "regenerated": "2023-11-17 12:05:36.502802", + "spec_repo_commit": "0686849c" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2023-11-17 11:20:28.339599", - "spec_repo_commit": "04139dfa" + "regenerated": "2023-11-17 12:05:36.525495", + "spec_repo_commit": "0686849c" } } } \ No newline at end of file diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index 78928c9a5e5..25f744649d5 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -14705,6 +14705,55 @@ components: type: $ref: '#/components/schemas/SyntheticsGlobalVariableParseTestOptionsType' type: object + SyntheticsPatchTestBody: + description: Wrapper around an array of [JSON Patch](https://jsonpatch.com) + operations to perform on the test + properties: + data: + description: Array of [JSON Patch](https://jsonpatch.com) operations to + perform on the test + example: + - op: replace + path: /name + value: New test name + - op: remove + path: /config/assertions/0 + items: + $ref: '#/components/schemas/SyntheticsPatchTestOperation' + type: array + type: object + SyntheticsPatchTestOperation: + description: A single [JSON Patch](https://jsonpatch.com) operation to perform + on the test + properties: + op: + $ref: '#/components/schemas/SyntheticsPatchTestOperationName' + path: + description: The path to the value to modify + example: /name + type: string + value: + description: A value to use in a [JSON Patch](https://jsonpatch.com) operation + example: New Test Name + type: object + SyntheticsPatchTestOperationName: + description: The operation to perform + enum: + - add + - remove + - replace + - move + - copy + - test + example: replace + type: string + x-enum-varnames: + - ADD + - REMOVE + - REPLACE + - MOVE + - COPY + - TEST SyntheticsPlayingTab: description: Navigate between different tabs for your browser test. enum: @@ -29651,7 +29700,7 @@ paths: description: Edit the configuration of a Synthetic browser test. operationId: UpdateBrowserTest parameters: - - description: The public ID of the test to get details from. + - description: The public ID of the test to edit. in: path name: public_id required: true @@ -29990,6 +30039,60 @@ paths: summary: Get a test configuration tags: - Synthetics + patch: + description: Patch the configuration of a Synthetic test with partial data. + operationId: PatchTest + parameters: + - description: The public ID of the test to patch. + in: path + name: public_id + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/SyntheticsPatchTestBody' + description: '[JSON Patch](https://jsonpatch.com/) compliant list of operations' + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/SyntheticsTestDetails' + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: '- JSON format is wrong + + - Updating sub-type is forbidden' + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Forbidden + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: '- Synthetic Monitoring is not activated for the user + + - Test is not owned by the user + + - Test can''t be found' + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Patch a Synthetic test + tags: + - Synthetics + x-codegen-request-body-name: body /api/v1/synthetics/tests/{public_id}/results: get: description: Get the last 150 test results summaries for a given Synthetic API diff --git a/api/datadogV1/api_synthetics.go b/api/datadogV1/api_synthetics.go index 1a8ff34e748..387f6fea5f8 100644 --- a/api/datadogV1/api_synthetics.go +++ b/api/datadogV1/api_synthetics.go @@ -1771,6 +1771,80 @@ func (a *SyntheticsApi) ListTestsWithPagination(ctx _context.Context, o ...ListT return items, cancel } +// PatchTest Patch a Synthetic test. +// Patch the configuration of a Synthetic test with partial data. +func (a *SyntheticsApi) PatchTest(ctx _context.Context, publicId string, body SyntheticsPatchTestBody) (SyntheticsTestDetails, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodPatch + localVarPostBody interface{} + localVarReturnValue SyntheticsTestDetails + ) + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v1.SyntheticsApi.PatchTest") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v1/synthetics/tests/{public_id}" + localVarPath = strings.Replace(localVarPath, "{"+"public_id"+"}", _neturl.PathEscape(datadog.ParameterToString(publicId, "")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + localVarHeaderParams["Content-Type"] = "application/json" + localVarHeaderParams["Accept"] = "application/json" + + // body params + localVarPostBody = &body + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 || localVarHTTPResponse.StatusCode == 429 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + // TriggerCITests Trigger tests from CI/CD pipelines. // Trigger a set of Synthetic tests for continuous integration. func (a *SyntheticsApi) TriggerCITests(ctx _context.Context, body SyntheticsCITestBody) (SyntheticsTriggerCITestsResponse, *_nethttp.Response, error) { diff --git a/api/datadogV1/doc.go b/api/datadogV1/doc.go index db9524a11fa..85245595a3c 100644 --- a/api/datadogV1/doc.go +++ b/api/datadogV1/doc.go @@ -170,6 +170,7 @@ // - [SyntheticsApi.ListGlobalVariables] // - [SyntheticsApi.ListLocations] // - [SyntheticsApi.ListTests] +// - [SyntheticsApi.PatchTest] // - [SyntheticsApi.TriggerCITests] // - [SyntheticsApi.TriggerTests] // - [SyntheticsApi.UpdateAPITest] diff --git a/api/datadogV1/model_synthetics_patch_test_body.go b/api/datadogV1/model_synthetics_patch_test_body.go new file mode 100644 index 00000000000..ec12b03b3eb --- /dev/null +++ b/api/datadogV1/model_synthetics_patch_test_body.go @@ -0,0 +1,102 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV1 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// SyntheticsPatchTestBody Wrapper around an array of [JSON Patch](https://jsonpatch.com) operations to perform on the test +type SyntheticsPatchTestBody struct { + // Array of [JSON Patch](https://jsonpatch.com) operations to perform on the test + Data []SyntheticsPatchTestOperation `json:"data,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} +} + +// NewSyntheticsPatchTestBody instantiates a new SyntheticsPatchTestBody object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewSyntheticsPatchTestBody() *SyntheticsPatchTestBody { + this := SyntheticsPatchTestBody{} + return &this +} + +// NewSyntheticsPatchTestBodyWithDefaults instantiates a new SyntheticsPatchTestBody object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewSyntheticsPatchTestBodyWithDefaults() *SyntheticsPatchTestBody { + this := SyntheticsPatchTestBody{} + return &this +} + +// GetData returns the Data field value if set, zero value otherwise. +func (o *SyntheticsPatchTestBody) GetData() []SyntheticsPatchTestOperation { + if o == nil || o.Data == nil { + var ret []SyntheticsPatchTestOperation + return ret + } + return o.Data +} + +// GetDataOk returns a tuple with the Data field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SyntheticsPatchTestBody) GetDataOk() (*[]SyntheticsPatchTestOperation, bool) { + if o == nil || o.Data == nil { + return nil, false + } + return &o.Data, true +} + +// HasData returns a boolean if a field has been set. +func (o *SyntheticsPatchTestBody) HasData() bool { + return o != nil && o.Data != nil +} + +// SetData gets a reference to the given []SyntheticsPatchTestOperation and assigns it to the Data field. +func (o *SyntheticsPatchTestBody) SetData(v []SyntheticsPatchTestOperation) { + o.Data = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o SyntheticsPatchTestBody) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Data != nil { + toSerialize["data"] = o.Data + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *SyntheticsPatchTestBody) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Data []SyntheticsPatchTestOperation `json:"data,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"data"}) + } else { + return err + } + o.Data = all.Data + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/api/datadogV1/model_synthetics_patch_test_operation.go b/api/datadogV1/model_synthetics_patch_test_operation.go new file mode 100644 index 00000000000..28805e95c3f --- /dev/null +++ b/api/datadogV1/model_synthetics_patch_test_operation.go @@ -0,0 +1,182 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV1 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// SyntheticsPatchTestOperation A single [JSON Patch](https://jsonpatch.com) operation to perform on the test +type SyntheticsPatchTestOperation struct { + // The operation to perform + Op *SyntheticsPatchTestOperationName `json:"op,omitempty"` + // The path to the value to modify + Path *string `json:"path,omitempty"` + // A value to use in a [JSON Patch](https://jsonpatch.com) operation + Value interface{} `json:"value,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} +} + +// NewSyntheticsPatchTestOperation instantiates a new SyntheticsPatchTestOperation object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewSyntheticsPatchTestOperation() *SyntheticsPatchTestOperation { + this := SyntheticsPatchTestOperation{} + return &this +} + +// NewSyntheticsPatchTestOperationWithDefaults instantiates a new SyntheticsPatchTestOperation object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewSyntheticsPatchTestOperationWithDefaults() *SyntheticsPatchTestOperation { + this := SyntheticsPatchTestOperation{} + return &this +} + +// GetOp returns the Op field value if set, zero value otherwise. +func (o *SyntheticsPatchTestOperation) GetOp() SyntheticsPatchTestOperationName { + if o == nil || o.Op == nil { + var ret SyntheticsPatchTestOperationName + return ret + } + return *o.Op +} + +// GetOpOk returns a tuple with the Op field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SyntheticsPatchTestOperation) GetOpOk() (*SyntheticsPatchTestOperationName, bool) { + if o == nil || o.Op == nil { + return nil, false + } + return o.Op, true +} + +// HasOp returns a boolean if a field has been set. +func (o *SyntheticsPatchTestOperation) HasOp() bool { + return o != nil && o.Op != nil +} + +// SetOp gets a reference to the given SyntheticsPatchTestOperationName and assigns it to the Op field. +func (o *SyntheticsPatchTestOperation) SetOp(v SyntheticsPatchTestOperationName) { + o.Op = &v +} + +// GetPath returns the Path field value if set, zero value otherwise. +func (o *SyntheticsPatchTestOperation) GetPath() string { + if o == nil || o.Path == nil { + var ret string + return ret + } + return *o.Path +} + +// GetPathOk returns a tuple with the Path field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SyntheticsPatchTestOperation) GetPathOk() (*string, bool) { + if o == nil || o.Path == nil { + return nil, false + } + return o.Path, true +} + +// HasPath returns a boolean if a field has been set. +func (o *SyntheticsPatchTestOperation) HasPath() bool { + return o != nil && o.Path != nil +} + +// SetPath gets a reference to the given string and assigns it to the Path field. +func (o *SyntheticsPatchTestOperation) SetPath(v string) { + o.Path = &v +} + +// GetValue returns the Value field value if set, zero value otherwise. +func (o *SyntheticsPatchTestOperation) GetValue() interface{} { + if o == nil || o.Value == nil { + var ret interface{} + return ret + } + return o.Value +} + +// GetValueOk returns a tuple with the Value field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SyntheticsPatchTestOperation) GetValueOk() (*interface{}, bool) { + if o == nil || o.Value == nil { + return nil, false + } + return &o.Value, true +} + +// HasValue returns a boolean if a field has been set. +func (o *SyntheticsPatchTestOperation) HasValue() bool { + return o != nil && o.Value != nil +} + +// SetValue gets a reference to the given interface{} and assigns it to the Value field. +func (o *SyntheticsPatchTestOperation) SetValue(v interface{}) { + o.Value = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o SyntheticsPatchTestOperation) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Op != nil { + toSerialize["op"] = o.Op + } + if o.Path != nil { + toSerialize["path"] = o.Path + } + if o.Value != nil { + toSerialize["value"] = o.Value + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *SyntheticsPatchTestOperation) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Op *SyntheticsPatchTestOperationName `json:"op,omitempty"` + Path *string `json:"path,omitempty"` + Value interface{} `json:"value,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"op", "path", "value"}) + } else { + return err + } + + hasInvalidField := false + if all.Op != nil && !all.Op.IsValid() { + hasInvalidField = true + } else { + o.Op = all.Op + } + o.Path = all.Path + o.Value = all.Value + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV1/model_synthetics_patch_test_operation_name.go b/api/datadogV1/model_synthetics_patch_test_operation_name.go new file mode 100644 index 00000000000..cf48d2c236e --- /dev/null +++ b/api/datadogV1/model_synthetics_patch_test_operation_name.go @@ -0,0 +1,74 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV1 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// SyntheticsPatchTestOperationName The operation to perform +type SyntheticsPatchTestOperationName string + +// List of SyntheticsPatchTestOperationName. +const ( + SYNTHETICSPATCHTESTOPERATIONNAME_ADD SyntheticsPatchTestOperationName = "add" + SYNTHETICSPATCHTESTOPERATIONNAME_REMOVE SyntheticsPatchTestOperationName = "remove" + SYNTHETICSPATCHTESTOPERATIONNAME_REPLACE SyntheticsPatchTestOperationName = "replace" + SYNTHETICSPATCHTESTOPERATIONNAME_MOVE SyntheticsPatchTestOperationName = "move" + SYNTHETICSPATCHTESTOPERATIONNAME_COPY SyntheticsPatchTestOperationName = "copy" + SYNTHETICSPATCHTESTOPERATIONNAME_TEST SyntheticsPatchTestOperationName = "test" +) + +var allowedSyntheticsPatchTestOperationNameEnumValues = []SyntheticsPatchTestOperationName{ + SYNTHETICSPATCHTESTOPERATIONNAME_ADD, + SYNTHETICSPATCHTESTOPERATIONNAME_REMOVE, + SYNTHETICSPATCHTESTOPERATIONNAME_REPLACE, + SYNTHETICSPATCHTESTOPERATIONNAME_MOVE, + SYNTHETICSPATCHTESTOPERATIONNAME_COPY, + SYNTHETICSPATCHTESTOPERATIONNAME_TEST, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *SyntheticsPatchTestOperationName) GetAllowedValues() []SyntheticsPatchTestOperationName { + return allowedSyntheticsPatchTestOperationNameEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *SyntheticsPatchTestOperationName) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = SyntheticsPatchTestOperationName(value) + return nil +} + +// NewSyntheticsPatchTestOperationNameFromValue returns a pointer to a valid SyntheticsPatchTestOperationName +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewSyntheticsPatchTestOperationNameFromValue(v string) (*SyntheticsPatchTestOperationName, error) { + ev := SyntheticsPatchTestOperationName(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for SyntheticsPatchTestOperationName: valid values are %v", v, allowedSyntheticsPatchTestOperationNameEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v SyntheticsPatchTestOperationName) IsValid() bool { + for _, existing := range allowedSyntheticsPatchTestOperationNameEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to SyntheticsPatchTestOperationName value. +func (v SyntheticsPatchTestOperationName) Ptr() *SyntheticsPatchTestOperationName { + return &v +} diff --git a/examples/v1/synthetics/PatchTest.go b/examples/v1/synthetics/PatchTest.go new file mode 100644 index 00000000000..a646fc47d64 --- /dev/null +++ b/examples/v1/synthetics/PatchTest.go @@ -0,0 +1,45 @@ +// Patch a Synthetic test returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV1" +) + +func main() { + // there is a valid "synthetics_api_test" in the system + SyntheticsAPITestPublicID := os.Getenv("SYNTHETICS_API_TEST_PUBLIC_ID") + + body := datadogV1.SyntheticsPatchTestBody{ + Data: []datadogV1.SyntheticsPatchTestOperation{ + { + Op: datadogV1.SYNTHETICSPATCHTESTOPERATIONNAME_REPLACE.Ptr(), + Path: datadog.PtrString("/name"), + Value: "New test name", + }, + { + Op: datadogV1.SYNTHETICSPATCHTESTOPERATIONNAME_REMOVE.Ptr(), + Path: datadog.PtrString("/config/assertions/0"), + }, + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV1.NewSyntheticsApi(apiClient) + resp, r, err := api.PatchTest(ctx, SyntheticsAPITestPublicID, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `SyntheticsApi.PatchTest`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `SyntheticsApi.PatchTest`:\n%s\n", responseContent) +} diff --git a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Synthetics/Scenario_Patch_a_Synthetic_test_returns_OK_response.freeze b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Synthetics/Scenario_Patch_a_Synthetic_test_returns_OK_response.freeze new file mode 100644 index 00000000000..43a7d443cc7 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Synthetics/Scenario_Patch_a_Synthetic_test_returns_OK_response.freeze @@ -0,0 +1 @@ +2023-11-15T14:03:15.532Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Synthetics/Scenario_Patch_a_Synthetic_test_returns_OK_response.yaml b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Synthetics/Scenario_Patch_a_Synthetic_test_returns_OK_response.yaml new file mode 100644 index 00000000000..d51773a7502 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Synthetics/Scenario_Patch_a_Synthetic_test_returns_OK_response.yaml @@ -0,0 +1,64 @@ +interactions: +- request: + body: | + {"config":{"assertions":[{"operator":"is","property":"{{ PROPERTY }}","target":"text/html","type":"header"},{"operator":"lessThan","target":2000,"timingsScope":"withoutDNS","type":"responseTime"},{"operator":"validatesJSONPath","target":{"jsonPath":"topKey","operator":"isNot","targetValue":"0"},"type":"body"},{"operator":"validatesXPath","target":{"operator":"contains","targetValue":"0","xPath":"target-xpath"},"type":"body"}],"configVariables":[{"example":"content-type","name":"PROPERTY","pattern":"content-type","type":"text"}],"request":{"basicAuth":{"accessTokenUrl":"https://datadog-token.com","audience":"audience","clientId":"client-id","clientSecret":"client-secret","resource":"resource","scope":"yoyo","tokenApiAuthentication":"header","type":"oauth-client"},"certificate":{"cert":{"content":"cert-content","filename":"cert-filename","updatedAt":"2020-10-16T09:23:24.857Z"},"key":{"content":"key-content","filename":"key-filename","updatedAt":"2020-10-16T09:23:24.857Z"}},"headers":{"unique":"testpatchasyntheticstestreturnsokresponse1700056995"},"method":"GET","persistCookies":true,"proxy":{"headers":{},"url":"https://datadoghq.com"},"timeout":10,"url":"https://datadoghq.com"}},"locations":["aws:us-east-2"],"message":"BDD test payload: synthetics_api_http_test_payload.json","name":"Test-Patch_a_Synthetics_test_returns_OK_response-1700056995","options":{"accept_self_signed":false,"allow_insecure":true,"follow_redirects":true,"httpVersion":"http2","min_failure_duration":10,"min_location_failed":1,"monitor_name":"Test-Patch_a_Synthetics_test_returns_OK_response-1700056995","monitor_priority":5,"retry":{"count":3,"interval":10},"tick_every":60},"subtype":"http","tags":["testing:api"],"type":"api"} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + method: POST + url: https://api.datadoghq.com/api/v1/synthetics/tests/api + response: + body: '{"public_id":"j7s-9tj-9m5","name":"Test-Patch_a_Synthetics_test_returns_OK_response-1700056995","status":"live","type":"api","tags":["testing:api"],"created_at":"2023-11-15T14:03:16.148685+00:00","modified_at":"2023-11-15T14:03:16.148685+00:00","config":{"assertions":[{"operator":"is","property":"{{ + PROPERTY }}","target":"text/html","type":"header"},{"operator":"lessThan","target":2000,"timingsScope":"withoutDNS","type":"responseTime"},{"operator":"validatesJSONPath","target":{"jsonPath":"topKey","operator":"isNot","targetValue":"0"},"type":"body"},{"operator":"validatesXPath","target":{"operator":"contains","targetValue":"0","xPath":"target-xpath"},"type":"body"}],"configVariables":[{"example":"content-type","name":"PROPERTY","pattern":"content-type","type":"text"}],"request":{"basicAuth":{"accessTokenUrl":"https://datadog-token.com","audience":"audience","clientId":"client-id","clientSecret":"client-secret","resource":"resource","scope":"yoyo","tokenApiAuthentication":"header","type":"oauth-client"},"certificate":{"cert":{"filename":"cert-filename","updatedAt":"2020-10-16T09:23:24.857Z"},"key":{"filename":"key-filename","updatedAt":"2020-10-16T09:23:24.857Z"}},"headers":{"unique":"testpatchasyntheticstestreturnsokresponse1700056995"},"method":"GET","persistCookies":true,"proxy":{"headers":{},"url":"https://datadoghq.com"},"timeout":10,"url":"https://datadoghq.com"}},"message":"BDD + test payload: synthetics_api_http_test_payload.json","options":{"accept_self_signed":false,"allow_insecure":true,"follow_redirects":true,"httpVersion":"http2","min_failure_duration":10,"min_location_failed":1,"monitor_name":"Test-Patch_a_Synthetics_test_returns_OK_response-1700056995","monitor_priority":5,"retry":{"count":3,"interval":10},"tick_every":60},"locations":["aws:us-east-2"],"subtype":"http","created_by":{"name":"Frog","handle":"frog@datadoghq.com","email":"frog@datadoghq.com"},"deleted_at":null,"monitor_id":134858209,"org_id":569509,"modified_by":{"name":"Frog","handle":"frog@datadoghq.com","email":"frog@datadoghq.com"}}' + code: 200 + duration: '' + headers: + Content-Type: + - application/json + status: 200 OK +- request: + body: | + {"data":[{"op":"replace","path":"/name","value":"New test name"},{"op":"remove","path":"/config/assertions/0"}]} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + method: PATCH + url: https://api.datadoghq.com/api/v1/synthetics/tests/j7s-9tj-9m5 + response: + body: '{"public_id":"j7s-9tj-9m5","name":"New test name","status":"live","type":"api","tags":["testing:api"],"created_at":"2023-11-15T14:03:16.148685+00:00","modified_at":"2023-11-15T14:03:16.871219+00:00","config":{"assertions":[{"operator":"lessThan","target":2000,"timingsScope":"withoutDNS","type":"responseTime"},{"operator":"validatesJSONPath","target":{"jsonPath":"topKey","operator":"isNot","targetValue":"0"},"type":"body"},{"operator":"validatesXPath","target":{"operator":"contains","targetValue":"0","xPath":"target-xpath"},"type":"body"}],"configVariables":[{"example":"content-type","name":"PROPERTY","pattern":"content-type","type":"text"}],"request":{"basicAuth":{"accessTokenUrl":"https://datadog-token.com","audience":"audience","clientId":"client-id","clientSecret":"client-secret","resource":"resource","scope":"yoyo","tokenApiAuthentication":"header","type":"oauth-client"},"certificate":{"key":{"filename":"key-filename","updatedAt":"2020-10-16T09:23:24.857Z"},"cert":{"filename":"cert-filename","updatedAt":"2020-10-16T09:23:24.857Z"}},"headers":{"unique":"testpatchasyntheticstestreturnsokresponse1700056995"},"method":"GET","persistCookies":true,"proxy":{"headers":{},"url":"https://datadoghq.com"},"timeout":10,"url":"https://datadoghq.com"}},"message":"BDD + test payload: synthetics_api_http_test_payload.json","options":{"accept_self_signed":false,"allow_insecure":true,"follow_redirects":true,"httpVersion":"http2","min_failure_duration":10,"min_location_failed":1,"monitor_name":"Test-Patch_a_Synthetics_test_returns_OK_response-1700056995","monitor_priority":5,"retry":{"count":3,"interval":10},"tick_every":60},"locations":["aws:us-east-2"],"subtype":"http","created_by":{"name":"Frog","handle":"frog@datadoghq.com","email":"frog@datadoghq.com"},"deleted_at":null,"monitor_id":134858209,"org_id":569509,"modified_by":{"name":"Frog","handle":"frog@datadoghq.com","email":"frog@datadoghq.com"}}' + code: 200 + duration: '' + headers: + Content-Type: + - application/json + status: 200 OK +- request: + body: | + {"public_ids":["j7s-9tj-9m5"]} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + method: POST + url: https://api.datadoghq.com/api/v1/synthetics/tests/delete + response: + body: '{"deleted_tests":[{"public_id":"j7s-9tj-9m5","deleted_at":"2023-11-15T14:03:17.553122+00:00"}]} + + ' + code: 200 + duration: '' + headers: + Content-Type: + - application/json + status: 200 OK +version: 1 diff --git a/tests/scenarios/features/v1/synthetics.feature b/tests/scenarios/features/v1/synthetics.feature index 2a081e01c1e..9b707a6ee47 100644 --- a/tests/scenarios/features/v1/synthetics.feature +++ b/tests/scenarios/features/v1/synthetics.feature @@ -554,6 +554,31 @@ Feature: Synthetics When the request is sent Then the response status is 200 OK + @generated @skip @team:DataDog/synthetics-app + Scenario: Patch a Synthetic test returns "- JSON format is wrong" response + Given new "PatchTest" request + And request contains "public_id" parameter from "REPLACE.ME" + And body with value {"data": [{"op": "replace", "path": "/name", "value": "New test name"}, {"op": "remove", "path": "/config/assertions/0"}]} + When the request is sent + Then the response status is 400 - JSON format is wrong + + @generated @skip @team:DataDog/synthetics-app + Scenario: Patch a Synthetic test returns "- Synthetic Monitoring is not activated for the user" response + Given new "PatchTest" request + And request contains "public_id" parameter from "REPLACE.ME" + And body with value {"data": [{"op": "replace", "path": "/name", "value": "New test name"}, {"op": "remove", "path": "/config/assertions/0"}]} + When the request is sent + Then the response status is 404 - Synthetic Monitoring is not activated for the user + + @team:DataDog/synthetics-app + Scenario: Patch a Synthetic test returns "OK" response + Given there is a valid "synthetics_api_test" in the system + And new "PatchTest" request + And request contains "public_id" parameter from "synthetics_api_test.public_id" + And body with value {"data": [{"op": "replace", "path": "/name", "value": "New test name"}, {"op": "remove", "path": "/config/assertions/0"}]} + When the request is sent + Then the response status is 200 OK + @generated @skip @team:DataDog/synthetics-app Scenario: Pause or start a test returns "- Synthetic Monitoring is not activated for the user" response Given new "UpdateTestPauseStatus" request diff --git a/tests/scenarios/features/v1/undo.json b/tests/scenarios/features/v1/undo.json index cb8c824383f..704f278b5cd 100644 --- a/tests/scenarios/features/v1/undo.json +++ b/tests/scenarios/features/v1/undo.json @@ -1196,6 +1196,12 @@ "type": "safe" } }, + "PatchTest": { + "tag": "Synthetics", + "undo": { + "type": "idempotent" + } + }, "GetAPITestLatestResults": { "tag": "Synthetics", "undo": {