Skip to content

Commit

Permalink
text: fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Jan 30, 2025
1 parent 75b5005 commit 19cca70
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
29 changes: 29 additions & 0 deletions modules/analysis/src/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub fn configure(config: &mut ServiceConfig, db: Database, analysis: AnalysisSer
.service(search_component_root_components)
.service(get_component_root_components)
.service(get_component)
.service(search_component)
.service(analysis_status)
.service(search_component_deps)
.service(get_component_deps)
Expand Down Expand Up @@ -139,6 +140,34 @@ pub async fn get_component(
))
}

#[utoipa::path(
tag = "analysis",
operation_id = "searchComponent",
params(
Query,
Paginated,
QueryOptions,
),
responses(
(status = 200, description = "Retrieve component(s) root components by name, pURL, or CPE.", body = PaginatedResults<BaseSummary>),
),
)]
#[get("/v2/analysis/component")]
pub async fn search_component(
service: web::Data<AnalysisService>,
db: web::Data<Database>,
web::Query(search): web::Query<Query>,
web::Query(options): web::Query<QueryOptions>,
web::Query(paginated): web::Query<Paginated>,
_: Require<ReadSbom>,
) -> actix_web::Result<impl Responder> {
Ok(HttpResponse::Ok().json(
service
.retrieve(&search, options, paginated, db.as_ref())
.await?,
))
}

#[utoipa::path(
tag = "analysis",
operation_id = "searchComponentDeps",
Expand Down
11 changes: 7 additions & 4 deletions modules/analysis/src/endpoints/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,10 @@ async fn cdx_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;
tracing::debug!(test = "", "{response:#?}");
Expand All @@ -439,8 +442,8 @@ async fn cdx_generated_from(ctx: &TrustifyContext) -> Result<(), anyhow::Error>
.unwrap()
.iter()
.filter(|i| i["node_id"] == src)
.flat_map(|i| i["deps"].as_array().unwrap().iter())
.filter(|d| d["relationship"] == "GeneratedFrom")
.flat_map(|i| i["descendants"].as_array().unwrap().iter())
.filter(|d| d["relationship"] == "generated_from")
.count()
);

Expand Down Expand Up @@ -770,7 +773,7 @@ async fn spdx_package_of(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {

// Ensure the product contains the component
let uri = format!(
"/api/v2/analysis/component?q={}&vdescendants=10",
"/api/v2/analysis/component?q={}&descendants=10",
urlencoding::encode("SATELLITE-6.15-RHEL-8")
);
let request: Request = TestRequest::get().uri(&uri).to_request();
Expand Down

0 comments on commit 19cca70

Please sign in to comment.