Skip to content

Commit

Permalink
Add test for embedded requirements
Browse files Browse the repository at this point in the history
Signed-off-by: J Robert Ray <[email protected]>
  • Loading branch information
jrray committed Jun 10, 2023
1 parent fe4dbf2 commit 65998fd
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/spk-solve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ macro_rules! request {
RequestedBy::SpkInternalTest,
))
};
($req:ident) => {
$crate::Request::Pkg($crate::PkgRequest::new(
$crate::parse_ident_range($req).unwrap(),
RequestedBy::SpkInternalTest,
))
};
($req:tt) => {{
let value = serde_json::json!($req);
let req: $crate::Request = serde_json::from_value(value).unwrap();
Expand Down
57 changes: 57 additions & 0 deletions crates/spk-solve/src/solver_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2130,6 +2130,63 @@ async fn test_solver_component_embedded(mut solver: Solver) {
assert!(res.is_err());
}

#[rstest]
#[case::comp1("mypkg:comp1", true)]
#[case::comp2("mypkg:comp2", false)]
#[tokio::test]
async fn test_solver_component_embedded_component_requirements(
mut solver: Solver,
#[case] package_to_request: &str,
#[case] expected_solve_result: bool,
) {
// test a component with embedded packages that have their own requirements
// - the requirements are added to the solution

let repo = make_repo!(
[
{
"pkg": "mypkg/1.0.0",
"install": {
"components": [
{"name": "comp1"},
{"name": "comp2"},
],
"embedded": [
{"pkg": "dep-e1/1.0.0",
"install": {"components": [
// comp1 requires a package that exists
{"name": "comp1", "requirements": [{"pkg": "dep-e2/1.0.0"}]},
// comp2 requires a package that does not exist
{"name": "comp2", "requirements": [{"pkg": "dep-e3/1.0.0"}]}
]}
},
],
},
},
{"pkg": "dep-e2/1.0.0"},
]
);
let repo = Arc::new(repo);

solver.add_repository(repo);
solver.add_request(request!(package_to_request));

match run_and_print_resolve_for_tests(&solver).await {
Ok(solution) => {
assert!(expected_solve_result, "expected solve to fail");

assert_resolved!(
solution,
"dep-e2",
build = Build::Embedded(EmbeddedSource::Unknown)
);
}
Err(_) => {
assert!(!expected_solve_result, "expected solve to succeed");
}
}
}

#[rstest]
fn test_solver_get_request_validator() {
let solver = Solver::default();
Expand Down

0 comments on commit 65998fd

Please sign in to comment.