Skip to content

Commit

Permalink
testutils: allow passing TestRepoBackend to TestWorkspace too
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvonz committed Sep 18, 2023
1 parent 8263c05 commit 76e9de5
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/testutils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,25 @@ pub struct TestWorkspace {

impl TestWorkspace {
pub fn init(settings: &UserSettings, use_git: bool) -> Self {
let backend = if use_git {
TestRepoBackend::Git
} else {
TestRepoBackend::Local
};
Self::init_with_backend(settings, backend)
}

pub fn init_with_backend(settings: &UserSettings, backend: TestRepoBackend) -> Self {
let temp_dir = new_temp_dir();

let workspace_root = temp_dir.path().join("repo");
fs::create_dir(&workspace_root).unwrap();

let (workspace, repo) = if use_git {
Workspace::init_internal_git(settings, &workspace_root).unwrap()
} else {
Workspace::init_local(settings, &workspace_root).unwrap()
};
let (workspace, repo) =
Workspace::init_with_backend(settings, &workspace_root, |store_path| {
backend.init_backend(store_path)
})
.unwrap();

Self {
temp_dir,
Expand Down

0 comments on commit 76e9de5

Please sign in to comment.