mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-27 06:23:18 +00:00
testutils: move default_store_factories() to TestEnvironment
It will capture the TestBackendData mapping.
This commit is contained in:
parent
d4786a3256
commit
7b5df93fe4
5 changed files with 28 additions and 29 deletions
|
@ -35,7 +35,7 @@ fn test_load_at_operation() {
|
|||
let loader = RepoLoader::init_from_file_system(
|
||||
&settings,
|
||||
test_repo.repo_path(),
|
||||
&TestRepo::default_store_factories(),
|
||||
&test_repo.env.default_store_factories(),
|
||||
)
|
||||
.unwrap();
|
||||
let head_repo = loader.load_at_head(&settings).unwrap();
|
||||
|
@ -46,7 +46,7 @@ fn test_load_at_operation() {
|
|||
let loader = RepoLoader::init_from_file_system(
|
||||
&settings,
|
||||
test_repo.repo_path(),
|
||||
&TestRepo::default_store_factories(),
|
||||
&test_repo.env.default_store_factories(),
|
||||
)
|
||||
.unwrap();
|
||||
let old_repo = loader.load_at(repo.operation()).unwrap();
|
||||
|
|
|
@ -52,7 +52,6 @@ use test_case::test_case;
|
|||
use testutils::commit_with_tree;
|
||||
use testutils::create_tree;
|
||||
use testutils::write_random_commit;
|
||||
use testutils::TestRepo;
|
||||
use testutils::TestRepoBackend;
|
||||
use testutils::TestWorkspace;
|
||||
|
||||
|
@ -384,7 +383,7 @@ fn test_acl() {
|
|||
let mut ws = Workspace::load(
|
||||
&settings,
|
||||
&workspace_root,
|
||||
&TestRepo::default_store_factories(),
|
||||
&test_workspace.env.default_store_factories(),
|
||||
&default_working_copy_factories(),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
|
@ -26,7 +26,6 @@ use jj_lib::workspace::Workspace;
|
|||
use testutils::commit_with_tree;
|
||||
use testutils::create_tree;
|
||||
use testutils::write_working_copy_file;
|
||||
use testutils::TestRepo;
|
||||
use testutils::TestWorkspace;
|
||||
|
||||
#[test]
|
||||
|
@ -58,7 +57,7 @@ fn test_concurrent_checkout() {
|
|||
let mut ws2 = Workspace::load(
|
||||
&settings,
|
||||
&workspace1_root,
|
||||
&TestRepo::default_store_factories(),
|
||||
&test_workspace1.env.default_store_factories(),
|
||||
&default_working_copy_factories(),
|
||||
)
|
||||
.unwrap();
|
||||
|
@ -75,7 +74,7 @@ fn test_concurrent_checkout() {
|
|||
let ws3 = Workspace::load(
|
||||
&settings,
|
||||
&workspace1_root,
|
||||
&TestRepo::default_store_factories(),
|
||||
&test_workspace1.env.default_store_factories(),
|
||||
&default_working_copy_factories(),
|
||||
)
|
||||
.unwrap();
|
||||
|
@ -113,6 +112,7 @@ fn test_checkout_parallel() {
|
|||
|
||||
thread::scope(|s| {
|
||||
for tree_id in &tree_ids {
|
||||
let test_env = &test_workspace.env;
|
||||
let op_id = repo.op_id().clone();
|
||||
let tree_ids = tree_ids.clone();
|
||||
let commit = commit_with_tree(repo.store(), tree_id.clone());
|
||||
|
@ -122,7 +122,7 @@ fn test_checkout_parallel() {
|
|||
let mut workspace = Workspace::load(
|
||||
&settings,
|
||||
&workspace_root,
|
||||
&TestRepo::default_store_factories(),
|
||||
&test_env.default_store_factories(),
|
||||
&default_working_copy_factories(),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
|
@ -21,19 +21,19 @@ use jj_lib::workspace::default_working_copy_factories;
|
|||
use jj_lib::workspace::default_working_copy_factory;
|
||||
use jj_lib::workspace::Workspace;
|
||||
use jj_lib::workspace::WorkspaceLoadError;
|
||||
use testutils::TestRepo;
|
||||
use testutils::TestEnvironment;
|
||||
use testutils::TestWorkspace;
|
||||
|
||||
#[test]
|
||||
fn test_load_bad_path() {
|
||||
let settings = testutils::user_settings();
|
||||
let temp_dir = testutils::new_temp_dir();
|
||||
let workspace_root = temp_dir.path().to_owned();
|
||||
let test_env = TestEnvironment::init();
|
||||
let workspace_root = test_env.root().to_owned();
|
||||
// We haven't created a repo in the workspace_root, so it should fail to load.
|
||||
let result = Workspace::load(
|
||||
&settings,
|
||||
&workspace_root,
|
||||
&TestRepo::default_store_factories(),
|
||||
&test_env.default_store_factories(),
|
||||
&default_working_copy_factories(),
|
||||
);
|
||||
assert_matches!(
|
||||
|
@ -77,7 +77,7 @@ fn test_init_additional_workspace() {
|
|||
let same_workspace = Workspace::load(
|
||||
&settings,
|
||||
&ws2_root,
|
||||
&TestRepo::default_store_factories(),
|
||||
&test_workspace.env.default_store_factories(),
|
||||
&default_working_copy_factories(),
|
||||
);
|
||||
assert!(same_workspace.is_ok());
|
||||
|
|
|
@ -134,12 +134,27 @@ impl TestEnvironment {
|
|||
self.temp_dir.path()
|
||||
}
|
||||
|
||||
pub fn default_store_factories(&self) -> StoreFactories {
|
||||
let mut factories = StoreFactories::default();
|
||||
factories.add_backend(
|
||||
"test",
|
||||
Box::new(|_settings, store_path| Ok(Box::new(TestBackend::load(store_path)))),
|
||||
);
|
||||
factories.add_backend(
|
||||
SecretBackend::name(),
|
||||
Box::new(|settings, store_path| {
|
||||
Ok(Box::new(SecretBackend::load(settings, store_path)?))
|
||||
}),
|
||||
);
|
||||
factories
|
||||
}
|
||||
|
||||
pub fn load_repo_at_head(
|
||||
&self,
|
||||
settings: &UserSettings,
|
||||
repo_path: &Path,
|
||||
) -> Arc<ReadonlyRepo> {
|
||||
RepoLoader::init_from_file_system(settings, repo_path, &TestRepo::default_store_factories())
|
||||
RepoLoader::init_from_file_system(settings, repo_path, &self.default_store_factories())
|
||||
.unwrap()
|
||||
.load_at_head(settings)
|
||||
.unwrap()
|
||||
|
@ -214,21 +229,6 @@ impl TestRepo {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn default_store_factories() -> StoreFactories {
|
||||
let mut factories = StoreFactories::default();
|
||||
factories.add_backend(
|
||||
"test",
|
||||
Box::new(|_settings, store_path| Ok(Box::new(TestBackend::load(store_path)))),
|
||||
);
|
||||
factories.add_backend(
|
||||
SecretBackend::name(),
|
||||
Box::new(|settings, store_path| {
|
||||
Ok(Box::new(SecretBackend::load(settings, store_path)?))
|
||||
}),
|
||||
);
|
||||
factories
|
||||
}
|
||||
|
||||
pub fn repo_path(&self) -> &Path {
|
||||
&self.repo_path
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue