datadog_api_client/datadogV2/model/
model_flaky_test_attributes.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9/// Attributes of a flaky test.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct FlakyTestAttributes {
14    /// Unique identifier for the attempt to fix this flaky test. Use this ID in the Git commit message in order to trigger the attempt to fix workflow.
15    ///
16    /// When the workflow is triggered the test is automatically retried by the tracer a certain number of configurable times. When all retries pass, the test is automatically marked as fixed in Flaky Test Management.
17    /// Test runs are tagged with @test.test_management.attempt_to_fix_passed and @test.test_management.is_attempt_to_fix when the attempt to fix workflow is triggered.
18    #[serde(rename = "attempt_to_fix_id")]
19    pub attempt_to_fix_id: Option<String>,
20    /// The name of the test's code owners as inferred from the repository configuration.
21    #[serde(rename = "codeowners")]
22    pub codeowners: Option<Vec<String>>,
23    /// List of environments where this test has been flaky.
24    #[serde(rename = "envs")]
25    pub envs: Option<Vec<String>>,
26    /// The branch name where the test exhibited flakiness for the first time.
27    #[serde(rename = "first_flaked_branch")]
28    pub first_flaked_branch: Option<String>,
29    /// The commit SHA where the test exhibited flakiness for the first time.
30    #[serde(rename = "first_flaked_sha")]
31    pub first_flaked_sha: Option<String>,
32    /// Unix timestamp when the test exhibited flakiness for the first time.
33    #[serde(rename = "first_flaked_ts")]
34    pub first_flaked_ts: Option<i64>,
35    /// The category of a flaky test.
36    #[serde(
37        rename = "flaky_category",
38        default,
39        with = "::serde_with::rust::double_option"
40    )]
41    pub flaky_category: Option<Option<String>>,
42    /// The current state of the flaky test.
43    #[serde(rename = "flaky_state")]
44    pub flaky_state: Option<crate::datadogV2::model::FlakyTestAttributesFlakyState>,
45    /// The branch name where the test exhibited flakiness for the last time.
46    #[serde(rename = "last_flaked_branch")]
47    pub last_flaked_branch: Option<String>,
48    /// The commit SHA where the test exhibited flakiness for the last time.
49    #[serde(rename = "last_flaked_sha")]
50    pub last_flaked_sha: Option<String>,
51    /// Unix timestamp when the test exhibited flakiness for the last time.
52    #[serde(rename = "last_flaked_ts")]
53    pub last_flaked_ts: Option<i64>,
54    /// The name of the test module. The definition of module changes slightly per language:
55    /// - In .NET, a test module groups every test that is run under the same unit test project.
56    /// - In Swift, a test module groups every test that is run for a given bundle.
57    /// - In JavaScript, the test modules map one-to-one to test sessions.
58    /// - In Java, a test module groups every test that is run by the same Maven Surefire/Failsafe or Gradle Test task execution.
59    /// - In Python, a test module groups every test that is run under the same `.py` file as part of a test suite, which is typically managed by a framework like `unittest` or `pytest`.
60    /// - In Ruby, a test module groups every test that is run within the same test file, which is typically managed by a framework like `RSpec` or `Minitest`.
61    #[serde(rename = "module", default, with = "::serde_with::rust::double_option")]
62    pub module: Option<Option<String>>,
63    /// The test name. A concise name for a test case. Defined in the test itself.
64    #[serde(rename = "name")]
65    pub name: Option<String>,
66    /// CI pipeline related statistics for the flaky test. This information is only available if test runs are associated with CI pipeline events from CI Visibility.
67    #[serde(rename = "pipeline_stats")]
68    pub pipeline_stats: Option<crate::datadogV2::model::FlakyTestPipelineStats>,
69    /// List of test service names where this test has been flaky.
70    ///
71    /// A test service is a group of tests associated with a project or repository. It contains all the individual tests for your code, optionally organized into test suites, which are like folders for your tests.
72    #[serde(rename = "services")]
73    pub services: Option<Vec<String>>,
74    /// The name of the test suite. A group of tests exercising the same unit of code depending on your language and testing framework.
75    #[serde(rename = "suite")]
76    pub suite: Option<String>,
77    /// Metadata about the latest failed test run of the flaky test.
78    #[serde(rename = "test_run_metadata")]
79    pub test_run_metadata: Option<crate::datadogV2::model::FlakyTestRunMetadata>,
80    /// Test statistics for the flaky test.
81    #[serde(rename = "test_stats")]
82    pub test_stats: Option<crate::datadogV2::model::FlakyTestStats>,
83    #[serde(flatten)]
84    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
85    #[serde(skip)]
86    #[serde(default)]
87    pub(crate) _unparsed: bool,
88}
89
90impl FlakyTestAttributes {
91    pub fn new() -> FlakyTestAttributes {
92        FlakyTestAttributes {
93            attempt_to_fix_id: None,
94            codeowners: None,
95            envs: None,
96            first_flaked_branch: None,
97            first_flaked_sha: None,
98            first_flaked_ts: None,
99            flaky_category: None,
100            flaky_state: None,
101            last_flaked_branch: None,
102            last_flaked_sha: None,
103            last_flaked_ts: None,
104            module: None,
105            name: None,
106            pipeline_stats: None,
107            services: None,
108            suite: None,
109            test_run_metadata: None,
110            test_stats: None,
111            additional_properties: std::collections::BTreeMap::new(),
112            _unparsed: false,
113        }
114    }
115
116    pub fn attempt_to_fix_id(mut self, value: String) -> Self {
117        self.attempt_to_fix_id = Some(value);
118        self
119    }
120
121    pub fn codeowners(mut self, value: Vec<String>) -> Self {
122        self.codeowners = Some(value);
123        self
124    }
125
126    pub fn envs(mut self, value: Vec<String>) -> Self {
127        self.envs = Some(value);
128        self
129    }
130
131    pub fn first_flaked_branch(mut self, value: String) -> Self {
132        self.first_flaked_branch = Some(value);
133        self
134    }
135
136    pub fn first_flaked_sha(mut self, value: String) -> Self {
137        self.first_flaked_sha = Some(value);
138        self
139    }
140
141    pub fn first_flaked_ts(mut self, value: i64) -> Self {
142        self.first_flaked_ts = Some(value);
143        self
144    }
145
146    pub fn flaky_category(mut self, value: Option<String>) -> Self {
147        self.flaky_category = Some(value);
148        self
149    }
150
151    pub fn flaky_state(
152        mut self,
153        value: crate::datadogV2::model::FlakyTestAttributesFlakyState,
154    ) -> Self {
155        self.flaky_state = Some(value);
156        self
157    }
158
159    pub fn last_flaked_branch(mut self, value: String) -> Self {
160        self.last_flaked_branch = Some(value);
161        self
162    }
163
164    pub fn last_flaked_sha(mut self, value: String) -> Self {
165        self.last_flaked_sha = Some(value);
166        self
167    }
168
169    pub fn last_flaked_ts(mut self, value: i64) -> Self {
170        self.last_flaked_ts = Some(value);
171        self
172    }
173
174    pub fn module(mut self, value: Option<String>) -> Self {
175        self.module = Some(value);
176        self
177    }
178
179    pub fn name(mut self, value: String) -> Self {
180        self.name = Some(value);
181        self
182    }
183
184    pub fn pipeline_stats(
185        mut self,
186        value: crate::datadogV2::model::FlakyTestPipelineStats,
187    ) -> Self {
188        self.pipeline_stats = Some(value);
189        self
190    }
191
192    pub fn services(mut self, value: Vec<String>) -> Self {
193        self.services = Some(value);
194        self
195    }
196
197    pub fn suite(mut self, value: String) -> Self {
198        self.suite = Some(value);
199        self
200    }
201
202    pub fn test_run_metadata(
203        mut self,
204        value: crate::datadogV2::model::FlakyTestRunMetadata,
205    ) -> Self {
206        self.test_run_metadata = Some(value);
207        self
208    }
209
210    pub fn test_stats(mut self, value: crate::datadogV2::model::FlakyTestStats) -> Self {
211        self.test_stats = Some(value);
212        self
213    }
214
215    pub fn additional_properties(
216        mut self,
217        value: std::collections::BTreeMap<String, serde_json::Value>,
218    ) -> Self {
219        self.additional_properties = value;
220        self
221    }
222}
223
224impl Default for FlakyTestAttributes {
225    fn default() -> Self {
226        Self::new()
227    }
228}
229
230impl<'de> Deserialize<'de> for FlakyTestAttributes {
231    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
232    where
233        D: Deserializer<'de>,
234    {
235        struct FlakyTestAttributesVisitor;
236        impl<'a> Visitor<'a> for FlakyTestAttributesVisitor {
237            type Value = FlakyTestAttributes;
238
239            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
240                f.write_str("a mapping")
241            }
242
243            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
244            where
245                M: MapAccess<'a>,
246            {
247                let mut attempt_to_fix_id: Option<String> = None;
248                let mut codeowners: Option<Vec<String>> = None;
249                let mut envs: Option<Vec<String>> = None;
250                let mut first_flaked_branch: Option<String> = None;
251                let mut first_flaked_sha: Option<String> = None;
252                let mut first_flaked_ts: Option<i64> = None;
253                let mut flaky_category: Option<Option<String>> = None;
254                let mut flaky_state: Option<
255                    crate::datadogV2::model::FlakyTestAttributesFlakyState,
256                > = None;
257                let mut last_flaked_branch: Option<String> = None;
258                let mut last_flaked_sha: Option<String> = None;
259                let mut last_flaked_ts: Option<i64> = None;
260                let mut module: Option<Option<String>> = None;
261                let mut name: Option<String> = None;
262                let mut pipeline_stats: Option<crate::datadogV2::model::FlakyTestPipelineStats> =
263                    None;
264                let mut services: Option<Vec<String>> = None;
265                let mut suite: Option<String> = None;
266                let mut test_run_metadata: Option<crate::datadogV2::model::FlakyTestRunMetadata> =
267                    None;
268                let mut test_stats: Option<crate::datadogV2::model::FlakyTestStats> = None;
269                let mut additional_properties: std::collections::BTreeMap<
270                    String,
271                    serde_json::Value,
272                > = std::collections::BTreeMap::new();
273                let mut _unparsed = false;
274
275                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
276                    match k.as_str() {
277                        "attempt_to_fix_id" => {
278                            if v.is_null() {
279                                continue;
280                            }
281                            attempt_to_fix_id =
282                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
283                        }
284                        "codeowners" => {
285                            if v.is_null() {
286                                continue;
287                            }
288                            codeowners = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
289                        }
290                        "envs" => {
291                            if v.is_null() {
292                                continue;
293                            }
294                            envs = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
295                        }
296                        "first_flaked_branch" => {
297                            if v.is_null() {
298                                continue;
299                            }
300                            first_flaked_branch =
301                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
302                        }
303                        "first_flaked_sha" => {
304                            if v.is_null() {
305                                continue;
306                            }
307                            first_flaked_sha =
308                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
309                        }
310                        "first_flaked_ts" => {
311                            if v.is_null() {
312                                continue;
313                            }
314                            first_flaked_ts =
315                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
316                        }
317                        "flaky_category" => {
318                            flaky_category =
319                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
320                        }
321                        "flaky_state" => {
322                            if v.is_null() {
323                                continue;
324                            }
325                            flaky_state =
326                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
327                            if let Some(ref _flaky_state) = flaky_state {
328                                match _flaky_state {
329                                    crate::datadogV2::model::FlakyTestAttributesFlakyState::UnparsedObject(_flaky_state) => {
330                                        _unparsed = true;
331                                    },
332                                    _ => {}
333                                }
334                            }
335                        }
336                        "last_flaked_branch" => {
337                            if v.is_null() {
338                                continue;
339                            }
340                            last_flaked_branch =
341                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
342                        }
343                        "last_flaked_sha" => {
344                            if v.is_null() {
345                                continue;
346                            }
347                            last_flaked_sha =
348                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
349                        }
350                        "last_flaked_ts" => {
351                            if v.is_null() {
352                                continue;
353                            }
354                            last_flaked_ts =
355                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
356                        }
357                        "module" => {
358                            module = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
359                        }
360                        "name" => {
361                            if v.is_null() {
362                                continue;
363                            }
364                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
365                        }
366                        "pipeline_stats" => {
367                            if v.is_null() {
368                                continue;
369                            }
370                            pipeline_stats =
371                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
372                        }
373                        "services" => {
374                            if v.is_null() {
375                                continue;
376                            }
377                            services = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
378                        }
379                        "suite" => {
380                            if v.is_null() {
381                                continue;
382                            }
383                            suite = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
384                        }
385                        "test_run_metadata" => {
386                            if v.is_null() {
387                                continue;
388                            }
389                            test_run_metadata =
390                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
391                        }
392                        "test_stats" => {
393                            if v.is_null() {
394                                continue;
395                            }
396                            test_stats = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
397                        }
398                        &_ => {
399                            if let Ok(value) = serde_json::from_value(v.clone()) {
400                                additional_properties.insert(k, value);
401                            }
402                        }
403                    }
404                }
405
406                let content = FlakyTestAttributes {
407                    attempt_to_fix_id,
408                    codeowners,
409                    envs,
410                    first_flaked_branch,
411                    first_flaked_sha,
412                    first_flaked_ts,
413                    flaky_category,
414                    flaky_state,
415                    last_flaked_branch,
416                    last_flaked_sha,
417                    last_flaked_ts,
418                    module,
419                    name,
420                    pipeline_stats,
421                    services,
422                    suite,
423                    test_run_metadata,
424                    test_stats,
425                    additional_properties,
426                    _unparsed,
427                };
428
429                Ok(content)
430            }
431        }
432
433        deserializer.deserialize_any(FlakyTestAttributesVisitor)
434    }
435}