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"
|
assert2 = "0.3"
|
||||||
pretty_assertions = "1.4"
|
pretty_assertions = "1.4"
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
mockall = "0.12"
|
|
||||||
|
|
|
@ -56,7 +56,6 @@ 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,5 +22,4 @@ 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 FakeRepository {
|
pub struct MockRepository {
|
||||||
open_repos: Arc<Mutex<HashMap<config::GitDir, git::repository::FakeOpenRepository>>>,
|
open_repos: Arc<Mutex<HashMap<config::GitDir, git::repository::MockOpenRepository>>>,
|
||||||
clone_repos: Arc<Mutex<HashMap<config::GitDir, git::repository::FakeOpenRepository>>>,
|
clone_repos: Arc<Mutex<HashMap<config::GitDir, git::repository::MockOpenRepository>>>,
|
||||||
}
|
}
|
||||||
impl FakeRepository {
|
impl MockRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
open_repos: Default::default(),
|
open_repos: Default::default(),
|
||||||
|
@ -25,9 +25,9 @@ impl FakeRepository {
|
||||||
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::FakeOpenRepository {
|
) -> git::repository::MockOpenRepository {
|
||||||
let gitdir = repo_details.gitdir.clone();
|
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)]
|
#[allow(clippy::unwrap_used)]
|
||||||
self.open_repos
|
self.open_repos
|
||||||
.lock()
|
.lock()
|
||||||
|
@ -39,9 +39,9 @@ impl FakeRepository {
|
||||||
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::FakeOpenRepository {
|
) -> git::repository::MockOpenRepository {
|
||||||
let gitdir = repo_details.gitdir.clone();
|
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)]
|
#[allow(clippy::unwrap_used)]
|
||||||
self.clone_repos
|
self.clone_repos
|
||||||
.lock()
|
.lock()
|
||||||
|
@ -57,14 +57,14 @@ impl FakeRepository {
|
||||||
// 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::FakeOpenRepository> {
|
pub fn get(&self, gitdir: &config::GitDir) -> Option<git::repository::MockOpenRepository> {
|
||||||
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 FakeRepository {
|
impl git::repository::RepositoryLike for MockRepository {
|
||||||
fn open(
|
fn open(
|
||||||
&self,
|
&self,
|
||||||
gitdir: &config::GitDir,
|
gitdir: &config::GitDir,
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
//
|
//
|
||||||
mod mock;
|
mod mock;
|
||||||
pub use mock::FakeRepository;
|
pub use mock::MockRepository;
|
||||||
pub use open::FakeOpenRepository;
|
pub use open::MockOpenRepository;
|
||||||
|
|
||||||
pub mod open;
|
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(FakeRepository),
|
Mock(MockRepository),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn new() -> Repository {
|
pub const fn new() -> Repository {
|
||||||
Repository::Real
|
Repository::Real
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mock() -> FakeRepository {
|
pub fn mock() -> MockRepository {
|
||||||
FakeRepository::new()
|
MockRepository::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::FakeOpenRepository;
|
pub use omock::MockOpenRepository;
|
||||||
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.
|
||||||
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 {
|
pub fn real(gix_repo: gix::Repository) -> OpenRepository {
|
||||||
|
@ -78,7 +78,6 @@ 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>;
|
||||||
|
@ -114,7 +113,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::Fake(mock) => mock,
|
Self::Mock(mock) => mock,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,14 +11,14 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct FakeOpenRepository {
|
pub struct MockOpenRepository {
|
||||||
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 FakeOpenRepository {
|
impl MockOpenRepository {
|
||||||
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 FakeOpenRepository {
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<FakeOpenRepository> for git::OpenRepository {
|
impl From<MockOpenRepository> for git::OpenRepository {
|
||||||
fn from(value: FakeOpenRepository) -> Self {
|
fn from(value: MockOpenRepository) -> Self {
|
||||||
Self::Fake(value)
|
Self::Mock(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[allow(clippy::unwrap_used)]
|
#[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>> {
|
fn remote_branches(&self) -> git::push::Result<Vec<config::BranchName>> {
|
||||||
todo!("MockOpenRepository::remote_branched")
|
todo!("MockOpenRepository::remote_branched")
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,10 +215,9 @@ pub mod given {
|
||||||
//
|
//
|
||||||
use crate::{
|
use crate::{
|
||||||
self as git,
|
self as git,
|
||||||
repository::{FakeOpenRepository, FakeRepository},
|
repository::{MockOpenRepository, MockRepository},
|
||||||
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,
|
||||||
|
@ -349,7 +348,7 @@ pub mod given {
|
||||||
|
|
||||||
pub fn an_open_repository(
|
pub fn an_open_repository(
|
||||||
fs: &kxio::fs::FileSystem,
|
fs: &kxio::fs::FileSystem,
|
||||||
) -> (FakeOpenRepository, RepoDetails, FakeRepository) {
|
) -> (MockOpenRepository, RepoDetails, MockRepository) {
|
||||||
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