v2_test_optimization_SearchFlakyTests_2665223746/
v2_test-optimization_SearchFlakyTests_2665223746.rs

1// Search flaky tests returns "OK" response with filtered query
2use datadog_api_client::datadog;
3use datadog_api_client::datadogV2::api_test_optimization::SearchFlakyTestsOptionalParams;
4use datadog_api_client::datadogV2::api_test_optimization::TestOptimizationAPI;
5use datadog_api_client::datadogV2::model::FlakyTestsSearchFilter;
6use datadog_api_client::datadogV2::model::FlakyTestsSearchPageOptions;
7use datadog_api_client::datadogV2::model::FlakyTestsSearchRequest;
8use datadog_api_client::datadogV2::model::FlakyTestsSearchRequestAttributes;
9use datadog_api_client::datadogV2::model::FlakyTestsSearchRequestData;
10use datadog_api_client::datadogV2::model::FlakyTestsSearchRequestDataType;
11use datadog_api_client::datadogV2::model::FlakyTestsSearchSort;
12use futures_util::pin_mut;
13use futures_util::stream::StreamExt;
14
15#[tokio::main]
16async fn main() {
17    let body =
18        FlakyTestsSearchRequest
19        ::new().data(
20            FlakyTestsSearchRequestData::new()
21                .attributes(
22                    FlakyTestsSearchRequestAttributes::new()
23                        .filter(
24                            FlakyTestsSearchFilter
25                            ::new().query(
26                                r#"flaky_test_state:active @git.repository.id_v2:"github.com/datadog/cart-tracking""#.to_string(),
27                            ),
28                        )
29                        .page(FlakyTestsSearchPageOptions::new().limit(10))
30                        .sort(FlakyTestsSearchSort::LAST_FLAKED_DESCENDING),
31                )
32                .type_(FlakyTestsSearchRequestDataType::SEARCH_FLAKY_TESTS_REQUEST),
33        );
34    let mut configuration = datadog::Configuration::new();
35    configuration.set_unstable_operation_enabled("v2.SearchFlakyTests", true);
36    let api = TestOptimizationAPI::with_config(configuration);
37    let response = api
38        .search_flaky_tests_with_pagination(SearchFlakyTestsOptionalParams::default().body(body));
39    pin_mut!(response);
40    while let Some(resp) = response.next().await {
41        if let Ok(value) = resp {
42            println!("{:#?}", value);
43        } else {
44            println!("{:#?}", resp.unwrap_err());
45        }
46    }
47}