Skip to content

Commit c0d5c7a

Browse files
test: Check ability to create wrapper types around repository
1 parent 7467cd7 commit c0d5c7a

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

crates/core/tests/integration.rs

+31-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ use pretty_assertions::assert_eq;
3535
use rstest::{fixture, rstest};
3636
use rustic_core::{
3737
repofile::SnapshotFile, BackupOptions, CheckOptions, ConfigOptions, FindMatches, FindNode,
38-
KeyOptions, LimitOption, LsOptions, NoProgressBars, OpenStatus, PathList, Repository,
39-
RepositoryBackends, RepositoryOptions, RusticResult,
38+
FullIndex, IndexedFull, IndexedStatus, KeyOptions, LimitOption, LsOptions, NoProgressBars,
39+
OpenStatus, PathList, Repository, RepositoryBackends, RepositoryOptions, RusticResult,
4040
};
4141
use rustic_core::{
4242
repofile::{Metadata, Node},
@@ -464,3 +464,32 @@ fn test_prune(
464464

465465
Ok(())
466466
}
467+
468+
/// Verifies that users can create wrappers around repositories
469+
/// without resorting to generics. The rationale is that such
470+
/// types can be used to dynamically open, store, and cache repos.
471+
///
472+
/// See issue #277 for more context.
473+
#[test]
474+
fn test_wrapping_in_new_type() -> Result<()> {
475+
struct Wrapper(Repository<NoProgressBars, IndexedStatus<FullIndex, OpenStatus>>);
476+
477+
impl Wrapper {
478+
fn new() -> Result<Self> {
479+
Ok(Self(set_up_repo()?.to_indexed()?))
480+
}
481+
}
482+
483+
/// Fake function that "does something" with a fully indexed repo
484+
/// (without actually relying on any functionality for the test)
485+
fn use_repo(_: &impl IndexedFull) {}
486+
487+
let mut collection: Vec<Wrapper> = Vec::new();
488+
489+
collection.push(Wrapper::new()?);
490+
collection.push(Wrapper::new()?);
491+
492+
collection.iter().map(|r| &r.0).for_each(use_repo);
493+
494+
Ok(())
495+
}

0 commit comments

Comments
 (0)