Skip to content

Commit b80f397

Browse files
committed
Fix tests
Signed-off-by: Sebastian Ziebell <[email protected]>
1 parent f221cb4 commit b80f397

File tree

6 files changed

+40
-83
lines changed

6 files changed

+40
-83
lines changed

cyclonedx-bom/src/models/advisory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ mod test {
100100
assert_eq!(
101101
validation_result.errors(),
102102
Some(validation::list(
103-
"Advisory",
103+
"inner",
104104
[(
105105
0,
106106
vec![

cyclonedx-bom/src/models/bom.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -534,13 +534,13 @@ mod test {
534534
Some(
535535
vec![
536536
validation::custom(
537-
"dependency ref",
538-
"Dependency reference does not exist in the BOM"
537+
"dependency_ref",
538+
["Dependency ref 'dependency' does not exist in the BOM",],
539539
),
540540
validation::custom(
541-
"dependency ref",
542-
"Dependency reference does not exist in the BOM"
543-
),
541+
"sub dependency_ref",
542+
["Dependency ref 'sub-dependency' does not exist in the BOM"]
543+
)
544544
]
545545
.into()
546546
)
@@ -572,21 +572,12 @@ mod test {
572572

573573
assert_eq!(
574574
actual.errors(),
575-
Some(validation::list(
576-
"compositions",
577-
[(
578-
0,
579-
vec![
580-
validation::custom(
581-
"composition ref",
582-
"Composition reference 'abc' does not exist in the BOM"
583-
),
584-
validation::custom(
585-
"composition ref",
586-
"Composition reference 'abc' does not exist in the BOM"
587-
)
588-
]
589-
)]
575+
Some(validation::custom(
576+
"composition ref",
577+
[
578+
"Composition reference 'assembly' does not exist in the BOM",
579+
"Composition reference 'dependencies' does not exist in the BOM"
580+
]
590581
))
591582
);
592583
}

cyclonedx-bom/src/models/code.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ impl Validate for Issue {
118118
validate_normalized_string,
119119
)
120120
.add_struct_option("source", self.source.as_ref(), version)
121-
// TODO:
122-
// .add_list_option("references", self.references.as_ref(), |uri| {
123-
// validate_uri(uri)
124-
// })
121+
.add_list_option("references", self.references.as_ref(), validate_uri)
125122
.into()
126123
}
127124
}
@@ -411,7 +408,7 @@ mod test {
411408
[(
412409
0,
413410
vec![
414-
validation::field("patch_type", "Unknown patch classification"),
411+
validation::r#enum("patch_type", "Unknown patch classification"),
415412
validation::r#struct(
416413
"diff",
417414
vec![
@@ -449,7 +446,7 @@ mod test {
449446
)
450447
]
451448
),
452-
validation::list("references", [(0, validation::field("inner", "Uri does not conform to RFC 3986"))])
449+
validation::list("references", [(0, validation::custom("", ["Uri does not conform to RFC 3986"]))])
453450
]
454451
)]
455452
)

cyclonedx-bom/src/models/component.rs

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -259,22 +259,6 @@ impl Scope {
259259
}
260260
}
261261

262-
/*
263-
impl Validate for Scope {
264-
fn validate(&self, version: SpecVersion) -> ValidationResult {
265-
match self {
266-
Scope::UnknownScope(_) => ValidationResult::Failed {
267-
reasons: vec![FailureReason {
268-
message: "Unknown scope".to_string(),
269-
context,
270-
}],
271-
},
272-
_ => ValidationResult::Passed,
273-
}
274-
}
275-
}
276-
*/
277-
278262
/// Checks if given [`MimeType`] is valid / supported.
279263
pub fn validate_mime_type(mime_type: &MimeType) -> Result<(), ValidationError> {
280264
static UUID_REGEX: Lazy<Regex> =
@@ -341,26 +325,8 @@ impl Validate for ComponentEvidence {
341325
fn validate(&self, version: SpecVersion) -> ValidationResult {
342326
ValidationContext::new()
343327
.add_struct_option("licenses", self.licenses.as_ref(), version)
328+
.add_struct_option("copyright", self.copyright.as_ref(), version)
344329
.into()
345-
/*
346-
let mut results: Vec<ValidationResult> = vec![];
347-
348-
if let Some(licenses) = &self.licenses {
349-
let context = context.with_struct("ComponentEvidence", "licenses");
350-
351-
results.push(licenses.validate_with_context(context));
352-
}
353-
354-
if let Some(copyright) = &self.copyright {
355-
let context = context.with_struct("ComponentEvidence", "copyright");
356-
357-
results.push(copyright.validate_with_context(context));
358-
}
359-
360-
results
361-
.into_iter()
362-
.fold(ValidationResult::default(), |acc, result| acc.merge(result))
363-
*/
364330
}
365331
}
366332

cyclonedx-bom/src/models/external_reference.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -204,26 +204,29 @@ mod test {
204204
"inner",
205205
[(
206206
0,
207-
validation::r#struct(
208-
"ExternalReference",
209-
vec![
210-
validation::field(
211-
"external_reference_type",
212-
"Unknown external reference type"
213-
),
214-
validation::field("url", "Uri does not conform to RFC 3986"),
215-
validation::list(
216-
"hashes",
217-
[(
218-
0,
219-
validation::field(
220-
"content",
221-
"HashValue does not match regular expression"
222-
)
223-
)]
224-
),
225-
]
226-
)
207+
vec![
208+
validation::field(
209+
"external_reference_type",
210+
"Unknown external reference type"
211+
),
212+
validation::field("url", "Uri does not conform to RFC 3986"),
213+
validation::list(
214+
"hashes",
215+
[(
216+
0,
217+
validation::list(
218+
"inner",
219+
[(
220+
0,
221+
validation::field(
222+
"content",
223+
"HashValue does not match regular expression"
224+
)
225+
)]
226+
)
227+
)]
228+
)
229+
]
227230
)]
228231
))
229232
);

cyclonedx-bom/src/models/property.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ mod test {
103103
assert_eq!(
104104
validation_result.errors(),
105105
Some(validation::list(
106-
"Property",
106+
"inner",
107107
[(
108108
0,
109109
validation::field(

0 commit comments

Comments
 (0)