From 8494b3ed3ddf42f10012ad67d177afa381355ec7 Mon Sep 17 00:00:00 2001 From: J Robert Ray Date: Fri, 9 Jun 2023 18:03:26 -0700 Subject: [PATCH] Add test coverage for "which embeds" validation This new test reaches the validation check at the end of PkgRequirementsValidator::validate_request_against_existing_state which is checking that a new component requirement is not bringing in a new embedded package that conflicts with the current state. Signed-off-by: J Robert Ray --- crates/spk-solve/src/solver_test.rs | 82 +++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/crates/spk-solve/src/solver_test.rs b/crates/spk-solve/src/solver_test.rs index 05fa9fce4b..a8e24a1ef1 100644 --- a/crates/spk-solve/src/solver_test.rs +++ b/crates/spk-solve/src/solver_test.rs @@ -465,6 +465,50 @@ async fn test_solver_dependency_already_satisfied(mut solver: Solver) { assert_resolved!(packages, "dep-1", "1.0.0"); } +#[rstest] +#[tokio::test] +async fn test_solver_dependency_already_satisfied_conflicting_components(mut solver: Solver) { + // like test_solver_dependency_already_satisfied but with conflicting components + + let repo = make_repo!( + [ + { + "pkg": "pkg-top/1.0.0", + "install": { + "requirements": [{"pkg": "dep-1:comp1/~1.0.0"}, {"pkg": "dep-2/1"}] + }, + }, + { + "pkg": "dep-1/1.0.0", + "install": { + "components": [ + {"name": "comp1", "embedded_packages": ["em-1/1.0.0"]}, + {"name": "comp2", "embedded_packages": ["em-1/2.0.0"]}, + ], + "embedded": [ + {"pkg": "em-1/1.0.0"}, + {"pkg": "em-1/2.0.0"}, + ], + }, + }, + // when dep_2 gets resolved, it will re-request this but comp2 conflicts with comp1 + {"pkg": "dep-2/1.0.0", "install": {"requirements": [{"pkg": "dep-1:comp2/1"}]}}, + ] + ); + solver.add_repository(Arc::new(repo)); + solver.add_request(request!("pkg-top")); + + // XXX: This test provides coverage for the + // "requires {}:{} which embeds {}" incompatibility check inside + // PkgRequirementsValidator::validate_request_against_existing_state. + // How can this test code verify that the solver is actually hitting + // that code path? + + run_and_print_resolve_for_tests(&solver) + .await + .expect_err("solve should fail"); +} + #[rstest] #[tokio::test] async fn test_solver_dependency_reopen_solvable(mut solver: Solver) { @@ -2344,6 +2388,44 @@ async fn test_solver_component_embedded_multiple_versions( } } +#[rstest] +#[tokio::test] +async fn test_solver_component_embedded_incompatible_requests(mut solver: Solver) { + // test when different components of a package embedded packages that + // make incompatible requests + + let repo = make_repo!( + [ + { + "pkg": "mypkg/1.0.0", + "install": { + "components": [ + {"name": "comp1"}, + {"name": "comp2"}, + ], + "embedded": [ + {"pkg": "dep-e1/1.0.0", + "install": {"components": [ + {"name": "comp1", "requirements": [{"pkg": "dep-e2/1.0.0"}]}, + {"name": "comp2", "requirements": [{"pkg": "dep-e2/2.0.0"}]} + ]} + }, + ], + }, + }, + ] + ); + let repo = Arc::new(repo); + + solver.add_repository(repo); + solver.add_request(request!("mypkg:comp1")); + solver.add_request(request!("mypkg:comp2")); + + run_and_print_resolve_for_tests(&solver) + .await + .expect_err("expected solve to fail"); +} + #[rstest] fn test_solver_get_request_validator() { let solver = Solver::default();