|
| 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 | +} |
0 commit comments