Skip to content

Commit a6897f3

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add subtest for synthetics multistep tests (#1114)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 841e2ae commit a6897f3

10 files changed

+627
-0
lines changed

.generator/schemas/v1/openapi.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14766,6 +14766,61 @@ components:
1476614766
oneOf:
1476714767
- $ref: '#/components/schemas/SyntheticsAPITestStep'
1476814768
- $ref: '#/components/schemas/SyntheticsAPIWaitStep'
14769+
- $ref: '#/components/schemas/SyntheticsAPISubtestStep'
14770+
SyntheticsAPISubtestStep:
14771+
description: The subtest step used in a Synthetics multi-step API test.
14772+
properties:
14773+
allowFailure:
14774+
description: Determines whether or not to continue with test if this step
14775+
fails.
14776+
type: boolean
14777+
alwaysExecute:
14778+
description: A boolean set to always execute this step even if the previous
14779+
step failed or was skipped.
14780+
type: boolean
14781+
exitIfSucceed:
14782+
description: Determines whether or not to exit the test if the step succeeds.
14783+
type: boolean
14784+
extractedValuesFromScript:
14785+
description: Generate variables using JavaScript.
14786+
type: string
14787+
id:
14788+
description: ID of the step.
14789+
example: abc-def-123
14790+
readOnly: true
14791+
type: string
14792+
isCritical:
14793+
description: 'Determines whether or not to consider the entire test as failed
14794+
if this step fails.
14795+
14796+
Can be used only if `allowFailure` is `true`.'
14797+
type: boolean
14798+
name:
14799+
description: The name of the step.
14800+
example: Example step name
14801+
type: string
14802+
retry:
14803+
$ref: '#/components/schemas/SyntheticsTestOptionsRetry'
14804+
subtestPublicId:
14805+
description: Public ID of the test to be played as part of a `playSubTest`
14806+
step type.
14807+
example: ''
14808+
type: string
14809+
subtype:
14810+
$ref: '#/components/schemas/SyntheticsAPISubtestStepSubtype'
14811+
required:
14812+
- name
14813+
- subtype
14814+
- subtestPublicId
14815+
type: object
14816+
SyntheticsAPISubtestStepSubtype:
14817+
description: The subtype of the Synthetic multi-step API subtest step.
14818+
enum:
14819+
- playSubTest
14820+
example: playSubTest
14821+
type: string
14822+
x-enum-varnames:
14823+
- PLAY_SUB_TEST
1476914824
SyntheticsAPITest:
1477014825
description: Object containing details about a Synthetic API test.
1477114826
properties:
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Create a multistep test with subtest returns "OK" response
2+
use datadog_api_client::datadog;
3+
use datadog_api_client::datadogV1::api_synthetics::SyntheticsAPI;
4+
use datadog_api_client::datadogV1::model::SyntheticsAPIStep;
5+
use datadog_api_client::datadogV1::model::SyntheticsAPISubtestStep;
6+
use datadog_api_client::datadogV1::model::SyntheticsAPISubtestStepSubtype;
7+
use datadog_api_client::datadogV1::model::SyntheticsAPITest;
8+
use datadog_api_client::datadogV1::model::SyntheticsAPITestConfig;
9+
use datadog_api_client::datadogV1::model::SyntheticsAPITestStep;
10+
use datadog_api_client::datadogV1::model::SyntheticsAPITestStepSubtype;
11+
use datadog_api_client::datadogV1::model::SyntheticsAPITestType;
12+
use datadog_api_client::datadogV1::model::SyntheticsAssertion;
13+
use datadog_api_client::datadogV1::model::SyntheticsAssertionOperator;
14+
use datadog_api_client::datadogV1::model::SyntheticsAssertionTarget;
15+
use datadog_api_client::datadogV1::model::SyntheticsAssertionTargetValue;
16+
use datadog_api_client::datadogV1::model::SyntheticsAssertionType;
17+
use datadog_api_client::datadogV1::model::SyntheticsBasicAuth;
18+
use datadog_api_client::datadogV1::model::SyntheticsBasicAuthWeb;
19+
use datadog_api_client::datadogV1::model::SyntheticsTestDetailsSubType;
20+
use datadog_api_client::datadogV1::model::SyntheticsTestOptions;
21+
use datadog_api_client::datadogV1::model::SyntheticsTestRequest;
22+
23+
#[tokio::main]
24+
async fn main() {
25+
// there is a valid "synthetics_api_test" in the system
26+
let synthetics_api_test_public_id = std::env::var("SYNTHETICS_API_TEST_PUBLIC_ID").unwrap();
27+
let body = SyntheticsAPITest::new(
28+
SyntheticsAPITestConfig::new().steps(vec![
29+
SyntheticsAPIStep::SyntheticsAPITestStep(Box::new(SyntheticsAPITestStep::new(
30+
vec![SyntheticsAssertion::SyntheticsAssertionTarget(Box::new(
31+
SyntheticsAssertionTarget::new(
32+
SyntheticsAssertionOperator::IS,
33+
SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueNumber(
34+
200.0 as f64,
35+
),
36+
SyntheticsAssertionType::STATUS_CODE,
37+
),
38+
))],
39+
"request is sent".to_string(),
40+
SyntheticsTestRequest::new()
41+
.basic_auth(SyntheticsBasicAuth::SyntheticsBasicAuthWeb(Box::new(
42+
SyntheticsBasicAuthWeb::new()
43+
.password("password".to_string())
44+
.username("username".to_string()),
45+
)))
46+
.method("GET".to_string())
47+
.url("https://httpbin.org/status/200".to_string()),
48+
SyntheticsAPITestStepSubtype::HTTP,
49+
))),
50+
SyntheticsAPIStep::SyntheticsAPISubtestStep(Box::new(SyntheticsAPISubtestStep::new(
51+
"subtest step".to_string(),
52+
synthetics_api_test_public_id.clone(),
53+
SyntheticsAPISubtestStepSubtype::PLAY_SUB_TEST,
54+
))),
55+
]),
56+
vec!["aws:us-east-2".to_string()],
57+
"BDD test payload: synthetics_api_test_multi_step_with_subtest.json".to_string(),
58+
"Example-Synthetic".to_string(),
59+
SyntheticsTestOptions::new().tick_every(60),
60+
SyntheticsAPITestType::API,
61+
)
62+
.subtype(SyntheticsTestDetailsSubType::MULTI);
63+
let configuration = datadog::Configuration::new();
64+
let api = SyntheticsAPI::with_config(configuration);
65+
let resp = api.create_synthetics_api_test(body).await;
66+
if let Ok(value) = resp {
67+
println!("{:#?}", value);
68+
} else {
69+
println!("{:#?}", resp.unwrap_err());
70+
}
71+
}

src/datadogV1/model/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,10 @@ pub mod model_synthetics_api_wait_step;
15521552
pub use self::model_synthetics_api_wait_step::SyntheticsAPIWaitStep;
15531553
pub mod model_synthetics_api_wait_step_subtype;
15541554
pub use self::model_synthetics_api_wait_step_subtype::SyntheticsAPIWaitStepSubtype;
1555+
pub mod model_synthetics_api_subtest_step;
1556+
pub use self::model_synthetics_api_subtest_step::SyntheticsAPISubtestStep;
1557+
pub mod model_synthetics_api_subtest_step_subtype;
1558+
pub use self::model_synthetics_api_subtest_step_subtype::SyntheticsAPISubtestStepSubtype;
15551559
pub mod model_synthetics_api_step;
15561560
pub use self::model_synthetics_api_step::SyntheticsAPIStep;
15571561
pub mod model_synthetics_api_test_type;

src/datadogV1/model/model_synthetics_api_step.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use serde::{Deserialize, Deserializer, Serialize};
1010
pub enum SyntheticsAPIStep {
1111
SyntheticsAPITestStep(Box<crate::datadogV1::model::SyntheticsAPITestStep>),
1212
SyntheticsAPIWaitStep(Box<crate::datadogV1::model::SyntheticsAPIWaitStep>),
13+
SyntheticsAPISubtestStep(Box<crate::datadogV1::model::SyntheticsAPISubtestStep>),
1314
UnparsedObject(crate::datadog::UnparsedObject),
1415
}
1516

@@ -33,6 +34,14 @@ impl<'de> Deserialize<'de> for SyntheticsAPIStep {
3334
return Ok(SyntheticsAPIStep::SyntheticsAPIWaitStep(_v));
3435
}
3536
}
37+
if let Ok(_v) = serde_json::from_value::<
38+
Box<crate::datadogV1::model::SyntheticsAPISubtestStep>,
39+
>(value.clone())
40+
{
41+
if !_v._unparsed {
42+
return Ok(SyntheticsAPIStep::SyntheticsAPISubtestStep(_v));
43+
}
44+
}
3645

3746
return Ok(SyntheticsAPIStep::UnparsedObject(
3847
crate::datadog::UnparsedObject { value },

0 commit comments

Comments
 (0)