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

Add elementsOperator to json path assertion for synthetic HTTP tests #2532

Merged
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
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2024-06-13 08:10:10.481512",
"spec_repo_commit": "eb5da65e"
"regenerated": "2024-06-14 16:03:45.518169",
"spec_repo_commit": "7fc1538c"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-06-13 08:10:10.499687",
"spec_repo_commit": "eb5da65e"
"regenerated": "2024-06-14 16:03:45.536197",
"spec_repo_commit": "7fc1538c"
}
}
}
6 changes: 6 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13759,6 +13759,12 @@ components:
SyntheticsAssertionJSONPathTargetTarget:
description: Composed target for `validatesJSONPath` operator.
properties:
elementsOperator:
description: The element from the list of results to assert on. To choose
from the first element in the list `firstElementMatches`, every element
in the list `everyElementMatches`, at least one element in the list `atLeastOneElementMatches`
or the serialized value of the list `serializationMatches`.
type: string
jsonPath:
description: The JSON path to assert.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

// SyntheticsAssertionJSONPathTargetTarget Composed target for `validatesJSONPath` operator.
type SyntheticsAssertionJSONPathTargetTarget struct {
// The element from the list of results to assert on. To choose from the first element in the list `firstElementMatches`, every element in the list `everyElementMatches`, at least one element in the list `atLeastOneElementMatches` or the serialized value of the list `serializationMatches`.
ElementsOperator *string `json:"elementsOperator,omitempty"`
// The JSON path to assert.
JsonPath *string `json:"jsonPath,omitempty"`
// The specific operator to use on the path.
Expand Down Expand Up @@ -38,6 +40,34 @@ func NewSyntheticsAssertionJSONPathTargetTargetWithDefaults() *SyntheticsAsserti
return &this
}

// GetElementsOperator returns the ElementsOperator field value if set, zero value otherwise.
func (o *SyntheticsAssertionJSONPathTargetTarget) GetElementsOperator() string {
if o == nil || o.ElementsOperator == nil {
var ret string
return ret
}
return *o.ElementsOperator
}

// GetElementsOperatorOk returns a tuple with the ElementsOperator field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *SyntheticsAssertionJSONPathTargetTarget) GetElementsOperatorOk() (*string, bool) {
if o == nil || o.ElementsOperator == nil {
return nil, false
}
return o.ElementsOperator, true
}

// HasElementsOperator returns a boolean if a field has been set.
func (o *SyntheticsAssertionJSONPathTargetTarget) HasElementsOperator() bool {
return o != nil && o.ElementsOperator != nil
}

// SetElementsOperator gets a reference to the given string and assigns it to the ElementsOperator field.
func (o *SyntheticsAssertionJSONPathTargetTarget) SetElementsOperator(v string) {
o.ElementsOperator = &v
}

// GetJsonPath returns the JsonPath field value if set, zero value otherwise.
func (o *SyntheticsAssertionJSONPathTargetTarget) GetJsonPath() string {
if o == nil || o.JsonPath == nil {
Expand Down Expand Up @@ -128,6 +158,9 @@ func (o SyntheticsAssertionJSONPathTargetTarget) MarshalJSON() ([]byte, error) {
if o.UnparsedObject != nil {
return datadog.Marshal(o.UnparsedObject)
}
if o.ElementsOperator != nil {
toSerialize["elementsOperator"] = o.ElementsOperator
}
if o.JsonPath != nil {
toSerialize["jsonPath"] = o.JsonPath
}
Expand All @@ -147,19 +180,21 @@ func (o SyntheticsAssertionJSONPathTargetTarget) MarshalJSON() ([]byte, error) {
// UnmarshalJSON deserializes the given payload.
func (o *SyntheticsAssertionJSONPathTargetTarget) UnmarshalJSON(bytes []byte) (err error) {
all := struct {
JsonPath *string `json:"jsonPath,omitempty"`
Operator *string `json:"operator,omitempty"`
TargetValue interface{} `json:"targetValue,omitempty"`
ElementsOperator *string `json:"elementsOperator,omitempty"`
JsonPath *string `json:"jsonPath,omitempty"`
Operator *string `json:"operator,omitempty"`
TargetValue interface{} `json:"targetValue,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{"jsonPath", "operator", "targetValue"})
datadog.DeleteKeys(additionalProperties, &[]string{"elementsOperator", "jsonPath", "operator", "targetValue"})
} else {
return err
}
o.ElementsOperator = all.ElementsOperator
o.JsonPath = all.JsonPath
o.Operator = all.Operator
o.TargetValue = all.TargetValue
Expand Down
11 changes: 11 additions & 0 deletions examples/v1/synthetics/CreateSyntheticsAPITest_1487281163.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ func main() {
},
Type: datadogV1.SYNTHETICSASSERTIONTYPE_BODY,
}},
datadogV1.SyntheticsAssertion{
SyntheticsAssertionJSONPathTarget: &datadogV1.SyntheticsAssertionJSONPathTarget{
Operator: datadogV1.SYNTHETICSASSERTIONJSONPATHOPERATOR_VALIDATES_JSON_PATH,
Target: &datadogV1.SyntheticsAssertionJSONPathTargetTarget{
ElementsOperator: datadog.PtrString("atLeastOneElementMatches"),
JsonPath: datadog.PtrString("topKey"),
Operator: datadog.PtrString("isNot"),
TargetValue: "0",
},
Type: datadogV1.SYNTHETICSASSERTIONTYPE_BODY,
}},
datadogV1.SyntheticsAssertion{
SyntheticsAssertionJSONSchemaTarget: &datadogV1.SyntheticsAssertionJSONSchemaTarget{
Operator: datadogV1.SYNTHETICSASSERTIONJSONSCHEMAOPERATOR_VALIDATES_JSON_SCHEMA,
Expand Down
11 changes: 11 additions & 0 deletions examples/v1/synthetics/CreateSyntheticsAPITest_1987645492.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ func main() {
},
Type: datadogV1.SYNTHETICSASSERTIONTYPE_BODY,
}},
datadogV1.SyntheticsAssertion{
SyntheticsAssertionJSONPathTarget: &datadogV1.SyntheticsAssertionJSONPathTarget{
Operator: datadogV1.SYNTHETICSASSERTIONJSONPATHOPERATOR_VALIDATES_JSON_PATH,
Target: &datadogV1.SyntheticsAssertionJSONPathTargetTarget{
ElementsOperator: datadog.PtrString("atLeastOneElementMatches"),
JsonPath: datadog.PtrString("topKey"),
Operator: datadog.PtrString("isNot"),
TargetValue: "0",
},
Type: datadogV1.SYNTHETICSASSERTIONTYPE_BODY,
}},
datadogV1.SyntheticsAssertion{
SyntheticsAssertionJSONSchemaTarget: &datadogV1.SyntheticsAssertionJSONSchemaTarget{
Operator: datadogV1.SYNTHETICSASSERTIONJSONSCHEMAOPERATOR_VALIDATES_JSON_SCHEMA,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-06-07T17:11:07.876Z
2024-06-14T15:19:35.860Z
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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":"validatesJSONSchema","target":{"jsonSchema":"{\"type\": \"object\", \"properties\":{\"slideshow\":{\"type\":\"object\"}}}","metaSchema":"draft-07"},"type":"body"},{"operator":"validatesXPath","target":{"operator":"contains","targetValue":"0","xPath":"target-xpath"},"type":"body"},{"operator":"md5","target":"a","type":"bodyHash"}],"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":"testgetasyntheticsmonitorsdetails1717780267"},"method":"GET","persistCookies":true,"proxy":{"headers":{},"url":"https://datadoghq.com"},"timeout":10,"url":"https://datadoghq.com"},"variablesFromScript":"dd.variable.set(\"FOO\", \"foo\")"},"locations":["aws:us-east-2"],"message":"BDD test payload: synthetics_api_http_test_payload.json","name":"Test-Get_a_synthetics_monitor_s_details-1717780267","options":{"accept_self_signed":false,"allow_insecure":true,"follow_redirects":true,"httpVersion":"http2","min_failure_duration":10,"min_location_failed":1,"monitor_name":"Test-Get_a_synthetics_monitor_s_details-1717780267","monitor_priority":5,"retry":{"count":3,"interval":10},"tick_every":60},"subtype":"http","tags":["testing:api"],"type":"api"}
{"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":"validatesJSONPath","target":{"elementsOperator":"atLeastOneElementMatches","jsonPath":"topKey","operator":"isNot","targetValue":"0"},"type":"body"},{"operator":"validatesJSONSchema","target":{"jsonSchema":"{\"type\": \"object\", \"properties\":{\"slideshow\":{\"type\":\"object\"}}}","metaSchema":"draft-07"},"type":"body"},{"operator":"validatesXPath","target":{"operator":"contains","targetValue":"0","xPath":"target-xpath"},"type":"body"},{"operator":"md5","target":"a","type":"bodyHash"}],"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":"testgetasyntheticsmonitorsdetails1718378375"},"method":"GET","persistCookies":true,"proxy":{"headers":{},"url":"https://datadoghq.com"},"timeout":10,"url":"https://datadoghq.com"},"variablesFromScript":"dd.variable.set(\"FOO\", \"foo\")"},"locations":["aws:us-east-2"],"message":"BDD test payload: synthetics_api_http_test_payload.json","name":"Test-Get_a_synthetics_monitor_s_details-1718378375","options":{"accept_self_signed":false,"allow_insecure":true,"follow_redirects":true,"httpVersion":"http2","min_failure_duration":10,"min_location_failed":1,"monitor_name":"Test-Get_a_synthetics_monitor_s_details-1718378375","monitor_priority":5,"retry":{"count":3,"interval":10},"tick_every":60},"subtype":"http","tags":["testing:api"],"type":"api"}
form: {}
headers:
Accept:
Expand All @@ -12,12 +12,10 @@ interactions:
method: POST
url: https://api.datadoghq.com/api/v1/synthetics/tests/api
response:
body: '{"public_id":"345-34e-6z9","name":"Test-Get_a_synthetics_monitor_s_details-1717780267","status":"live","type":"api","tags":["testing:api"],"created_at":"2024-06-07T17:11:08.310477+00:00","modified_at":"2024-06-07T17:11:08.310477+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":"validatesJSONSchema","target":{"jsonSchema":"{\"type\":
\"object\", \"properties\":{\"slideshow\":{\"type\":\"object\"}}}","metaSchema":"draft-07"},"type":"body"},{"operator":"validatesXPath","target":{"operator":"contains","targetValue":"0","xPath":"target-xpath"},"type":"body"},{"operator":"md5","target":"a","type":"bodyHash"}],"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":"testgetasyntheticsmonitorsdetails1717780267"},"method":"GET","persistCookies":true,"proxy":{"headers":{},"url":"https://datadoghq.com"},"timeout":10,"url":"https://datadoghq.com"},"variablesFromScript":"dd.variable.set(\"FOO\",
\"foo\")"},"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-Get_a_synthetics_monitor_s_details-1717780267","monitor_priority":5,"retry":{"count":3,"interval":10},"tick_every":60},"locations":["aws:us-east-2"],"subtype":"http","created_by":{"name":"CI
Account","handle":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","email":"[email protected]"},"deleted_at":null,"monitor_id":146628223,"org_id":321813,"modified_by":{"name":"CI
Account","handle":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","email":"[email protected]"}}'
body: '{"public_id":"8xz-6uh-7qb","name":"Test-Get_a_synthetics_monitor_s_details-1718378375","status":"live","type":"api","tags":["testing:api"],"created_at":"2024-06-14T15:19:36.457734+00:00","modified_at":"2024-06-14T15:19:36.457734+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":"validatesJSONPath","target":{"elementsOperator":"atLeastOneElementMatches","jsonPath":"topKey","operator":"isNot","targetValue":"0"},"type":"body"},{"operator":"validatesJSONSchema","target":{"jsonSchema":"{\"type\":
\"object\", \"properties\":{\"slideshow\":{\"type\":\"object\"}}}","metaSchema":"draft-07"},"type":"body"},{"operator":"validatesXPath","target":{"operator":"contains","targetValue":"0","xPath":"target-xpath"},"type":"body"},{"operator":"md5","target":"a","type":"bodyHash"}],"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":"testgetasyntheticsmonitorsdetails1718378375"},"method":"GET","persistCookies":true,"proxy":{"headers":{},"url":"https://datadoghq.com"},"timeout":10,"url":"https://datadoghq.com"},"variablesFromScript":"dd.variable.set(\"FOO\",
\"foo\")"},"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-Get_a_synthetics_monitor_s_details-1718378375","monitor_priority":5,"retry":{"count":3,"interval":10},"tick_every":60},"locations":["aws:us-east-2"],"subtype":"http","created_by":{"name":null,"handle":"[email protected]","email":"[email protected]"},"deleted_at":null,"monitor_id":147128145,"org_id":321813,"modified_by":{"name":null,"handle":"[email protected]","email":"[email protected]"}}'
code: 200
duration: 0ms
headers:
Expand All @@ -32,11 +30,11 @@ interactions:
- application/json
id: 1
method: GET
url: https://api.datadoghq.com/api/v1/monitor/146628223
url: https://api.datadoghq.com/api/v1/monitor/147128145
response:
body: '{"id":146628223,"org_id":321813,"type":"synthetics alert","name":"Test-Get_a_synthetics_monitor_s_details-1717780267","message":"BDD
test payload: synthetics_api_http_test_payload.json","tags":["testing:api","probe_dc:aws:us-east-2","check_type:api","check_status:live","ci_execution_rule:blocking"],"query":"no_query","options":{"on_missing_data":"show_no_data","notify_audit":false,"new_host_delay":300,"include_tags":true,"synthetics_check_id":"345-34e-6z9","silenced":{}},"multi":false,"created_at":1717780268000,"created":"2024-06-07T17:11:08.287753+00:00","modified":"2024-06-07T17:11:08.287753+00:00","deleted":null,"restricted_roles":null,"priority":5,"overall_state_modified":null,"overall_state":"No
Data","creator":{"name":"CI Account","email":"team-intg-tools-libs-spam@datadoghq.com","handle":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","id":2320499}}
body: '{"id":147128145,"org_id":321813,"type":"synthetics alert","name":"Test-Get_a_synthetics_monitor_s_details-1718378375","message":"BDD
test payload: synthetics_api_http_test_payload.json","tags":["testing:api","probe_dc:aws:us-east-2","check_type:api","check_status:live","ci_execution_rule:blocking"],"query":"no_query","options":{"on_missing_data":"show_no_data","notify_audit":false,"new_host_delay":300,"include_tags":true,"synthetics_check_id":"8xz-6uh-7qb","silenced":{}},"multi":false,"created_at":1718378376000,"created":"2024-06-14T15:19:36.431746+00:00","modified":"2024-06-14T15:19:36.431746+00:00","deleted":null,"restricted_roles":null,"priority":5,"overall_state_modified":null,"overall_state":"No
Data","creator":{"name":null,"email":"frog@datadoghq.com","handle":"[email protected]","id":1445416}}

'
code: 200
Expand All @@ -47,7 +45,7 @@ interactions:
status: 200 OK
- request:
body: |
{"public_ids":["345-34e-6z9"]}
{"public_ids":["8xz-6uh-7qb"]}
form: {}
headers:
Accept:
Expand All @@ -58,7 +56,7 @@ interactions:
method: POST
url: https://api.datadoghq.com/api/v1/synthetics/tests/delete
response:
body: '{"deleted_tests":[{"public_id":"345-34e-6z9","deleted_at":"2024-06-07T17:11:09.164875+00:00"}]}
body: '{"deleted_tests":[{"public_id":"8xz-6uh-7qb","deleted_at":"2024-06-14T15:19:38.234242+00:00"}]}

'
code: 200
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-06-10T13:58:21.100Z
2024-06-14T14:40:25.126Z
Loading
Loading