Compare commits
5 commits
9b1c1d6d87
...
2797538420
Author | SHA1 | Date | |
---|---|---|---|
2797538420 | |||
3e3aaad28c | |||
a2dc3a821a | |||
6afc4f2f68 | |||
eb541f2782 |
8 changed files with 27 additions and 32 deletions
|
@ -96,4 +96,3 @@ tokio = { version = "1.37", features = ["rt", "macros"] }
|
|||
assert2 = "0.3"
|
||||
pretty_assertions = "1.4"
|
||||
rand = "0.8"
|
||||
mockall = "0.12"
|
||||
|
|
|
@ -56,7 +56,6 @@ actix = { workspace = true }
|
|||
assert2 = { workspace = true }
|
||||
rand = { workspace = true }
|
||||
pretty_assertions = { workspace = true }
|
||||
mockall = { workspace = true }
|
||||
|
||||
[lints.clippy]
|
||||
nursery = { level = "warn", priority = -1 }
|
||||
|
|
|
@ -22,5 +22,4 @@ 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 FakeRepository {
|
||||
open_repos: Arc<Mutex<HashMap<config::GitDir, git::repository::FakeOpenRepository>>>,
|
||||
clone_repos: Arc<Mutex<HashMap<config::GitDir, git::repository::FakeOpenRepository>>>,
|
||||
pub struct MockRepository {
|
||||
open_repos: Arc<Mutex<HashMap<config::GitDir, git::repository::MockOpenRepository>>>,
|
||||
clone_repos: Arc<Mutex<HashMap<config::GitDir, git::repository::MockOpenRepository>>>,
|
||||
}
|
||||
impl FakeRepository {
|
||||
impl MockRepository {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
open_repos: Default::default(),
|
||||
|
@ -25,9 +25,9 @@ impl FakeRepository {
|
|||
pub fn given_can_be_opened(
|
||||
&mut self,
|
||||
repo_details: git::RepoDetails,
|
||||
) -> git::repository::FakeOpenRepository {
|
||||
) -> git::repository::MockOpenRepository {
|
||||
let gitdir = repo_details.gitdir.clone();
|
||||
let open_repo = git::repository::FakeOpenRepository::new(repo_details);
|
||||
let open_repo = git::repository::MockOpenRepository::new(repo_details);
|
||||
#[allow(clippy::unwrap_used)]
|
||||
self.open_repos
|
||||
.lock()
|
||||
|
@ -39,9 +39,9 @@ impl FakeRepository {
|
|||
pub fn given_can_be_cloned(
|
||||
&mut self,
|
||||
repo_details: git::RepoDetails,
|
||||
) -> git::repository::FakeOpenRepository {
|
||||
) -> git::repository::MockOpenRepository {
|
||||
let gitdir = repo_details.gitdir.clone();
|
||||
let clone_repo = git::repository::FakeOpenRepository::new(repo_details);
|
||||
let clone_repo = git::repository::MockOpenRepository::new(repo_details);
|
||||
#[allow(clippy::unwrap_used)]
|
||||
self.clone_repos
|
||||
.lock()
|
||||
|
@ -57,14 +57,14 @@ impl FakeRepository {
|
|||
// drop repository to allow same mutable access to mock repository
|
||||
self
|
||||
}
|
||||
pub fn get(&self, gitdir: &config::GitDir) -> Option<git::repository::FakeOpenRepository> {
|
||||
pub fn get(&self, gitdir: &config::GitDir) -> Option<git::repository::MockOpenRepository> {
|
||||
self.open_repos
|
||||
.lock()
|
||||
.map(|or| or.get(gitdir).cloned())
|
||||
.unwrap_or(None)
|
||||
}
|
||||
}
|
||||
impl git::repository::RepositoryLike for FakeRepository {
|
||||
impl git::repository::RepositoryLike for MockRepository {
|
||||
fn open(
|
||||
&self,
|
||||
gitdir: &config::GitDir,
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
//
|
||||
mod mock;
|
||||
pub use mock::FakeRepository;
|
||||
pub use open::FakeOpenRepository;
|
||||
pub use mock::MockRepository;
|
||||
pub use open::MockOpenRepository;
|
||||
|
||||
pub mod open;
|
||||
mod open;
|
||||
mod real;
|
||||
pub mod test;
|
||||
|
||||
|
@ -33,15 +33,15 @@ use super::RepoDetails;
|
|||
pub enum Repository {
|
||||
Real,
|
||||
Test(TestRepository),
|
||||
Mock(FakeRepository),
|
||||
Mock(MockRepository),
|
||||
}
|
||||
|
||||
pub const fn new() -> Repository {
|
||||
Repository::Real
|
||||
}
|
||||
|
||||
pub fn mock() -> FakeRepository {
|
||||
FakeRepository::new()
|
||||
pub fn mock() -> MockRepository {
|
||||
MockRepository::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::FakeOpenRepository;
|
||||
pub use omock::MockOpenRepository;
|
||||
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.
|
||||
Fake(git::repository::FakeOpenRepository), // TODO: (#38) contain a mock model of a repo
|
||||
Mock(git::repository::MockOpenRepository), // TODO: (#38) contain a mock model of a repo
|
||||
}
|
||||
|
||||
pub fn real(gix_repo: gix::Repository) -> OpenRepository {
|
||||
|
@ -78,7 +78,6 @@ 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>;
|
||||
|
@ -114,7 +113,7 @@ impl std::ops::Deref for OpenRepository {
|
|||
match self {
|
||||
Self::Real(real) => real,
|
||||
Self::Test(test) => test,
|
||||
Self::Fake(mock) => mock,
|
||||
Self::Mock(mock) => mock,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,14 +11,14 @@ use std::{
|
|||
};
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct FakeOpenRepository {
|
||||
pub struct MockOpenRepository {
|
||||
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 FakeOpenRepository {
|
||||
impl MockOpenRepository {
|
||||
pub fn new(repo_details: RepoDetails) -> Self {
|
||||
Self {
|
||||
repo_details,
|
||||
|
@ -81,13 +81,13 @@ impl FakeOpenRepository {
|
|||
.unwrap_or_default()
|
||||
}
|
||||
}
|
||||
impl From<FakeOpenRepository> for git::OpenRepository {
|
||||
fn from(value: FakeOpenRepository) -> Self {
|
||||
Self::Fake(value)
|
||||
impl From<MockOpenRepository> for git::OpenRepository {
|
||||
fn from(value: MockOpenRepository) -> Self {
|
||||
Self::Mock(value)
|
||||
}
|
||||
}
|
||||
#[allow(clippy::unwrap_used)]
|
||||
impl git::repository::OpenRepositoryLike for FakeOpenRepository {
|
||||
impl git::repository::OpenRepositoryLike for MockOpenRepository {
|
||||
fn remote_branches(&self) -> git::push::Result<Vec<config::BranchName>> {
|
||||
todo!("MockOpenRepository::remote_branched")
|
||||
}
|
||||
|
|
|
@ -215,10 +215,9 @@ pub mod given {
|
|||
//
|
||||
use crate::{
|
||||
self as git,
|
||||
repository::{FakeOpenRepository, FakeRepository},
|
||||
repository::{MockOpenRepository, MockRepository},
|
||||
tests::given,
|
||||
};
|
||||
|
||||
use config::{
|
||||
BranchName, ForgeAlias, ForgeConfig, ForgeType, GitDir, RepoAlias, RepoBranches,
|
||||
RepoConfig, ServerRepoConfig,
|
||||
|
@ -349,7 +348,7 @@ pub mod given {
|
|||
|
||||
pub fn an_open_repository(
|
||||
fs: &kxio::fs::FileSystem,
|
||||
) -> (FakeOpenRepository, RepoDetails, FakeRepository) {
|
||||
) -> (MockOpenRepository, RepoDetails, MockRepository) {
|
||||
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