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