v1_synthetics_CreateSyntheticsAPITest_1402674167/
v1_synthetics_CreateSyntheticsAPITest_1402674167.rs

1// Create an API GRPC test returns "OK - Returns the created test details."
2// response
3use datadog_api_client::datadog;
4use datadog_api_client::datadogV1::api_synthetics::SyntheticsAPI;
5use datadog_api_client::datadogV1::model::SyntheticsAPITest;
6use datadog_api_client::datadogV1::model::SyntheticsAPITestConfig;
7use datadog_api_client::datadogV1::model::SyntheticsAPITestType;
8use datadog_api_client::datadogV1::model::SyntheticsAssertion;
9use datadog_api_client::datadogV1::model::SyntheticsAssertionOperator;
10use datadog_api_client::datadogV1::model::SyntheticsAssertionTarget;
11use datadog_api_client::datadogV1::model::SyntheticsAssertionTargetValue;
12use datadog_api_client::datadogV1::model::SyntheticsAssertionType;
13use datadog_api_client::datadogV1::model::SyntheticsTestDetailsSubType;
14use datadog_api_client::datadogV1::model::SyntheticsTestOptions;
15use datadog_api_client::datadogV1::model::SyntheticsTestOptionsMonitorOptions;
16use datadog_api_client::datadogV1::model::SyntheticsTestRequest;
17use datadog_api_client::datadogV1::model::SyntheticsTestRequestPort;
18use std::collections::BTreeMap;
19
20#[tokio::main]
21async fn main() {
22    let body = SyntheticsAPITest::new(
23        SyntheticsAPITestConfig::new()
24            .assertions(vec![
25                SyntheticsAssertion::SyntheticsAssertionTarget(Box::new(
26                    SyntheticsAssertionTarget::new(
27                        SyntheticsAssertionOperator::IS,
28                        SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueNumber(
29                            1.0 as f64,
30                        ),
31                        SyntheticsAssertionType::GRPC_HEALTHCHECK_STATUS,
32                    ),
33                )),
34                SyntheticsAssertion::SyntheticsAssertionTarget(Box::new(
35                    SyntheticsAssertionTarget::new(
36                        SyntheticsAssertionOperator::IS,
37                        SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueString(
38                            "proto target".to_string(),
39                        ),
40                        SyntheticsAssertionType::GRPC_PROTO,
41                    ),
42                )),
43                SyntheticsAssertion::SyntheticsAssertionTarget(Box::new(
44                    SyntheticsAssertionTarget::new(
45                        SyntheticsAssertionOperator::IS,
46                        SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueString(
47                            "123".to_string(),
48                        ),
49                        SyntheticsAssertionType::GRPC_METADATA,
50                    )
51                    .property("property".to_string()),
52                )),
53            ])
54            .request(
55                SyntheticsTestRequest::new()
56                    .host("localhost".to_string())
57                    .message("".to_string())
58                    .metadata(BTreeMap::from([]))
59                    .method("GET".to_string())
60                    .port(SyntheticsTestRequestPort::SyntheticsTestRequestNumericalPort(50051))
61                    .service("Hello".to_string()),
62            ),
63        vec!["aws:us-east-2".to_string()],
64        "BDD test payload: synthetics_api_grpc_test_payload.json".to_string(),
65        "Example-Synthetic".to_string(),
66        SyntheticsTestOptions::new()
67            .min_failure_duration(0)
68            .min_location_failed(1)
69            .monitor_name("Example-Synthetic".to_string())
70            .monitor_options(SyntheticsTestOptionsMonitorOptions::new().renotify_interval(0))
71            .tick_every(60),
72        SyntheticsAPITestType::API,
73    )
74    .subtype(SyntheticsTestDetailsSubType::GRPC)
75    .tags(vec!["testing:api".to_string()]);
76    let configuration = datadog::Configuration::new();
77    let api = SyntheticsAPI::with_config(configuration);
78    let resp = api.create_synthetics_api_test(body).await;
79    if let Ok(value) = resp {
80        println!("{:#?}", value);
81    } else {
82        println!("{:#?}", resp.unwrap_err());
83    }
84}