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 JSONSchema assertion support to API and multistep tests #52

Merged
Merged
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
@@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2024-04-19 20:49:39.245621",
"spec_repo_commit": "c3db9ec1"
"regenerated": "2024-04-22 11:29:42.562557",
"spec_repo_commit": "0f37d2e6"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-04-19 20:49:39.263464",
"spec_repo_commit": "c3db9ec1"
"regenerated": "2024-04-22 11:29:42.579972",
"spec_repo_commit": "0f37d2e6"
}
}
}
40 changes: 40 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
@@ -13627,6 +13627,7 @@ components:
oneOf:
- $ref: '#/components/schemas/SyntheticsAssertionTarget'
- $ref: '#/components/schemas/SyntheticsAssertionJSONPathTarget'
- $ref: '#/components/schemas/SyntheticsAssertionJSONSchemaTarget'
- $ref: '#/components/schemas/SyntheticsAssertionXPathTarget'
SyntheticsAssertionJSONPathOperator:
description: Assertion operator to apply.
@@ -13664,6 +13665,45 @@ components:
targetValue:
description: The path target value to compare to.
type: object
SyntheticsAssertionJSONSchemaMetaSchema:
description: The JSON Schema meta-schema version used in the assertion.
enum:
- draft-07
- draft-06
type: string
x-enum-varnames:
- DRAFT_07
- DRAFT_06
SyntheticsAssertionJSONSchemaOperator:
description: Assertion operator to apply.
enum:
- validatesJSONSchema
example: validatesJSONSchema
type: string
x-enum-varnames:
- VALIDATES_JSON_SCHEMA
SyntheticsAssertionJSONSchemaTarget:
description: An assertion for the `validatesJSONSchema` operator.
properties:
operator:
$ref: '#/components/schemas/SyntheticsAssertionJSONSchemaOperator'
target:
$ref: '#/components/schemas/SyntheticsAssertionJSONSchemaTargetTarget'
type:
$ref: '#/components/schemas/SyntheticsAssertionType'
required:
- type
- operator
type: object
SyntheticsAssertionJSONSchemaTargetTarget:
description: Composed target for `validatesJSONSchema` operator.
properties:
jsonSchema:
description: The JSON Schema to assert.
type: string
metaSchema:
$ref: '#/components/schemas/SyntheticsAssertionJSONSchemaMetaSchema'
type: object
SyntheticsAssertionOperator:
description: Assertion operator to apply.
enum:
252 changes: 137 additions & 115 deletions examples/v1_synthetics_create_synthetics_api_test_1487281163.rs
Original file line number Diff line number Diff line change
@@ -9,6 +9,10 @@ use datadog_api_client::datadogV1::model::SyntheticsAssertion;
use datadog_api_client::datadogV1::model::SyntheticsAssertionJSONPathOperator;
use datadog_api_client::datadogV1::model::SyntheticsAssertionJSONPathTarget;
use datadog_api_client::datadogV1::model::SyntheticsAssertionJSONPathTargetTarget;
use datadog_api_client::datadogV1::model::SyntheticsAssertionJSONSchemaMetaSchema;
use datadog_api_client::datadogV1::model::SyntheticsAssertionJSONSchemaOperator;
use datadog_api_client::datadogV1::model::SyntheticsAssertionJSONSchemaTarget;
use datadog_api_client::datadogV1::model::SyntheticsAssertionJSONSchemaTargetTarget;
use datadog_api_client::datadogV1::model::SyntheticsAssertionOperator;
use datadog_api_client::datadogV1::model::SyntheticsAssertionTarget;
use datadog_api_client::datadogV1::model::SyntheticsAssertionTimingsScope;
@@ -35,123 +39,141 @@ use std::collections::BTreeMap;

#[tokio::main]
async fn main() {
let body = SyntheticsAPITest::new(
SyntheticsAPITestConfig::new()
.assertions(vec![
SyntheticsAssertion::SyntheticsAssertionTarget(Box::new(
SyntheticsAssertionTarget::new(
SyntheticsAssertionOperator::IS,
Value::from("text/html"),
SyntheticsAssertionType::HEADER,
)
.property("{{ PROPERTY }}".to_string()),
)),
SyntheticsAssertion::SyntheticsAssertionTarget(Box::new(
SyntheticsAssertionTarget::new(
SyntheticsAssertionOperator::LESS_THAN,
Value::from(2000),
SyntheticsAssertionType::RESPONSE_TIME,
)
.timings_scope(SyntheticsAssertionTimingsScope::WITHOUT_DNS),
)),
SyntheticsAssertion::SyntheticsAssertionJSONPathTarget(Box::new(
SyntheticsAssertionJSONPathTarget::new(
SyntheticsAssertionJSONPathOperator::VALIDATES_JSON_PATH,
SyntheticsAssertionType::BODY,
)
.target(
SyntheticsAssertionJSONPathTargetTarget::new()
.json_path("topKey".to_string())
.operator("isNot".to_string())
.target_value(Value::from("0")),
),
)),
SyntheticsAssertion::SyntheticsAssertionXPathTarget(Box::new(
SyntheticsAssertionXPathTarget::new(
SyntheticsAssertionXPathOperator::VALIDATES_X_PATH,
SyntheticsAssertionType::BODY,
)
.target(
SyntheticsAssertionXPathTargetTarget::new()
.operator("contains".to_string())
.target_value(Value::from("0"))
.x_path("target-xpath".to_string()),
),
)),
])
.config_variables(vec![SyntheticsConfigVariable::new(
"PROPERTY".to_string(),
SyntheticsConfigVariableType::TEXT,
)
.example("content-type".to_string())
.pattern("content-type".to_string())])
.request(
SyntheticsTestRequest::new()
.basic_auth(SyntheticsBasicAuth::SyntheticsBasicAuthOauthClient(
Box::new(
SyntheticsBasicAuthOauthClient::new(
"https://datadog-token.com".to_string(),
"client-id".to_string(),
"client-secret".to_string(),
SyntheticsBasicAuthOauthTokenApiAuthentication::HEADER,
)
.audience("audience".to_string())
.resource("resource".to_string())
.scope("yoyo".to_string())
.type_(SyntheticsBasicAuthOauthClientType::OAUTH_CLIENT),
let body =
SyntheticsAPITest::new(
SyntheticsAPITestConfig::new()
.assertions(
vec![
SyntheticsAssertion::SyntheticsAssertionTarget(
Box::new(
SyntheticsAssertionTarget::new(
SyntheticsAssertionOperator::IS,
Value::from("text/html"),
SyntheticsAssertionType::HEADER,
).property("{{ PROPERTY }}".to_string()),
),
),
SyntheticsAssertion::SyntheticsAssertionTarget(
Box::new(
SyntheticsAssertionTarget::new(
SyntheticsAssertionOperator::LESS_THAN,
Value::from(2000),
SyntheticsAssertionType::RESPONSE_TIME,
).timings_scope(SyntheticsAssertionTimingsScope::WITHOUT_DNS),
),
),
SyntheticsAssertion::SyntheticsAssertionJSONPathTarget(
Box::new(
SyntheticsAssertionJSONPathTarget::new(
SyntheticsAssertionJSONPathOperator::VALIDATES_JSON_PATH,
SyntheticsAssertionType::BODY,
).target(
SyntheticsAssertionJSONPathTargetTarget::new()
.json_path("topKey".to_string())
.operator("isNot".to_string())
.target_value(Value::from("0")),
),
),
),
SyntheticsAssertion::SyntheticsAssertionJSONSchemaTarget(
Box::new(
SyntheticsAssertionJSONSchemaTarget::new(
SyntheticsAssertionJSONSchemaOperator::VALIDATES_JSON_SCHEMA,
SyntheticsAssertionType::BODY,
).target(
SyntheticsAssertionJSONSchemaTargetTarget::new()
.json_schema(
r#"{"type": "object", "properties":{"slideshow":{"type":"object"}}}"#.to_string(),
)
.meta_schema(SyntheticsAssertionJSONSchemaMetaSchema::DRAFT_07),
),
),
),
))
.certificate(
SyntheticsTestRequestCertificate::new()
.cert(
SyntheticsTestRequestCertificateItem::new()
.content("cert-content".to_string())
.filename("cert-filename".to_string())
.updated_at("2020-10-16T09:23:24.857Z".to_string()),
)
.key(
SyntheticsTestRequestCertificateItem::new()
.content("key-content".to_string())
.filename("key-filename".to_string())
.updated_at("2020-10-16T09:23:24.857Z".to_string()),
SyntheticsAssertion::SyntheticsAssertionXPathTarget(
Box::new(
SyntheticsAssertionXPathTarget::new(
SyntheticsAssertionXPathOperator::VALIDATES_X_PATH,
SyntheticsAssertionType::BODY,
).target(
SyntheticsAssertionXPathTargetTarget::new()
.operator("contains".to_string())
.target_value(Value::from("0"))
.x_path("target-xpath".to_string()),
),
),
)
],
)
.config_variables(
vec![
SyntheticsConfigVariable::new("PROPERTY".to_string(), SyntheticsConfigVariableType::TEXT)
.example("content-type".to_string())
.pattern("content-type".to_string())
],
)
.request(
SyntheticsTestRequest::new()
.basic_auth(
SyntheticsBasicAuth::SyntheticsBasicAuthOauthClient(
Box::new(
SyntheticsBasicAuthOauthClient::new(
"https://datadog-token.com".to_string(),
"client-id".to_string(),
"client-secret".to_string(),
SyntheticsBasicAuthOauthTokenApiAuthentication::HEADER,
)
.audience("audience".to_string())
.resource("resource".to_string())
.scope("yoyo".to_string())
.type_(SyntheticsBasicAuthOauthClientType::OAUTH_CLIENT),
),
),
)
.headers(BTreeMap::from([(
"unique".to_string(),
"examplesynthetic".to_string(),
)]))
.method("GET".to_string())
.persist_cookies(true)
.proxy(
SyntheticsTestRequestProxy::new("https://datadoghq.com".to_string())
.headers(BTreeMap::from([])),
)
.timeout(10.0 as f64)
.url("https://datadoghq.com".to_string()),
)
.variables_from_script(r#"dd.variable.set("FOO", "foo")"#.to_string()),
vec!["aws:us-east-2".to_string()],
"BDD test payload: synthetics_api_http_test_payload.json".to_string(),
"Example-Synthetic".to_string(),
SyntheticsTestOptions::new()
.accept_self_signed(false)
.allow_insecure(true)
.follow_redirects(true)
.http_version(SyntheticsTestOptionsHTTPVersion::HTTP2)
.min_failure_duration(10)
.min_location_failed(1)
.monitor_name("Example-Synthetic".to_string())
.monitor_priority(5)
.retry(
SyntheticsTestOptionsRetry::new()
.count(3)
.interval(10.0 as f64),
)
.tick_every(60),
SyntheticsAPITestType::API,
)
.subtype(SyntheticsTestDetailsSubType::HTTP)
.tags(vec!["testing:api".to_string()]);
)
.certificate(
SyntheticsTestRequestCertificate::new()
.cert(
SyntheticsTestRequestCertificateItem::new()
.content("cert-content".to_string())
.filename("cert-filename".to_string())
.updated_at("2020-10-16T09:23:24.857Z".to_string()),
)
.key(
SyntheticsTestRequestCertificateItem::new()
.content("key-content".to_string())
.filename("key-filename".to_string())
.updated_at("2020-10-16T09:23:24.857Z".to_string()),
),
)
.headers(BTreeMap::from([("unique".to_string(), "examplesynthetic".to_string())]))
.method("GET".to_string())
.persist_cookies(true)
.proxy(
SyntheticsTestRequestProxy::new(
"https://datadoghq.com".to_string(),
).headers(BTreeMap::from([])),
)
.timeout(10.0 as f64)
.url("https://datadoghq.com".to_string()),
)
.variables_from_script(r#"dd.variable.set("FOO", "foo")"#.to_string()),
vec!["aws:us-east-2".to_string()],
"BDD test payload: synthetics_api_http_test_payload.json".to_string(),
"Example-Synthetic".to_string(),
SyntheticsTestOptions::new()
.accept_self_signed(false)
.allow_insecure(true)
.follow_redirects(true)
.http_version(SyntheticsTestOptionsHTTPVersion::HTTP2)
.min_failure_duration(10)
.min_location_failed(1)
.monitor_name("Example-Synthetic".to_string())
.monitor_priority(5)
.retry(SyntheticsTestOptionsRetry::new().count(3).interval(10.0 as f64))
.tick_every(60),
SyntheticsAPITestType::API,
)
.subtype(SyntheticsTestDetailsSubType::HTTP)
.tags(vec!["testing:api".to_string()]);
let configuration = datadog::Configuration::new();
let api = SyntheticsAPI::with_config(configuration);
let resp = api.create_synthetics_api_test(body).await;
Loading
Loading