Skip to content

Commit

Permalink
Add test coverage for "which embeds" validation
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jrray committed Dec 5, 2023
1 parent 254fc98 commit d5b071d
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions crates/spk-solve/src/solver_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,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) {
Expand Down Expand Up @@ -2338,6 +2382,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();
Expand Down

0 comments on commit d5b071d

Please sign in to comment.