-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test to confirm
spk rm
works with legacy version tags
How the version number is specified on the command line shouldn't matter, as long as it would be considered equal to how the version exists on disk, e.g., "1.0" == "1.0.0". Signed-off-by: J Robert Ray <jrray@jrray.org>
- Loading branch information
Showing
2 changed files
with
148 additions
and
0 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,144 @@ | ||
// Copyright (c) Sony Pictures Imageworks, et al. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// https://github.com/imageworks/spk | ||
|
||
use clap::Parser; | ||
use futures::prelude::*; | ||
use relative_path::RelativePathBuf; | ||
use rstest::rstest; | ||
use spfs::config::Remote; | ||
use spfs::storage::EntryType; | ||
use spfs::RemoteAddress; | ||
use spk_schema::foundation::ident_component::Component; | ||
use spk_schema::ident_ops::VerbatimTagStrategy; | ||
use spk_schema::recipe; | ||
use spk_solve::spec; | ||
use spk_storage::fixtures::*; | ||
use spk_storage::RepositoryHandle; | ||
|
||
use super::{Remove, Run}; | ||
|
||
#[derive(Parser)] | ||
struct Opt { | ||
#[clap(flatten)] | ||
remove: Remove, | ||
} | ||
|
||
/// When the legacy-spk-version-tags feature is enabled, and when a package | ||
/// is published with a non-normalized version tag, `spk rm` is expected to | ||
/// successfully delete the package. | ||
#[rstest] | ||
#[tokio::test] | ||
async fn test_remove_succeeds_for_package_saved_with_legacy_version_tag( | ||
#[values("1", "1.0", "1.0.0", "1.0.0.0", "1.0.0.0.0")] version_to_publish: &str, | ||
#[values("1", "1.0", "1.0.0", "1.0.0.0", "1.0.0.0.0")] version_to_delete: &str, | ||
) { | ||
let mut rt = spfs_runtime_with_tag_strategy::<VerbatimTagStrategy>().await; | ||
let remote_repo = spfsrepo().await; | ||
|
||
rt.add_remote_repo( | ||
"origin", | ||
Remote::Address(RemoteAddress { | ||
address: remote_repo.address().clone(), | ||
}), | ||
) | ||
.unwrap(); | ||
|
||
let recipe = recipe!({"pkg": format!("my-local-pkg/{version_to_publish}")}); | ||
rt.tmprepo.publish_recipe(&recipe).await.unwrap(); | ||
let spec = spec!({"pkg": format!("my-local-pkg/{version_to_publish}/BGSHW3CN")}); | ||
rt.tmprepo | ||
.publish_package( | ||
&spec, | ||
&vec![(Component::Run, empty_layer_digest())] | ||
.into_iter() | ||
.collect(), | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
// Confirm that the tags were created with the legacy version tag strategy. | ||
for (tag_path, entry_type_filter) in [ | ||
( | ||
"spk/spec/my-local-pkg", | ||
Box::new(|tag: &_| matches!(tag, Ok(EntryType::Tag(tag)) if tag == version_to_publish)) | ||
as Box<dyn for<'a> Fn(&'a Result<EntryType, spfs::Error>) -> bool>, | ||
), | ||
( | ||
"spk/pkg/my-local-pkg", | ||
Box::new(|tag| matches!(tag, Ok(EntryType::Folder(tag)) if tag == version_to_publish)), | ||
), | ||
] | ||
.iter() | ||
{ | ||
match &*rt.tmprepo { | ||
RepositoryHandle::SPFSWithVerbatimTags(spfs) => { | ||
assert!( | ||
spfs.ls_tags(&RelativePathBuf::from(tag_path)) | ||
.filter(|tag| { future::ready(entry_type_filter(tag)) }) | ||
.next() | ||
.await | ||
.is_some(), | ||
"expected \"{tag_path}/{version_to_publish}\" tag to be found" | ||
); | ||
} | ||
_ => panic!("expected SPFSWithVerbatimTags"), | ||
} | ||
} | ||
|
||
match &*rt.tmprepo { | ||
RepositoryHandle::SPFSWithVerbatimTags(spfs) => { | ||
assert!( | ||
spfs.ls_tags(&RelativePathBuf::from("spk/spec/my-local-pkg")) | ||
.filter(|tag| { | ||
future::ready( | ||
matches!(tag, Ok(EntryType::Tag(tag)) if tag == version_to_publish), | ||
) | ||
}) | ||
.next() | ||
.await | ||
.is_some(), | ||
"expected \"{version_to_publish}\" tag to be found" | ||
); | ||
} | ||
_ => panic!("expected SPFSWithVerbatimTags"), | ||
} | ||
|
||
let mut opt = Opt::try_parse_from([ | ||
"remove", | ||
"--legacy-spk-version-tags", | ||
"--yes", | ||
&format!("my-local-pkg/{version_to_delete}"), | ||
]) | ||
.unwrap(); | ||
opt.remove.run().await.unwrap(); | ||
|
||
// Confirm that the tags are now gone. | ||
for (tag_path, entry_type_filter) in [ | ||
( | ||
"spk/spec/my-local-pkg", | ||
Box::new(|tag: &_| matches!(tag, Ok(EntryType::Tag(tag)) if tag == version_to_publish)) | ||
as Box<dyn for<'a> Fn(&'a Result<EntryType, spfs::Error>) -> bool>, | ||
), | ||
( | ||
"spk/pkg/my-local-pkg", | ||
Box::new(|tag| matches!(tag, Ok(EntryType::Folder(tag)) if tag == version_to_publish)), | ||
), | ||
] | ||
.iter() | ||
{ | ||
match &*rt.tmprepo { | ||
RepositoryHandle::SPFSWithVerbatimTags(spfs) => { | ||
assert!( | ||
spfs.ls_tags(&RelativePathBuf::from(tag_path)) | ||
.filter(|tag| { future::ready(entry_type_filter(tag)) }) | ||
.next() | ||
.await | ||
.is_none(), | ||
"expected \"{tag_path}/{version_to_publish}\" tag to be gone" | ||
); | ||
} | ||
_ => panic!("expected SPFSWithVerbatimTags"), | ||
} | ||
} | ||
} |