use relative_path::RelativePathBuf;
use crate::{
Origin, Properties, Revision, TEST_RUNS_FOLDER_NAME,
encoding::TargetEncoding,
product::ProductId,
report::{
product::ProductMetadata,
review::ReviewReference,
test_case::TestCaseReference,
tests::{TestCoverage, TestRelatedRequirement, TestState, TestsSummary},
},
test_runs::LogOutput,
};
#[derive(
Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
)]
#[serde(rename_all = "snake_case")]
pub struct TestRunReference {
pub product_id: ProductId,
pub name: String,
#[serde(with = "time::serde::iso8601")]
#[schemars(with = "String")]
pub utc_date: time::OffsetDateTime,
pub state: TestState,
}
impl TestRunReference {
pub fn url_path(&self) -> RelativePathBuf {
self.encode_path(TargetEncoding::Url)
}
pub fn os_path(&self) -> RelativePathBuf {
self.encode_path(TargetEncoding::Os)
}
fn encode_path(&self, target: TargetEncoding) -> RelativePathBuf {
let product_path = match target {
TargetEncoding::Os => self.product_id.os_path(),
TargetEncoding::Url => self.product_id.url_path(),
};
let limit_name = crate::encoding::limit_str_len(&self.name);
let encoded_ref = format!(
"{}_{}",
super::encode_utc_date(&self.utc_date),
crate::encoding::encode(&limit_name, target)
);
product_path.join(TEST_RUNS_FOLDER_NAME).join(encoded_ref)
}
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct TestRunReportSchema {
#[serde(serialize_with = "crate::serialize_schema_version")]
pub schema_version: Option<String>,
pub product: ProductMetadata,
pub name: String,
#[serde(with = "time::serde::iso8601")]
#[schemars(with = "String")]
pub utc_date: time::OffsetDateTime,
pub state: TestState,
pub description: Option<String>,
pub revisions: Option<Vec<Revision>>,
pub origin: Option<Origin>,
pub base_origin: Option<Origin>,
pub nr_of_test_cases: i64,
pub properties: Option<Properties>,
#[schemars(with = "String")]
#[serde(with = "crate::test_runs::duration_as_saturating_seconds_f64", default)]
pub duration_sec: Option<time::Duration>,
pub logs: Option<Vec<LogOutput>>,
pub test_cases: Option<TestCasesOverview>,
pub child_test_runs: Option<Vec<TestRunReference>>,
pub parent_test_runs: Option<Vec<TestRunReference>>,
pub coverage: Option<TestCoverage>,
pub related_reqs: Option<Vec<TestRelatedRequirement>>,
pub overridden_by: Option<Vec<ReviewReference>>,
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
pub struct TestCasesOverview {
pub summary: TestsSummary,
pub passed: Vec<TestCaseReference>,
pub failed: Vec<TestCaseReference>,
pub skipped: Vec<TestCaseReference>,
pub unknown: Vec<TestCaseReference>,
pub obsolete: Vec<TestCaseReference>,
}