-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for spdx "relationshipType": "PACKAGE_OF" #1186
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -654,7 +654,7 @@ async fn spdx_package_of(ctx: &TrustifyContext) -> Result<(), anyhow::Error> { | |||||||||||||||||||||||||||
let uri = format!("/api/v2/analysis/dep/{}", urlencoding::encode(purl)); | ||||||||||||||||||||||||||||
let request: Request = TestRequest::get().uri(&uri).to_request(); | ||||||||||||||||||||||||||||
let response: Value = app.call_and_read_body_json(request).await; | ||||||||||||||||||||||||||||
log::debug!("{response:#?}"); | ||||||||||||||||||||||||||||
log::debug!("{}", serde_json::to_string_pretty(&response)?); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
let sbom = &response["items"][0]; | ||||||||||||||||||||||||||||
let matches: Vec<_> = sbom["deps"] | ||||||||||||||||||||||||||||
|
@@ -677,5 +677,33 @@ async fn spdx_package_of(ctx: &TrustifyContext) -> Result<(), anyhow::Error> { | |||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
assert_eq!(1, matches.len()); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
let uri = format!( | ||||||||||||||||||||||||||||
"/api/v2/analysis/root-component?q={}", | ||||||||||||||||||||||||||||
urlencoding::encode("SATELLITE-6.15-RHEL-8") | ||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||
let request: Request = TestRequest::get().uri(&uri).to_request(); | ||||||||||||||||||||||||||||
let response: Value = app.call_and_read_body_json(request).await; | ||||||||||||||||||||||||||||
log::info!("{}", serde_json::to_string_pretty(&response)?); | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. your right.. will fix. |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
let sbom = &response["items"][0]; | ||||||||||||||||||||||||||||
let matches: Vec<_> = sbom["ancestors"] | ||||||||||||||||||||||||||||
.as_array() | ||||||||||||||||||||||||||||
.into_iter() | ||||||||||||||||||||||||||||
.flatten() | ||||||||||||||||||||||||||||
.filter(|m| { | ||||||||||||||||||||||||||||
m == &&json!({ | ||||||||||||||||||||||||||||
"sbom_id": sbom["sbom_id"], | ||||||||||||||||||||||||||||
"node_id": m["node_id"], | ||||||||||||||||||||||||||||
"relationship": "PackageOf", | ||||||||||||||||||||||||||||
"purl": m["purl"], // long list assume it's correct | ||||||||||||||||||||||||||||
"cpe": m["cpe"], // long list assume it's correct | ||||||||||||||||||||||||||||
"name": "rubygem-google-cloud-compute", | ||||||||||||||||||||||||||||
"version": "0.5.0-1.el8sat" | ||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To me, this is a brittle test. I'd want my expectation to be the minimum required to affirm the test. If some future change adds or takes away one of the fields that has nothing to do with this test, it's still gonna break. Is that good or annoying? I'd rather something like this, maybe even omitting
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kinda was thinking about similar lines. Is there an existing function that can test if an actual Value matches a partial set of fields of another expected Value? The assertion would become more concise and less brittle then. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not that I know of. You can always downcast the Another option is to use |
||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||
.collect(); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
assert_eq!(1, matches.len()); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
Ok(()) | ||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really wish serde's impl of
:#?
usedto_string_pretty
. I can remember the former, but never the latter. :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100%