|
19 | 19 | use std::convert::TryFrom; |
20 | 20 |
|
21 | 21 | use crate::errors::BomError; |
22 | | -use crate::errors::BomError::BomV13SerializationError; |
| 22 | +use crate::errors::BomError::BomSerializationError; |
23 | 23 | use crate::utilities::try_convert_optional; |
24 | 24 | use crate::{ |
25 | 25 | errors::XmlReadError, |
@@ -166,7 +166,10 @@ impl TryFrom<models::component::Component> for Component { |
166 | 166 |
|
167 | 167 | fn try_from(other: models::component::Component) -> Result<Self, Self::Error> { |
168 | 168 | match other.version { |
169 | | - None => Err(BomV13SerializationError("version missing".to_string())), |
| 169 | + None => Err(BomSerializationError( |
| 170 | + models::bom::SpecVersion::V1_3, |
| 171 | + "version missing".to_string(), |
| 172 | + )), |
170 | 173 | Some(version) => Ok(Self { |
171 | 174 | component_type: other.component_type.to_string(), |
172 | 175 | mime_type: other.mime_type.map(|m| MimeType(m.0)), |
@@ -1171,6 +1174,7 @@ impl From<MimeType> for models::component::MimeType { |
1171 | 1174 | #[cfg(test)] |
1172 | 1175 | pub(crate) mod test { |
1173 | 1176 | use crate::{ |
| 1177 | + models::bom::SpecVersion, |
1174 | 1178 | specs::v1_3::{ |
1175 | 1179 | attached_text::test::{corresponding_attached_text, example_attached_text}, |
1176 | 1180 | code::test::{ |
@@ -1463,4 +1467,16 @@ pub(crate) mod test { |
1463 | 1467 | let expected = example_components(); |
1464 | 1468 | assert_eq!(actual, expected); |
1465 | 1469 | } |
| 1470 | + |
| 1471 | + #[test] |
| 1472 | + fn it_should_fail_conversion_without_version_field() { |
| 1473 | + let mut component = corresponding_component(); |
| 1474 | + component.version = None; |
| 1475 | + |
| 1476 | + let result = Component::try_from(component); |
| 1477 | + assert!(matches!( |
| 1478 | + result, |
| 1479 | + Err(BomError::BomSerializationError(SpecVersion::V1_3, _)) |
| 1480 | + )); |
| 1481 | + } |
1466 | 1482 | } |
0 commit comments