Skip to main content

mantra_schema/report/
test_run.rs

1use relative_path::RelativePathBuf;
2
3use crate::{
4    Origin, Properties, Revision, TEST_RUNS_FOLDER_NAME,
5    encoding::TargetEncoding,
6    product::ProductId,
7    report::{
8        product::ProductMetadata,
9        review::ReviewReference,
10        test_case::TestCaseReference,
11        tests::{TestCoverage, TestRelatedRequirement, TestState, TestsSummary},
12    },
13    test_runs::LogOutput,
14};
15
16#[derive(
17    Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
18)]
19#[serde(rename_all = "snake_case")]
20pub struct TestRunReference {
21    pub product_id: ProductId,
22    pub name: String,
23    #[serde(with = "time::serde::iso8601")]
24    #[schemars(with = "String")]
25    pub utc_date: time::OffsetDateTime,
26    pub state: TestState,
27}
28
29impl TestRunReference {
30    pub fn url_path(&self) -> RelativePathBuf {
31        self.encode_path(TargetEncoding::Url)
32    }
33
34    pub fn os_path(&self) -> RelativePathBuf {
35        self.encode_path(TargetEncoding::Os)
36    }
37
38    fn encode_path(&self, target: TargetEncoding) -> RelativePathBuf {
39        let product_path = match target {
40            TargetEncoding::Os => self.product_id.os_path(),
41            TargetEncoding::Url => self.product_id.url_path(),
42        };
43
44        let limit_name = crate::encoding::limit_str_len(&self.name);
45        let encoded_ref = format!(
46            "{}_{}",
47            super::encode_utc_date(&self.utc_date),
48            crate::encoding::encode(&limit_name, target)
49        );
50
51        product_path.join(TEST_RUNS_FOLDER_NAME).join(encoded_ref)
52    }
53}
54
55/// Represents a test run in *mantra*.
56/// [req("testcov.test_run")]
57#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
58#[serde(rename_all = "snake_case")]
59pub struct TestRunReportSchema {
60    /// The schema version.
61    /// [req("exchange.versioned")]
62    #[serde(serialize_with = "crate::serialize_schema_version")]
63    pub schema_version: Option<String>,
64    pub product: ProductMetadata,
65    /// The name of the test run.
66    /// [req("testcov.test_run.id")]
67    pub name: String,
68    /// The UTC date the test run execution started.
69    ///
70    /// **Note:** The date must be given in ISO8601 format.
71    /// [req("testcov.test_run.date")]
72    #[serde(with = "time::serde::iso8601")]
73    #[schemars(with = "String")]
74    pub utc_date: time::OffsetDateTime,
75    pub state: TestState,
76    /// Optional description of the test run.
77    pub description: Option<String>,
78    /// Optional revisions for the test run.
79    pub revisions: Option<Vec<Revision>>,
80    /// Optional origin of the test run.
81    /// [req("testcov.test_run.origin")]
82    pub origin: Option<Origin>,
83    pub base_origin: Option<Origin>,
84    /// Nr of test cases that are part of the test run.
85    ///
86    /// **Note:** Must match with the number of entries in the `test_cases` field,
87    /// plus the number of entries in the `test_cases` fields of all child test runs.
88    /// In case this differs, it indicates that not all test cases have finished execution.
89    pub nr_of_test_cases: i64,
90    /// Optional field to store custom information per test run.
91    /// [req("testcov.test_run.metadata")]
92    pub properties: Option<Properties>,
93    /// Optional duration about how long the test run took.
94    /// Will be displayed in seconds with nanosecond precision in decimal form.
95    #[schemars(with = "String")]
96    #[serde(with = "crate::test_runs::duration_as_saturating_seconds_f64", default)]
97    pub duration_sec: Option<time::Duration>,
98    /// Optional logs that were output during the execution of the test run.
99    ///
100    // TODO: add req
101    pub logs: Option<Vec<LogOutput>>,
102    /// Overview of test cases that are part of the test run.
103    /// [req("testcov.test_case")]
104    pub test_cases: Option<TestCasesOverview>,
105    /// Optional test run children.
106    pub child_test_runs: Option<Vec<TestRunReference>>,
107    /// Optional test run parents.
108    pub parent_test_runs: Option<Vec<TestRunReference>>,
109    /// Optional list of coverage information per file that was collected during the test run.
110    /// [req("testcov.cov")]
111    pub coverage: Option<TestCoverage>,
112    pub related_reqs: Option<Vec<TestRelatedRequirement>>,
113    pub overridden_by: Option<Vec<ReviewReference>>,
114}
115
116#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
117pub struct TestCasesOverview {
118    pub summary: TestsSummary,
119    pub passed: Vec<TestCaseReference>,
120    pub failed: Vec<TestCaseReference>,
121    pub skipped: Vec<TestCaseReference>,
122    pub unknown: Vec<TestCaseReference>,
123    pub obsolete: Vec<TestCaseReference>,
124}