Skip to content

Commit

Permalink
test: fixup even more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Jan 31, 2025
1 parent 10a5c76 commit c4ba5f4
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions modules/analysis/src/endpoints/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,14 +448,14 @@ async fn cdx_generated_from(ctx: &TrustifyContext) -> Result<(), anyhow::Error>
.iter()
.filter(|i| i["node_id"] == src)
.flat_map(|i| i["descendants"].as_array().unwrap().iter())
.filter(|d| d["relationship"] == "generated_from")
.filter(|d| d["relationship"] == "generates")
.count()
);

// Ensure binary rpm GeneratedFrom src rpm
let x86 = "pkg:rpm/redhat/[email protected]_2?arch=x86_64";
let uri = format!(
"/api/v2/analysis/root-component/{}",
"/api/v2/analysis/component/{}?ancestors=10",
urlencoding::encode(x86)
);
let request: Request = TestRequest::get().uri(&uri).to_request();
Expand All @@ -465,7 +465,7 @@ async fn cdx_generated_from(ctx: &TrustifyContext) -> Result<(), anyhow::Error>
"items": [{
"purl": [ x86 ],
"ancestors": [{
"relationship": "GeneratedFrom",
"relationship": "geneartes",
"purl": [ src ]
}]
}]
Expand All @@ -483,7 +483,10 @@ async fn spdx_generated_from(ctx: &TrustifyContext) -> Result<(), anyhow::Error>

// Find all deps of src rpm
let src = "pkg:rpm/redhat/[email protected]_2?arch=src";
let uri = format!("/api/v2/analysis/dep/{}", urlencoding::encode(src));
let uri = format!(
"/api/v2/analysis/component/{}?descendants=10",
urlencoding::encode(src)
);
let request: Request = TestRequest::get().uri(&uri).to_request();
let response: Value = app.call_and_read_body_json(request).await;
log::debug!("{response:#?}");
Expand All @@ -496,24 +499,25 @@ async fn spdx_generated_from(ctx: &TrustifyContext) -> Result<(), anyhow::Error>
.iter()
.filter(|i| i["node_id"] == "SPDXRef-SRPM")
.flat_map(|i| i["descendants"].as_array().unwrap().iter())
.filter(|d| d["relationship"] == "GeneratedFrom")
.filter(|d| d["relationship"] == "generates")
.count()
);

// Ensure binary rpm GeneratedFrom src rpm
let x86 = "pkg:rpm/redhat/[email protected]_2?arch=x86_64";
let uri = format!(
"/api/v2/analysis/root-component/{}",
"/api/v2/analysis/component/{}?ancestors=10",
urlencoding::encode(x86)
);
let request: Request = TestRequest::get().uri(&uri).to_request();
let response: Value = app.call_and_read_body_json(request).await;
log::debug!("{response:#?}");

assert!(response.contains_subset(json!({
"items": [{
"purl": [ x86 ],
"ancestors": [{
"relationship": "GeneratedFrom",
"relationship": "generates",
"purl": [ src ]
}]
}]
Expand All @@ -534,7 +538,7 @@ async fn cdx_variant_of(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
let child = "pkg:oci/openshift-ose-console@sha256:94a0d7feec34600a858c8e383ee0e8d5f4a077f6bbc327dcad8762acfcf40679";

let uri = format!(
"/api/v2/analysis/component/{}?descendants=10",
"/api/v2/analysis/component/{}?ancestors=10",
urlencoding::encode(parent)
);
let request: Request = TestRequest::get().uri(&uri).to_request();
Expand All @@ -544,7 +548,7 @@ async fn cdx_variant_of(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
assert!(response.contains_subset(json!({
"items": [{
"purl": [ parent ],
"descendants": [{
"ancestors": [{
"relationship": "variant",
"purl": [ child ]
}]
Expand All @@ -553,7 +557,7 @@ async fn cdx_variant_of(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {

// Ensure child is variant of src
let uri = format!(
"/api/v2/analysis/component/{}?ancestors=10",
"/api/v2/analysis/component/{}?descendants=10",
urlencoding::encode(child)
);
let request: Request = TestRequest::get().uri(&uri).to_request();
Expand All @@ -563,7 +567,7 @@ async fn cdx_variant_of(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
assert!(response.contains_subset(json!({
"items": [{
"purl": [ child ],
"ancestors": [{
"descendants": [{
"relationship": "variant",
"purl": [ parent ]
}]
Expand Down Expand Up @@ -769,7 +773,7 @@ async fn spdx_package_of(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
assert!(response.contains_subset(json!({
"items": [ {
"ancestors": [ {
"relationship": "packages",
"relationship": "package",
"name": "SATELLITE-6.15-RHEL-8",
"version": "6.15",
}]
Expand All @@ -788,7 +792,7 @@ async fn spdx_package_of(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
assert!(response.contains_subset(json!({
"items": [ {
"descendants": [ {
"relationship": "packages",
"relationship": "package",
"name": "rubygem-google-cloud-compute",
"version": "0.5.0-1.el8sat"
}]
Expand Down

0 comments on commit c4ba5f4

Please sign in to comment.