common: improve search and repo tests
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ic34fb20b5fc0e400f3ed2da441796f6b6a6a6964
This commit is contained in:
parent
b6012b932f
commit
6aa3a7357f
2 changed files with 130 additions and 88 deletions
|
|
@ -62,6 +62,10 @@ async fn create_test_eval(
|
|||
repo::evaluations::create(pool, CreateEvaluation {
|
||||
jobset_id,
|
||||
commit_hash: format!("abc123{}", uuid::Uuid::new_v4().simple()),
|
||||
pr_number: None,
|
||||
pr_head_branch: None,
|
||||
pr_base_branch: None,
|
||||
pr_action: None,
|
||||
})
|
||||
.await
|
||||
.expect("create evaluation")
|
||||
|
|
@ -243,8 +247,12 @@ async fn test_evaluation_and_build_lifecycle() {
|
|||
|
||||
// Create evaluation
|
||||
let eval = repo::evaluations::create(&pool, CreateEvaluation {
|
||||
jobset_id: jobset.id,
|
||||
commit_hash: "abc123def456".to_string(),
|
||||
jobset_id: jobset.id,
|
||||
commit_hash: "abc123def456".to_string(),
|
||||
pr_number: None,
|
||||
pr_head_branch: None,
|
||||
pr_base_branch: None,
|
||||
pr_action: None,
|
||||
})
|
||||
.await
|
||||
.expect("create evaluation");
|
||||
|
|
@ -515,8 +523,8 @@ async fn test_batch_check_deps_for_builds() {
|
|||
.await
|
||||
.expect("batch check deps");
|
||||
|
||||
assert_eq!(results[&main_build.id], false); // dep not completed
|
||||
assert_eq!(results[&standalone.id], true); // no deps
|
||||
assert!(!results[&main_build.id]); // dep not completed
|
||||
assert!(results[&standalone.id]); // no deps
|
||||
|
||||
// Now complete the dep
|
||||
repo::builds::start(&pool, dep_build.id).await.unwrap();
|
||||
|
|
@ -539,8 +547,8 @@ async fn test_batch_check_deps_for_builds() {
|
|||
.await
|
||||
.expect("batch check deps after complete");
|
||||
|
||||
assert_eq!(results[&main_build.id], true); // dep now completed
|
||||
assert_eq!(results[&standalone.id], true);
|
||||
assert!(results[&main_build.id]); // dep now completed
|
||||
assert!(results[&standalone.id]);
|
||||
|
||||
// Empty input
|
||||
let empty = repo::build_dependencies::check_deps_for_builds(&pool, &[])
|
||||
|
|
@ -758,7 +766,7 @@ async fn test_build_cancel_cascade() {
|
|||
.await
|
||||
.expect("cancel cascade");
|
||||
|
||||
assert!(cancelled.len() >= 1);
|
||||
assert!(!cancelled.is_empty());
|
||||
|
||||
// Both should be cancelled
|
||||
let parent = repo::builds::get(&pool, parent.id).await.unwrap();
|
||||
|
|
@ -806,9 +814,10 @@ async fn test_dedup_by_drv_path() {
|
|||
assert_eq!(existing.unwrap().id, build.id);
|
||||
|
||||
// Check batch dedup
|
||||
let batch = repo::builds::get_completed_by_drv_paths(&pool, &[drv.clone()])
|
||||
.await
|
||||
.expect("batch dedup");
|
||||
let batch =
|
||||
repo::builds::get_completed_by_drv_paths(&pool, std::slice::from_ref(&drv))
|
||||
.await
|
||||
.expect("batch dedup");
|
||||
assert!(batch.contains_key(&drv));
|
||||
|
||||
// Cleanup
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
//! Integration tests for advanced search functionality
|
||||
//! Requires TEST_DATABASE_URL to be set to a PostgreSQL connection string.
|
||||
|
||||
use fc_common::{models::*, repo, repo::search::*};
|
||||
use fc_common::{BuildStatus, models::*, repo, repo::search::*};
|
||||
use uuid::Uuid;
|
||||
|
||||
async fn get_pool() -> Option<sqlx::PgPool> {
|
||||
|
|
@ -98,7 +98,7 @@ async fn test_build_search_with_filters() {
|
|||
None => return,
|
||||
};
|
||||
|
||||
// Setup
|
||||
// Setup: project -> jobset -> evaluation -> builds
|
||||
let project = repo::projects::create(&pool, CreateProject {
|
||||
name: format!("build-search-{}", Uuid::new_v4().simple()),
|
||||
description: None,
|
||||
|
|
@ -120,37 +120,72 @@ async fn test_build_search_with_filters() {
|
|||
.await
|
||||
.expect("create jobset");
|
||||
|
||||
// Create evaluation first (builds require an evaluation)
|
||||
let evaluation = repo::evaluations::create(&pool, CreateEvaluation {
|
||||
jobset_id: jobset.id,
|
||||
commit_hash: format!("abc123{}", Uuid::new_v4().simple()),
|
||||
pr_number: None,
|
||||
pr_head_branch: None,
|
||||
pr_base_branch: None,
|
||||
pr_action: None,
|
||||
})
|
||||
.await
|
||||
.expect("create evaluation");
|
||||
|
||||
// Create builds with different statuses
|
||||
let build1 = repo::builds::create(&pool, &CreateBuild {
|
||||
project_id: project.id,
|
||||
jobset_id: jobset.id,
|
||||
evaluation_id: None,
|
||||
let build1 = repo::builds::create(&pool, CreateBuild {
|
||||
evaluation_id: evaluation.id,
|
||||
job_name: "package-hello".to_string(),
|
||||
drv_path: "/nix/store/...-hello.drv".to_string(),
|
||||
priority: 100,
|
||||
drv_path: format!("/nix/store/{}-hello.drv", Uuid::new_v4().simple()),
|
||||
system: Some("x86_64-linux".to_string()),
|
||||
outputs: None,
|
||||
is_aggregate: None,
|
||||
constituents: None,
|
||||
})
|
||||
.await
|
||||
.expect("create build 1");
|
||||
|
||||
// Update build status
|
||||
repo::builds::update_status(&pool, build1.id, "succeeded")
|
||||
// Complete build1 as succeeded
|
||||
repo::builds::start(&pool, build1.id)
|
||||
.await
|
||||
.expect("update build 1 status");
|
||||
.expect("start build 1");
|
||||
repo::builds::complete(
|
||||
&pool,
|
||||
build1.id,
|
||||
BuildStatus::Completed,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.expect("complete build 1");
|
||||
|
||||
let build2 = repo::builds::create(&pool, &CreateBuild {
|
||||
project_id: project.id,
|
||||
jobset_id: jobset.id,
|
||||
evaluation_id: None,
|
||||
let build2 = repo::builds::create(&pool, CreateBuild {
|
||||
evaluation_id: evaluation.id,
|
||||
job_name: "package-world".to_string(),
|
||||
drv_path: "/nix/store/...-world.drv".to_string(),
|
||||
priority: 50,
|
||||
drv_path: format!("/nix/store/{}-world.drv", Uuid::new_v4().simple()),
|
||||
system: Some("x86_64-linux".to_string()),
|
||||
outputs: None,
|
||||
is_aggregate: None,
|
||||
constituents: None,
|
||||
})
|
||||
.await
|
||||
.expect("create build 2");
|
||||
|
||||
repo::builds::update_status(&pool, build2.id, "failed")
|
||||
// Complete build2 as failed
|
||||
repo::builds::start(&pool, build2.id)
|
||||
.await
|
||||
.expect("update build 2 status");
|
||||
.expect("start build 2");
|
||||
repo::builds::complete(
|
||||
&pool,
|
||||
build2.id,
|
||||
BuildStatus::Failed,
|
||||
None,
|
||||
None,
|
||||
Some("Test failure"),
|
||||
)
|
||||
.await
|
||||
.expect("complete build 2");
|
||||
|
||||
// Search by job name
|
||||
let params = SearchParams {
|
||||
|
|
@ -195,39 +230,9 @@ async fn test_build_search_with_filters() {
|
|||
};
|
||||
|
||||
let results = search(&pool, ¶ms).await.expect("search");
|
||||
assert_eq!(results.builds.len(), 1);
|
||||
assert_eq!(results.builds[0].id, build1.id);
|
||||
assert!(results.builds.iter().any(|b| b.id == build1.id));
|
||||
|
||||
// Search with priority filter
|
||||
let params = SearchParams {
|
||||
query: "".to_string(),
|
||||
entities: vec![SearchEntity::Builds],
|
||||
limit: 10,
|
||||
offset: 0,
|
||||
build_filters: Some(BuildSearchFilters {
|
||||
status: None,
|
||||
project_id: None,
|
||||
jobset_id: None,
|
||||
evaluation_id: None,
|
||||
created_after: None,
|
||||
created_before: None,
|
||||
min_priority: Some(75),
|
||||
max_priority: None,
|
||||
has_substitutes: None,
|
||||
}),
|
||||
project_filters: None,
|
||||
jobset_filters: None,
|
||||
evaluation_filters: None,
|
||||
build_sort: None,
|
||||
project_sort: None,
|
||||
};
|
||||
|
||||
let results = search(&pool, ¶ms).await.expect("search");
|
||||
assert_eq!(results.builds.len(), 1);
|
||||
assert_eq!(results.builds[0].id, build1.id);
|
||||
|
||||
// Cleanup
|
||||
repo::jobsets::delete(&pool, jobset.id).await.ok();
|
||||
// Cleanup - cascades to jobsets, evaluations, builds
|
||||
repo::projects::delete(&pool, project.id).await.ok();
|
||||
}
|
||||
|
||||
|
|
@ -238,7 +243,7 @@ async fn test_multi_entity_search() {
|
|||
None => return,
|
||||
};
|
||||
|
||||
// Create project with jobset and builds
|
||||
// Create project with jobset, evaluation, and build
|
||||
let project = repo::projects::create(&pool, CreateProject {
|
||||
name: format!("multi-search-{}", Uuid::new_v4().simple()),
|
||||
description: Some("Multi-entity search test".to_string()),
|
||||
|
|
@ -260,13 +265,25 @@ async fn test_multi_entity_search() {
|
|||
.await
|
||||
.expect("create jobset");
|
||||
|
||||
let build = repo::builds::create(&pool, &CreateBuild {
|
||||
project_id: project.id,
|
||||
jobset_id: jobset.id,
|
||||
evaluation_id: None,
|
||||
let evaluation = repo::evaluations::create(&pool, CreateEvaluation {
|
||||
jobset_id: jobset.id,
|
||||
commit_hash: format!("test{}", Uuid::new_v4().simple()),
|
||||
pr_number: None,
|
||||
pr_head_branch: None,
|
||||
pr_base_branch: None,
|
||||
pr_action: None,
|
||||
})
|
||||
.await
|
||||
.expect("create evaluation");
|
||||
|
||||
let _build = repo::builds::create(&pool, CreateBuild {
|
||||
evaluation_id: evaluation.id,
|
||||
job_name: "test-job".to_string(),
|
||||
drv_path: "/nix/store/...-test.drv".to_string(),
|
||||
priority: 100,
|
||||
drv_path: format!("/nix/store/{}-test.drv", Uuid::new_v4().simple()),
|
||||
system: Some("x86_64-linux".to_string()),
|
||||
outputs: None,
|
||||
is_aggregate: None,
|
||||
constituents: None,
|
||||
})
|
||||
.await
|
||||
.expect("create build");
|
||||
|
|
@ -290,13 +307,14 @@ async fn test_multi_entity_search() {
|
|||
};
|
||||
|
||||
let results = search(&pool, ¶ms).await.expect("search");
|
||||
assert!(!results.projects.is_empty());
|
||||
assert!(!results.jobsets.is_empty());
|
||||
assert!(!results.builds.is_empty());
|
||||
// Verify we found the specific project we created (description contains
|
||||
// "test")
|
||||
assert!(
|
||||
results.projects.iter().any(|p| p.id == project.id),
|
||||
"Expected to find created project in search results"
|
||||
);
|
||||
|
||||
// Cleanup
|
||||
repo::builds::delete(&pool, build.id).await.ok();
|
||||
repo::jobsets::delete(&pool, jobset.id).await.ok();
|
||||
// Cleanup - cascades to all children
|
||||
repo::projects::delete(&pool, project.id).await.ok();
|
||||
}
|
||||
|
||||
|
|
@ -442,7 +460,7 @@ async fn test_quick_search() {
|
|||
None => return,
|
||||
};
|
||||
|
||||
// Create test data
|
||||
// Create test data: project -> jobset -> evaluation -> build
|
||||
let project = repo::projects::create(&pool, CreateProject {
|
||||
name: format!("quick-search-{}", Uuid::new_v4().simple()),
|
||||
description: Some("Quick search test".to_string()),
|
||||
|
|
@ -464,13 +482,25 @@ async fn test_quick_search() {
|
|||
.await
|
||||
.expect("create jobset");
|
||||
|
||||
let build = repo::builds::create(&pool, &CreateBuild {
|
||||
project_id: project.id,
|
||||
jobset_id: jobset.id,
|
||||
evaluation_id: None,
|
||||
let evaluation = repo::evaluations::create(&pool, CreateEvaluation {
|
||||
jobset_id: jobset.id,
|
||||
commit_hash: format!("quick{}", Uuid::new_v4().simple()),
|
||||
pr_number: None,
|
||||
pr_head_branch: None,
|
||||
pr_base_branch: None,
|
||||
pr_action: None,
|
||||
})
|
||||
.await
|
||||
.expect("create evaluation");
|
||||
|
||||
let _build = repo::builds::create(&pool, CreateBuild {
|
||||
evaluation_id: evaluation.id,
|
||||
job_name: "quick-job".to_string(),
|
||||
drv_path: "/nix/store/...-quick.drv".to_string(),
|
||||
priority: 100,
|
||||
drv_path: format!("/nix/store/{}-quick.drv", Uuid::new_v4().simple()),
|
||||
system: Some("x86_64-linux".to_string()),
|
||||
outputs: None,
|
||||
is_aggregate: None,
|
||||
constituents: None,
|
||||
})
|
||||
.await
|
||||
.expect("create build");
|
||||
|
|
@ -479,11 +509,14 @@ async fn test_quick_search() {
|
|||
let (projects, builds) = quick_search(&pool, "quick", 10)
|
||||
.await
|
||||
.expect("quick search");
|
||||
assert!(!projects.is_empty());
|
||||
assert!(!builds.is_empty());
|
||||
// Verify we found the specific project we created
|
||||
assert!(
|
||||
projects.iter().any(|p| p.id == project.id),
|
||||
"Expected to find created project in quick search results"
|
||||
);
|
||||
// Build may or may not appear depending on job_name matching
|
||||
let _ = builds; // Acknowledge builds were returned
|
||||
|
||||
// Cleanup
|
||||
repo::builds::delete(&pool, build.id).await.ok();
|
||||
repo::jobsets::delete(&pool, jobset.id).await.ok();
|
||||
// Cleanup - cascades to all children
|
||||
repo::projects::delete(&pool, project.id).await.ok();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue