-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix:
get_unresolved_requests()
and incompatible requests (#1138)
Removes unwrap, and changes function to return a Result for better error handling Signed-off-by: David Gilligan-Cook <[email protected]>
- Loading branch information
Showing
6 changed files
with
128 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Copyright (c) Contributors to the SPK project. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// https://github.com/spkenv/spk | ||
|
||
use clap::Parser; | ||
use rstest::rstest; | ||
use spfs::config::Remote; | ||
use spfs::RemoteAddress; | ||
use spk_cli_common::Run; | ||
use spk_solve::{recipe, spec, Component}; | ||
use spk_storage::fixtures::{empty_layer_digest, spfs_runtime, spfsrepo}; | ||
|
||
use super::Bake; | ||
|
||
#[derive(Parser)] | ||
struct Opt { | ||
#[clap(flatten)] | ||
bake: Bake, | ||
} | ||
|
||
#[rstest] | ||
#[tokio::test] | ||
async fn test_bake() { | ||
// Test the bake command runs | ||
let mut rt = spfs_runtime().await; | ||
let remote_repo = spfsrepo().await; | ||
|
||
// Populate the "origin" repo with one package. | ||
// The "local" repo is empty. | ||
rt.add_remote_repo( | ||
"origin", | ||
Remote::Address(RemoteAddress { | ||
address: remote_repo.address().clone(), | ||
}), | ||
) | ||
.unwrap(); | ||
|
||
let recipe = recipe!({"pkg": "my-pkg/1.0.1"}); | ||
remote_repo.publish_recipe(&recipe).await.unwrap(); | ||
let spec = spec!({"pkg": "my-pkg/1.0.1/ZPGKGOTY"}); | ||
remote_repo | ||
.publish_package( | ||
&spec, | ||
&vec![(Component::Run, empty_layer_digest())] | ||
.into_iter() | ||
.collect(), | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
// Test a basic bake | ||
let mut opt = Opt::try_parse_from(["bake", "--no-runtime", "my-pkg:run"]).unwrap(); | ||
let result = opt.bake.run().await.unwrap(); | ||
assert_eq!(result, 0); | ||
} | ||
|
||
#[rstest] | ||
#[tokio::test] | ||
async fn test_bake_incompatible_merged_request() { | ||
// Test bake with an incompatible set of requests | ||
let mut rt = spfs_runtime().await; | ||
let remote_repo = spfsrepo().await; | ||
|
||
// Populate the "origin" repo with one package. | ||
// The "local" repo is empty. | ||
rt.add_remote_repo( | ||
"origin", | ||
Remote::Address(RemoteAddress { | ||
address: remote_repo.address().clone(), | ||
}), | ||
) | ||
.unwrap(); | ||
|
||
let recipe = recipe!({"pkg": "my-pkg/1.0.33+r.1"}); | ||
remote_repo.publish_recipe(&recipe).await.unwrap(); | ||
let spec = spec!({"pkg": "my-pkg/1.0.33+r.1/ZPGKGOTY"}); | ||
remote_repo | ||
.publish_package( | ||
&spec, | ||
&vec![(Component::Run, empty_layer_digest())] | ||
.into_iter() | ||
.collect(), | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
// Test bake command with 2 incompatible requests. This should | ||
// not panic, it should error out | ||
let mut opt = Opt::try_parse_from([ | ||
"bake", | ||
"--no-runtime", | ||
"my-pkg:run/==1.0.33+r.1/ZPGKGOTY", | ||
"my-pkg:run/=1.0.99", | ||
]) | ||
.unwrap(); | ||
let result = opt.bake.run().await; | ||
println!("bake run result: {result:?}"); | ||
|
||
match result { | ||
Err(err) => { | ||
println!("Bake errored with: {err}"); | ||
} | ||
Ok(_value) => { | ||
panic!("Incompatible requests for same package should cause bake to error"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -785,6 +785,7 @@ | |
"YYYNNNNNNN", | ||
"YYYNNNYYYY", | ||
"ZLMZGDCVUOL", | ||
"ZPGKGOTY", | ||
"ZWOIF" | ||
], | ||
"enabled": true | ||
|