v2_test_optimization_SearchFlakyTests_1224086727/
v2_test-optimization_SearchFlakyTests_1224086727.rs

1// Search flaky tests returns "OK" response with pagination
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/shopist""#.to_string(),
27                            ),
28                        )
29                        .page(
30                            FlakyTestsSearchPageOptions::new()
31                                .cursor(
32                                    "eyJzdGFydEF0IjoiQVFBQUFYS2tMS3pPbm40NGV3QUFBQUJCV0V0clRFdDZVbG8zY3pCRmNsbHJiVmxDWlEifQ==".to_string(),
33                                )
34                                .limit(25),
35                        )
36                        .sort(FlakyTestsSearchSort::FAILURE_RATE_ASCENDING),
37                )
38                .type_(FlakyTestsSearchRequestDataType::SEARCH_FLAKY_TESTS_REQUEST),
39        );
40    let mut configuration = datadog::Configuration::new();
41    configuration.set_unstable_operation_enabled("v2.SearchFlakyTests", true);
42    let api = TestOptimizationAPI::with_config(configuration);
43    let response = api
44        .search_flaky_tests_with_pagination(SearchFlakyTestsOptionalParams::default().body(body));
45    pin_mut!(response);
46    while let Some(resp) = response.next().await {
47        if let Ok(value) = resp {
48            println!("{:#?}", value);
49        } else {
50            println!("{:#?}", resp.unwrap_err());
51        }
52    }
53}