use relative_path::RelativePathBuf;
use crate::{
Properties,
encoding::TargetEncoding,
product::ProductId,
report::{
product::ProductMetadata,
review::ReviewReference,
test_run::TestRunReference,
tests::{TestCoverage, TestRelatedRequirement, TestState},
},
test_runs::{LogOutput, TestCaseLocation},
};
#[derive(
Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
)]
#[serde(rename_all = "snake_case")]
pub struct TestCaseReference {
pub product_id: ProductId,
pub test_run_name: String,
#[serde(with = "time::serde::iso8601")]
#[schemars(with = "String")]
pub test_run_date: time::OffsetDateTime,
pub test_case_name: String,
pub state: TestState,
}
impl TestCaseReference {
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 test_run = TestRunReference {
product_id: self.product_id.clone(),
name: self.test_run_name.clone(),
utc_date: self.test_run_date,
state: TestState::Unknown,
};
let limit_test_case_name = crate::encoding::limit_str_len(&self.test_case_name);
let test_case_path = if limit_test_case_name.contains("::") {
RelativePathBuf::from_iter(
limit_test_case_name
.split("::")
.map(|name| crate::encoding::encode(name, target).to_string()),
)
} else {
RelativePathBuf::from(
crate::encoding::encode(&limit_test_case_name, target).to_string(),
)
};
let test_run_path = match target {
TargetEncoding::Os => test_run.os_path(),
TargetEncoding::Url => test_run.url_path(),
};
test_run_path.join(test_case_path)
}
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct TestCaseReportSchema {
#[serde(serialize_with = "crate::serialize_schema_version")]
pub schema_version: Option<String>,
pub product: ProductMetadata,
pub test_run: TestRunReference,
pub name: String,
pub description: Option<String>,
pub state: TestState,
pub state_properties: Option<Properties>,
pub location: Option<TestCaseLocation>,
#[serde(with = "time::serde::iso8601::option")]
#[schemars(with = "String")]
#[serde(default)] pub utc_date: Option<time::OffsetDateTime>,
#[schemars(with = "String")]
#[serde(with = "crate::test_runs::duration_as_saturating_seconds_f64", default)]
pub duration_sec: Option<time::Duration>,
pub properties: Option<Properties>,
pub logs: Option<Vec<LogOutput>>,
pub coverage: Option<TestCoverage>,
pub related_reqs: Option<Vec<TestRelatedRequirement>>,
pub overridden_by: Option<Vec<ReviewReference>>,
}