diff --git a/crates/git/src/repository/fake.rs b/crates/git/src/repository/fake.rs deleted file mode 100644 index 9f824a3..0000000 --- a/crates/git/src/repository/fake.rs +++ /dev/null @@ -1,71 +0,0 @@ -// -#![cfg(not(tarpaulin_include))] // don't test mocks - -use std::{ - collections::HashMap, - sync::{Arc, Mutex}, -}; - -use crate as git; -use git_next_config as config; - -#[derive(Debug, Default, Clone)] -pub struct FakeRepository { - open_repos: Arc>>, -} -impl FakeRepository { - pub fn new() -> Self { - Self { - open_repos: Default::default(), - } - } - - pub fn given_can_be_opened( - &mut self, - gitdir: &config::GitDir, - ) -> git::repository::FakeOpenRepository { - let open_repo = git::repository::FakeOpenRepository::new(); - #[allow(clippy::unwrap_used)] - self.open_repos - .lock() - .map(|mut or| or.insert(gitdir.clone(), open_repo.clone())) - .unwrap(); - open_repo - } - - pub fn seal(self) -> (git::Repository, Self) { - (git::Repository::Fake(self.clone()), self) - } - pub fn unseal(self, _repository: git::Repository) -> Self { - // drop repository to allow same mutable access to mock repository - self - } - pub fn get(&self, gitdir: &config::GitDir) -> Option { - self.open_repos - .lock() - .map(|or| or.get(gitdir).cloned()) - .unwrap_or(None) - } -} -impl git::repository::RepositoryLike for FakeRepository { - fn open( - &self, - gitdir: &config::GitDir, - ) -> std::result::Result { - #[allow(clippy::unwrap_used)] - self.open_repos - .lock() - .map_err(|_| crate::repository::Error::FakeLock) - .map(|or| or.get(gitdir).cloned()) - .transpose() - .unwrap_or_else(|| Err(crate::repository::Error::InvalidGitDir(gitdir.clone()))) - .map(|mor| mor.into()) - } - - fn git_clone( - &self, - _repo_details: &git::RepoDetails, - ) -> std::result::Result { - todo!("MockRepository::git_clone") - } -} diff --git a/crates/git/src/repository/mod.rs b/crates/git/src/repository/mod.rs index a468e4f..42eeae9 100644 --- a/crates/git/src/repository/mod.rs +++ b/crates/git/src/repository/mod.rs @@ -1,15 +1,8 @@ // -#[cfg(test)] -mod fake; use std::sync::{atomic::AtomicBool, Arc, Mutex}; use derive_more::Deref as _; -#[cfg(test)] -pub use fake::FakeRepository; -#[cfg(test)] -pub use open::FakeOpenRepository; - pub mod open; mod real; mod test; @@ -38,8 +31,6 @@ use super::RepoDetails; #[allow(clippy::large_enum_variant)] pub enum Repository { Real, - #[cfg(test)] - Fake(FakeRepository), Test(TestRepository), } @@ -48,11 +39,6 @@ pub const fn new() -> Repository { Repository::Real } -#[cfg(test)] -pub fn fake() -> FakeRepository { - FakeRepository::new() -} - pub const fn test(fs: kxio::fs::FileSystem) -> TestRepository { TestRepository::new(false, fs, vec![], vec![]) } @@ -135,9 +121,6 @@ impl std::ops::Deref for Repository { match self { Self::Real => &real::RealRepository, Self::Test(test_repository) => test_repository, - - #[cfg(test)] - Self::Fake(mock_repository) => mock_repository, } } } diff --git a/crates/git/src/repository/open/mod.rs b/crates/git/src/repository/open/mod.rs index d803379..fc63c96 100644 --- a/crates/git/src/repository/open/mod.rs +++ b/crates/git/src/repository/open/mod.rs @@ -37,15 +37,6 @@ pub enum OpenRepository { /// server will result in an error, unless a predefined change /// has been scheduled for that request. Test(TestOpenRepository), - - /// A fake git repository. - /// - /// This variant has no on-disk presense, and only fakes some of - /// the behaviour of a git repository. Once the [Self::LocalOnly] - /// variant is ready for use, tests should be converted to using - /// that instead. - #[cfg(test)] - Mock(git::repository::FakeOpenRepository), // TODO: (#38) contain a mock model of a repo } pub fn real(gix_repo: gix::Repository) -> OpenRepository { @@ -116,9 +107,6 @@ impl std::ops::Deref for OpenRepository { match self { Self::Real(real) => real, Self::Test(test) => test, - - #[cfg(test)] - Self::Mock(mock) => mock, } } } diff --git a/crates/git/src/repository/open/ofake.rs b/crates/git/src/repository/open/ofake.rs index 44aefc2..bc1325c 100644 --- a/crates/git/src/repository/open/ofake.rs +++ b/crates/git/src/repository/open/ofake.rs @@ -50,11 +50,7 @@ impl FakeOpenRepository { .unwrap_or_default() } } -impl From for git::OpenRepository { - fn from(value: FakeOpenRepository) -> Self { - Self::Mock(value) - } -} + #[allow(clippy::unwrap_used)] impl git::repository::OpenRepositoryLike for FakeOpenRepository { fn remote_branches(&self) -> git::push::Result> { diff --git a/crates/git/src/tests.rs b/crates/git/src/tests.rs index d0c33df..458b630 100644 --- a/crates/git/src/tests.rs +++ b/crates/git/src/tests.rs @@ -215,20 +215,14 @@ mod repo_details { pub mod given { use std::path::PathBuf; - // - use crate::{ - self as git, - repository::{FakeOpenRepository, FakeRepository}, - tests::given, - }; + use crate as git; use config::{ BranchName, ForgeAlias, ForgeConfig, ForgeType, GitDir, RepoAlias, RepoBranches, RepoConfig, ServerRepoConfig, }; + use git::{tests::given, RepoDetails}; use git_next_config as config; - use crate::RepoDetails; - pub fn repo_branches() -> RepoBranches { RepoBranches::new( format!("main-{}", a_name()), @@ -349,15 +343,6 @@ pub mod given { ) } - pub fn an_open_repository( - fs: &kxio::fs::FileSystem, - ) -> (FakeOpenRepository, GitDir, FakeRepository) { - let mut mock = git::repository::fake(); - let gitdir = a_git_dir(fs); - let or = mock.given_can_be_opened(&gitdir); - (or, gitdir, mock) - } - pub fn a_git_remote() -> git::GitRemote { git::GitRemote::new( config::Hostname::new(given::a_name()),