use crate::csaf_traits::{CsafTrait, ProductTrait, ProductTreeTrait};
use crate::validation::ValidationError;
pub fn test_6_2_16_missing_product_identification_helper(doc: &impl CsafTrait) -> Result<(), Vec<ValidationError>> {
let mut errors: Option<Vec<ValidationError>> = None;
if let Some(tree) = doc.get_product_tree() {
tree.visit_all_products(&mut |fpn, path| {
if fpn.get_product_identification_helper().is_none() {
errors
.get_or_insert_default()
.push(create_missing_product_identification_helper_error(path));
}
});
}
errors.map_or(Ok(()), Err)
}
fn create_missing_product_identification_helper_error(instance_path: &str) -> ValidationError {
ValidationError {
message: "Product is missing 'product_identification_helper' property".to_string(),
instance_path: instance_path.to_string(),
}
}
crate::test_validation::impl_validator!(
ValidatorForTest6_2_16,
test_6_2_16_missing_product_identification_helper
);
#[cfg(test)]
mod tests {
use super::*;
use crate::csaf2_0::testcases::TESTS_2_0;
use crate::csaf2_1::testcases::TESTS_2_1;
#[test]
fn test_test_6_2_16() {
let case_01 = Err(vec![create_missing_product_identification_helper_error(
"/product_tree/full_product_names/0",
)]);
let case_02 = Err(vec![create_missing_product_identification_helper_error(
"/product_tree/branches/0/branches/0/branches/0/product",
)]);
TESTS_2_0.test_6_2_16.expect(case_01.clone(), case_02.clone(), Ok(()));
TESTS_2_1.test_6_2_16.expect(case_01, case_02, Ok(()));
}
}