forked from kemitix/git-next
chore: remove unused Fake repo facade
This commit is contained in:
parent
94ad2c441c
commit
8ce4528c88
5 changed files with 3 additions and 122 deletions
|
@ -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<Mutex<HashMap<config::GitDir, git::repository::FakeOpenRepository>>>,
|
||||
}
|
||||
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<git::repository::FakeOpenRepository> {
|
||||
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<git::repository::OpenRepository, crate::repository::Error> {
|
||||
#[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<git::repository::OpenRepository, crate::repository::Error> {
|
||||
todo!("MockRepository::git_clone")
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,11 +50,7 @@ impl FakeOpenRepository {
|
|||
.unwrap_or_default()
|
||||
}
|
||||
}
|
||||
impl From<FakeOpenRepository> 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<Vec<config::BranchName>> {
|
||||
|
|
|
@ -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()),
|
||||
|
|
Loading…
Reference in a new issue