mantra_schema/report/
test_run.rs1use 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#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
58#[serde(rename_all = "snake_case")]
59pub struct TestRunReportSchema {
60 #[serde(serialize_with = "crate::serialize_schema_version")]
63 pub schema_version: Option<String>,
64 pub product: ProductMetadata,
65 pub name: String,
68 #[serde(with = "time::serde::iso8601")]
73 #[schemars(with = "String")]
74 pub utc_date: time::OffsetDateTime,
75 pub state: TestState,
76 pub description: Option<String>,
78 pub revisions: Option<Vec<Revision>>,
80 pub origin: Option<Origin>,
83 pub base_origin: Option<Origin>,
84 pub nr_of_test_cases: i64,
90 pub properties: Option<Properties>,
93 #[schemars(with = "String")]
96 #[serde(with = "crate::test_runs::duration_as_saturating_seconds_f64", default)]
97 pub duration_sec: Option<time::Duration>,
98 pub logs: Option<Vec<LogOutput>>,
102 pub test_cases: Option<TestCasesOverview>,
105 pub child_test_runs: Option<Vec<TestRunReference>>,
107 pub parent_test_runs: Option<Vec<TestRunReference>>,
109 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}