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 BDD tests to synthetics #1006

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.4.1.dev8",
"regenerated": "2021-06-17 15:08:44.608594",
"spec_repo_commit": "7f25c3e"
"regenerated": "2021-06-21 15:12:20.452706",
"spec_repo_commit": "8327a94"
},
"v2": {
"apigentools_version": "1.4.1.dev8",
"regenerated": "2021-06-17 15:09:20.119232",
"spec_repo_commit": "7f25c3e"
"regenerated": "2021-06-21 15:12:54.871879",
"spec_repo_commit": "8327a94"
}
}
}
7 changes: 4 additions & 3 deletions api/v1/datadog/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6786,8 +6786,10 @@ paths:
x-codegen-request-body-name: body
x-menu-order: 1
x-undo:
operationId: TODO
parameters: []
operationId: DeleteTests
parameters:
- name: body
template: '{"public_ids": ["{{ public_id }}"]}'
type: unsafe
/api/v1/synthetics/tests/api/{public_id}:
get:
Expand Down Expand Up @@ -29338,7 +29340,6 @@ components:
type: string
targetValue:
description: The path target value to compare to.
type: object
type: object
SyntheticsBrowserTestResultFull_check:
description: Object describing the browser test configuration.
Expand Down
10 changes: 10 additions & 0 deletions api/v1/datadog/docs/SyntheticsAssertionJSONPathTargetTarget.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ SetTargetValue sets TargetValue field to given value.

HasTargetValue returns a boolean if a field has been set.

### SetTargetValueNil

`func (o *SyntheticsAssertionJSONPathTargetTarget) SetTargetValueNil(b bool)`

SetTargetValueNil sets the value for TargetValue to be an explicit nil

### UnsetTargetValue
`func (o *SyntheticsAssertionJSONPathTargetTarget) UnsetTargetValue()`

UnsetTargetValue ensures that no value is present for TargetValue, not even an explicit nil

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2021-06-18T10:17:04.070407+02:00
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
version: 1
interactions:
- request:
body: |
{"config":{"assertions":[{"operator":"contains","property":"content-type","target":"application/json","type":"header"},{"operator":"is","target":200,"type":"statusCode"},{"operator":"validatesJSONPath","target":{"jsonPath":"topKey","operator":"isNot","targetValue":"0"},"type":"body"},{"operator":"validatesJSONPath","target":{"jsonPath":"something","operator":"moreThan","targetValue":5},"type":"body"},{"operator":"isNot","target":200,"type":"statusCode"},{"operator":"matches","target":"20[04]","type":"statusCode"},{"operator":"doesNotMatch","target":"20[04]","type":"statusCode"}],"configVariables":[],"request":{"basicAuth":{"password":"secret","username":"admin"},"body":"this is a body","headers":{"Accept":"application/json"},"method":"GET","query":{"foo":"bar"},"timeout":30,"url":"https://www.datadoghq.com"}},"locations":["aws:eu-central-1"],"message":"Notify @datadog.user","name":"Test-Create_an_API_test_returns_OK_Returns_the_created_test_details_response-1624004224","options":{"follow_redirects":true,"min_location_failed":1,"monitor_options":{"renotify_interval":100},"tick_every":60},"status":"paused","subtype":"http","tags":["foo:bar","baz"],"type":"api"}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
Dd-Operation-Id:
- CreateSyntheticsAPITest
User-Agent:
- datadog-api-client-go/1.1.1+dev (go go1.16.3; os darwin; arch amd64)
X-Datadog-Parent-Id:
- "906676747306173172"
X-Datadog-Sampling-Priority:
- "1"
X-Datadog-Trace-Id:
- "7742831098697937852"
url: https://api.datadoghq.com/api/v1/synthetics/tests/api
method: POST
response:
body: '{"status":"paused","public_id":"27v-yzv-ey5","tags":["foo:bar","baz"],"org_id":321813,"locations":["aws:eu-central-1"],"message":"Notify
@datadog.user","deleted_at":null,"name":"Test-Create_an_API_test_returns_OK_Returns_the_created_test_details_response-1624004224","monitor_id":38897779,"type":"api","created_at":"2021-06-18T08:17:04.695890+00:00","modified_at":"2021-06-18T08:17:04.695890+00:00","subtype":"http","config":{"request":{"body":"this
is a body","url":"https://www.datadoghq.com","basicAuth":{"username":"admin","password":"secret"},"headers":{"Accept":"application/json"},"timeout":30,"query":{"foo":"bar"},"method":"GET"},"assertions":[{"operator":"contains","property":"content-type","type":"header","target":"application/json"},{"operator":"is","type":"statusCode","target":200},{"operator":"validatesJSONPath","type":"body","target":{"operator":"isNot","targetValue":"0","jsonPath":"topKey"}},{"operator":"validatesJSONPath","type":"body","target":{"operator":"moreThan","targetValue":5,"jsonPath":"something"}},{"operator":"isNot","type":"statusCode","target":200},{"operator":"matches","type":"statusCode","target":"20[04]"},{"operator":"doesNotMatch","type":"statusCode","target":"20[04]"}],"configVariables":[]},"options":{"follow_redirects":true,"monitor_options":{"notify_audit":false,"locked":false,"include_tags":true,"new_host_delay":300,"notify_no_data":false,"renotify_interval":100},"min_location_failed":1,"tick_every":60}}'
headers:
Cache-Control:
- no-cache
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Fri, 18 Jun 2021 08:17:04 GMT
Pragma:
- no-cache
Strict-Transport-Security:
- max-age=15724800;
Vary:
- Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Dd-Debug:
- vdJ3/nHEY1ioXQ6pQrBVvsQK1s4yyc+wufBMPSoXql71qZVuP/xMdtNo6DafhOAk
X-Dd-Version:
- "35.4779795"
X-Frame-Options:
- SAMEORIGIN
X-Ratelimit-Limit:
- "120"
X-Ratelimit-Period:
- "60"
X-Ratelimit-Remaining:
- "119"
X-Ratelimit-Reset:
- "56"
status: 200 OK
code: 200
duration: ""
- request:
body: |
{"public_ids":["27v-yzv-ey5"]}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
Dd-Operation-Id:
- DeleteTests
User-Agent:
- datadog-api-client-go/1.1.1+dev (go go1.16.3; os darwin; arch amd64)
X-Datadog-Parent-Id:
- "2245929313999588637"
X-Datadog-Sampling-Priority:
- "1"
X-Datadog-Trace-Id:
- "7742831098697937852"
url: https://api.datadoghq.com/api/v1/synthetics/tests/delete
method: POST
response:
body: '{"deleted_tests":[{"deleted_at":"2021-06-18T08:17:04.852952+00:00","public_id":"27v-yzv-ey5"}]}'
headers:
Cache-Control:
- no-cache
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Fri, 18 Jun 2021 08:17:04 GMT
Pragma:
- no-cache
Strict-Transport-Security:
- max-age=15724800;
Vary:
- Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Dd-Debug:
- twvpGlmuom5y6A0pjGtXzTf554cmwJgTcCZ71fK4H/RDi+v5ehBK0zQiRcTJQG5C
X-Dd-Version:
- "35.4779795"
X-Frame-Options:
- SAMEORIGIN
X-Ratelimit-Limit:
- "120"
X-Ratelimit-Period:
- "60"
X-Ratelimit-Remaining:
- "119"
X-Ratelimit-Reset:
- "56"
status: 200 OK
code: 200
duration: ""
3 changes: 1 addition & 2 deletions tests/api/v1/datadog/features/synthetics.feature
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ Feature: Synthetics
When the request is sent
Then the response status is 400 - JSON format is wrong

@generated @skip
Scenario: Create an API test returns "OK - Returns the created test details." response
Given new "CreateSyntheticsAPITest" request
And body with value {"config": {"assertions": [], "configVariables": [{"example": null, "id": null, "name": "VARIABLE_NAME", "pattern": null, "type": "global"}], "request": {"basicAuth": {"password": "", "username": ""}, "body": null, "certificate": {"cert": {"content": null, "filename": null, "updatedAt": null}, "key": {"content": null, "filename": null, "updatedAt": null}}, "dnsServer": null, "dnsServerPort": null, "headers": null, "host": null, "method": "GET", "noSavingResponseBody": null, "numberOfPackets": null, "port": null, "query": null, "shouldTrackHops": null, "timeout": null, "url": null}, "steps": [{"allowFailure": null, "assertions": [], "extractedValues": [{"field": "content-type", "name": null, "parser": {"type": "regex", "value": ".*"}, "type": "http_body"}], "isCritical": null, "name": null, "request": {"basicAuth": {"password": "", "username": ""}, "body": null, "certificate": {"cert": {"content": null, "filename": null, "updatedAt": null}, "key": {"content": null, "filename": null, "updatedAt": null}}, "dnsServer": null, "dnsServerPort": null, "headers": null, "host": null, "method": "GET", "noSavingResponseBody": null, "numberOfPackets": null, "port": null, "query": null, "shouldTrackHops": null, "timeout": null, "url": null}, "subtype": "http"}]}, "locations": [null], "message": null, "name": null, "options": {"accept_self_signed": null, "allow_insecure": null, "device_ids": ["laptop_large"], "disableCors": null, "follow_redirects": null, "min_failure_duration": null, "min_location_failed": null, "monitor_name": null, "monitor_options": {"renotify_interval": null}, "monitor_priority": null, "noScreenshot": null, "retry": {"count": null, "interval": null}, "tick_every": 30}, "status": "live", "subtype": "http", "tags": [null], "type": "api"}
And body with value {"config":{"assertions":[{"operator":"contains","property":"content-type","target":"application/json","type":"header"},{"operator":"is","target":200,"type":"statusCode"},{"operator":"validatesJSONPath","target":{"jsonPath":"topKey","operator":"isNot","targetValue":"0"},"type":"body"},{"operator":"validatesJSONPath","target":{"jsonPath":"something","operator":"moreThan","targetValue":5},"type":"body"},{"operator":"isNot","target":200,"type":"statusCode"},{"operator":"matches","target":"20[04]","type":"statusCode"},{"operator":"doesNotMatch","target":"20[04]","type":"statusCode"}],"configVariables":[],"request":{"basicAuth":{"password":"secret","username":"admin"},"body":"this is a body","headers":{"Accept":"application/json"},"method":"GET","query":{"foo":"bar"},"timeout":30,"url":"https://www.datadoghq.com"}},"locations":["aws:eu-central-1"],"message":"Notify @datadog.user","name":"{{ unique }}","options":{"follow_redirects":true,"min_location_failed":1,"monitor_options":{"renotify_interval":100},"tick_every":60},"status":"paused","subtype":"http","tags":["foo:bar","baz"],"type":"api"}
When the request is sent
Then the response status is 200 OK - Returns the created test details.

Expand Down
9 changes: 7 additions & 2 deletions tests/api/v1/datadog/features/undo.json
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,13 @@
"CreateSyntheticsAPITest": {
"tag": "Synthetics",
"undo": {
"operationId": "TODO",
"parameters": [],
"operationId": "DeleteTests",
"parameters": [
{
"name": "body",
"template": "{\"public_ids\": [\"{{ public_id }}\"]}"
}
],
"type": "unsafe"
}
},
Expand Down
23 changes: 17 additions & 6 deletions tests/scenarios.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ type UndoAction struct {
Type string `json:"type"`
OperationID string `json:"operationId"`
Parameters []struct {
Name string `json:"name"`
Source string `json:"source"`
Name string `json:"name"`
Source string `json:"source"`
Template string `json:"template"`
} `json:"parameters"`
} `json:"undo"`
}
Expand Down Expand Up @@ -393,11 +394,21 @@ func GetRequestsUndo(ctx gobdd.Context, operationID string) (func([]reflect.Valu
}

for i := 1; i < undoOperation.Type().NumIn() && i <= len(undo.Undo.Parameters); i++ {
object, err := lookup.LookupStringI(responseJSON, undo.Undo.Parameters[i-1].Source)
if err != nil {
t.Fatalf("%v", err)
if undo.Undo.Parameters[i-1].Source != "" {
object, err := lookup.LookupStringI(responseJSON, undo.Undo.Parameters[i-1].Source)
if err != nil {
t.Fatalf("%v", err)
}
in[i] = object.Convert(undoOperation.Type().In(i))
} else if undo.Undo.Parameters[i-1].Template != "" {
data := Templated(t, responseJSON.(map[string]interface{}), undo.Undo.Parameters[i-1].Template)
object := reflect.New(undoOperation.Type().In(i))
err := json.Unmarshal([]byte(data), object.Interface())
if err != nil {
t.Fatalf("%v", err)
}
in[i] = object.Elem()
}
in[i] = object.Convert(undoOperation.Type().In(i))
}

result := undoOperation.Call(in)
Expand Down