Skip to content

Commit

Permalink
test: Check ability to create wrapper types around repository
Browse files Browse the repository at this point in the history
  • Loading branch information
TilBlechschmidt committed Jun 14, 2024
1 parent a4a503d commit 88cfe64
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions crates/core/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ use pretty_assertions::assert_eq;
use rstest::{fixture, rstest};
use rustic_core::{
repofile::SnapshotFile, BackupOptions, CheckOptions, ConfigOptions, FindMatches, FindNode,
KeyOptions, LimitOption, LsOptions, NoProgressBars, OpenStatus, PathList, Repository,
RepositoryBackends, RepositoryOptions, RusticResult,
FullIndex, IndexedFull, IndexedStatus, KeyOptions, LimitOption, LsOptions, NoProgressBars,
OpenStatus, PathList, Repository, RepositoryBackends, RepositoryOptions, RusticResult,
};
use rustic_core::{
repofile::{Metadata, Node},
Expand Down Expand Up @@ -464,3 +464,32 @@ fn test_prune(

Ok(())
}

/// Verifies that users can create wrappers around repositories
/// without resorting to generics. The rationale is that such
/// types can be used to dynamically open, store, and cache repos.
///
/// See issue #277 for more context.
#[test]
fn test_wrapping_in_new_type() -> Result<()> {
struct Wrapper(Repository<NoProgressBars, IndexedStatus<FullIndex, OpenStatus>>);

impl Wrapper {
fn new() -> Result<Self> {
Ok(Self(set_up_repo()?.to_indexed()?))
}
}

/// Fake function that "does something" with a fully indexed repo
/// (without actually relying on any functionality for the test)
fn use_repo(_: &impl IndexedFull) {}

let mut collection: Vec<Wrapper> = Vec::new();

collection.push(Wrapper::new()?);
collection.push(Wrapper::new()?);

collection.iter().map(|r| &r.0).for_each(use_repo);

Ok(())
}

0 comments on commit 88cfe64

Please sign in to comment.