use crate::csaf::types::csaf_document_category::CsafDocumentCategory;
use crate::csaf_traits::{CsafTrait, DocumentTrait, TrackingTrait};
use crate::validation::ValidationError;
use crate::validations::utils::document_category_test_config::DocumentCategoryTestConfig;
fn create_revision_history_only_one_entry_error(document_category: &CsafDocumentCategory) -> ValidationError {
ValidationError {
message: format!(
"The revision history contains only one entry which is prohibited for documents with category {document_category}"
),
instance_path: "/document/tracking/revision_history".to_string(),
}
}
pub fn test_6_1_27_16_revision_history(doc: &impl CsafTrait) -> Result<(), Vec<ValidationError>> {
let doc_category = doc.get_document().get_category();
if !PROFILE_TEST_CONFIG.matches_category_with_csaf_version(doc.get_document().get_csaf_version(), &doc_category) {
return Ok(()); }
if doc.get_document().get_tracking().get_revision_history().len() == 1 {
return Err(vec![create_revision_history_only_one_entry_error(&doc_category)]);
}
Ok(())
}
const PROFILE_TEST_CONFIG: DocumentCategoryTestConfig = DocumentCategoryTestConfig::new().csaf21(&[
CsafDocumentCategory::CsafWithdrawn,
CsafDocumentCategory::CsafSuperseded,
]);
crate::test_validation::impl_validator!(csaf2_1, ValidatorForTest6_1_27_16, test_6_1_27_16_revision_history);
#[cfg(test)]
mod tests {
use super::*;
use crate::csaf2_1::testcases::TESTS_2_1;
#[test]
fn test_test_6_1_27_16() {
let fail_withdrawn = Err(vec![create_revision_history_only_one_entry_error(
&CsafDocumentCategory::CsafWithdrawn,
)]);
let fail_superseded = Err(vec![create_revision_history_only_one_entry_error(
&CsafDocumentCategory::CsafSuperseded,
)]);
TESTS_2_1
.test_6_1_27_16
.expect(fail_withdrawn, fail_superseded, Ok(()), Ok(()), Ok(()), Ok(()));
}
}