Compare commits
5 commits
2797538420
...
9b1c1d6d87
Author | SHA1 | Date | |
---|---|---|---|
9b1c1d6d87 | |||
4c0513cafb | |||
2cf21c11fc | |||
1773d4ecb9 | |||
399283ae97 |
8 changed files with 32 additions and 27 deletions
|
@ -96,3 +96,4 @@ tokio = { version = "1.37", features = ["rt", "macros"] }
|
|||
assert2 = "0.3"
|
||||
pretty_assertions = "1.4"
|
||||
rand = "0.8"
|
||||
mockall = "0.12"
|
||||
|
|
|
@ -56,6 +56,7 @@ actix = { workspace = true }
|
|||
assert2 = { workspace = true }
|
||||
rand = { workspace = true }
|
||||
pretty_assertions = { workspace = true }
|
||||
mockall = { workspace = true }
|
||||
|
||||
[lints.clippy]
|
||||
nursery = { level = "warn", priority = -1 }
|
||||
|
|
|
@ -22,4 +22,5 @@ pub use git_ref::GitRef;
|
|||
pub use git_remote::GitRemote;
|
||||
pub use repo_details::RepoDetails;
|
||||
pub use repository::OpenRepository;
|
||||
pub use repository::OpenRepositoryLike;
|
||||
pub use repository::Repository;
|
||||
|
|
|
@ -10,11 +10,11 @@ use crate as git;
|
|||
use git_next_config as config;
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct MockRepository {
|
||||
open_repos: Arc<Mutex<HashMap<config::GitDir, git::repository::MockOpenRepository>>>,
|
||||
clone_repos: Arc<Mutex<HashMap<config::GitDir, git::repository::MockOpenRepository>>>,
|
||||
pub struct FakeRepository {
|
||||
open_repos: Arc<Mutex<HashMap<config::GitDir, git::repository::FakeOpenRepository>>>,
|
||||
clone_repos: Arc<Mutex<HashMap<config::GitDir, git::repository::FakeOpenRepository>>>,
|
||||
}
|
||||
impl MockRepository {
|
||||
impl FakeRepository {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
open_repos: Default::default(),
|
||||
|
@ -25,9 +25,9 @@ impl MockRepository {
|
|||
pub fn given_can_be_opened(
|
||||
&mut self,
|
||||
repo_details: git::RepoDetails,
|
||||
) -> git::repository::MockOpenRepository {
|
||||
) -> git::repository::FakeOpenRepository {
|
||||
let gitdir = repo_details.gitdir.clone();
|
||||
let open_repo = git::repository::MockOpenRepository::new(repo_details);
|
||||
let open_repo = git::repository::FakeOpenRepository::new(repo_details);
|
||||
#[allow(clippy::unwrap_used)]
|
||||
self.open_repos
|
||||
.lock()
|
||||
|
@ -39,9 +39,9 @@ impl MockRepository {
|
|||
pub fn given_can_be_cloned(
|
||||
&mut self,
|
||||
repo_details: git::RepoDetails,
|
||||
) -> git::repository::MockOpenRepository {
|
||||
) -> git::repository::FakeOpenRepository {
|
||||
let gitdir = repo_details.gitdir.clone();
|
||||
let clone_repo = git::repository::MockOpenRepository::new(repo_details);
|
||||
let clone_repo = git::repository::FakeOpenRepository::new(repo_details);
|
||||
#[allow(clippy::unwrap_used)]
|
||||
self.clone_repos
|
||||
.lock()
|
||||
|
@ -57,14 +57,14 @@ impl MockRepository {
|
|||
// drop repository to allow same mutable access to mock repository
|
||||
self
|
||||
}
|
||||
pub fn get(&self, gitdir: &config::GitDir) -> Option<git::repository::MockOpenRepository> {
|
||||
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 MockRepository {
|
||||
impl git::repository::RepositoryLike for FakeRepository {
|
||||
fn open(
|
||||
&self,
|
||||
gitdir: &config::GitDir,
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
//
|
||||
mod mock;
|
||||
pub use mock::MockRepository;
|
||||
pub use open::MockOpenRepository;
|
||||
pub use mock::FakeRepository;
|
||||
pub use open::FakeOpenRepository;
|
||||
|
||||
mod open;
|
||||
pub mod open;
|
||||
mod real;
|
||||
pub mod test;
|
||||
|
||||
|
@ -33,15 +33,15 @@ use super::RepoDetails;
|
|||
pub enum Repository {
|
||||
Real,
|
||||
Test(TestRepository),
|
||||
Mock(MockRepository),
|
||||
Mock(FakeRepository),
|
||||
}
|
||||
|
||||
pub const fn new() -> Repository {
|
||||
Repository::Real
|
||||
}
|
||||
|
||||
pub fn mock() -> MockRepository {
|
||||
MockRepository::new()
|
||||
pub fn mock() -> FakeRepository {
|
||||
FakeRepository::new()
|
||||
}
|
||||
|
||||
pub fn new_test(fs: kxio::fs::FileSystem, hostname: config::Hostname) -> Repository {
|
||||
|
|
|
@ -17,7 +17,7 @@ use std::{
|
|||
use crate as git;
|
||||
use git::repository::Direction;
|
||||
use git_next_config as config;
|
||||
pub use omock::MockOpenRepository;
|
||||
pub use omock::FakeOpenRepository;
|
||||
pub use oreal::RealOpenRepository;
|
||||
pub use otest::TestOpenRepository;
|
||||
|
||||
|
@ -43,7 +43,7 @@ pub enum OpenRepository {
|
|||
/// the behaviour of a git repository. Once the [Self::LocalOnly]
|
||||
/// variant is ready for use, tests should be converted to using
|
||||
/// that instead.
|
||||
Mock(git::repository::MockOpenRepository), // TODO: (#38) contain a mock model of a repo
|
||||
Fake(git::repository::FakeOpenRepository), // TODO: (#38) contain a mock model of a repo
|
||||
}
|
||||
|
||||
pub fn real(gix_repo: gix::Repository) -> OpenRepository {
|
||||
|
@ -78,6 +78,7 @@ pub fn test_bare(
|
|||
OpenRepository::Test(open_repo)
|
||||
}
|
||||
|
||||
#[cfg_attr(test, mockall::automock)]
|
||||
pub trait OpenRepositoryLike {
|
||||
fn remote_branches(&self) -> git::push::Result<Vec<config::BranchName>>;
|
||||
fn find_default_remote(&self, direction: Direction) -> Option<git::GitRemote>;
|
||||
|
@ -113,7 +114,7 @@ impl std::ops::Deref for OpenRepository {
|
|||
match self {
|
||||
Self::Real(real) => real,
|
||||
Self::Test(test) => test,
|
||||
Self::Mock(mock) => mock,
|
||||
Self::Fake(mock) => mock,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,14 +11,14 @@ use std::{
|
|||
};
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct MockOpenRepository {
|
||||
pub struct FakeOpenRepository {
|
||||
log: Arc<Mutex<Vec<String>>>,
|
||||
default_push_remote: Arc<Mutex<Option<git::GitRemote>>>,
|
||||
default_fetch_remote: Arc<Mutex<Option<git::GitRemote>>>,
|
||||
commit_logs: HashMap<config::BranchName, Vec<git::Commit>>,
|
||||
repo_details: RepoDetails,
|
||||
}
|
||||
impl MockOpenRepository {
|
||||
impl FakeOpenRepository {
|
||||
pub fn new(repo_details: RepoDetails) -> Self {
|
||||
Self {
|
||||
repo_details,
|
||||
|
@ -81,13 +81,13 @@ impl MockOpenRepository {
|
|||
.unwrap_or_default()
|
||||
}
|
||||
}
|
||||
impl From<MockOpenRepository> for git::OpenRepository {
|
||||
fn from(value: MockOpenRepository) -> Self {
|
||||
Self::Mock(value)
|
||||
impl From<FakeOpenRepository> for git::OpenRepository {
|
||||
fn from(value: FakeOpenRepository) -> Self {
|
||||
Self::Fake(value)
|
||||
}
|
||||
}
|
||||
#[allow(clippy::unwrap_used)]
|
||||
impl git::repository::OpenRepositoryLike for MockOpenRepository {
|
||||
impl git::repository::OpenRepositoryLike for FakeOpenRepository {
|
||||
fn remote_branches(&self) -> git::push::Result<Vec<config::BranchName>> {
|
||||
todo!("MockOpenRepository::remote_branched")
|
||||
}
|
||||
|
|
|
@ -215,9 +215,10 @@ pub mod given {
|
|||
//
|
||||
use crate::{
|
||||
self as git,
|
||||
repository::{MockOpenRepository, MockRepository},
|
||||
repository::{FakeOpenRepository, FakeRepository},
|
||||
tests::given,
|
||||
};
|
||||
|
||||
use config::{
|
||||
BranchName, ForgeAlias, ForgeConfig, ForgeType, GitDir, RepoAlias, RepoBranches,
|
||||
RepoConfig, ServerRepoConfig,
|
||||
|
@ -348,7 +349,7 @@ pub mod given {
|
|||
|
||||
pub fn an_open_repository(
|
||||
fs: &kxio::fs::FileSystem,
|
||||
) -> (MockOpenRepository, RepoDetails, MockRepository) {
|
||||
) -> (FakeOpenRepository, RepoDetails, FakeRepository) {
|
||||
let mut mock = git::repository::mock();
|
||||
let repo_details = given::repo_details(fs);
|
||||
let or = mock.given_can_be_opened(repo_details.clone());
|
||||
|
|
Loading…
Reference in a new issue