forked from kemitix/git-next
refactor: split git::repository::tests module
This commit is contained in:
parent
56756cab70
commit
5ab075c181
3 changed files with 97 additions and 100 deletions
|
@ -1,100 +0,0 @@
|
||||||
use crate as git;
|
|
||||||
|
|
||||||
mod validate {
|
|
||||||
use crate::{tests::given, validation::remotes::validate_default_remotes};
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
use git::repository::Direction;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn should_ok_a_valid_repo() {
|
|
||||||
let fs = given::a_filesystem();
|
|
||||||
let repo_details = given::repo_details(&fs);
|
|
||||||
let repo_details_mock = repo_details.clone();
|
|
||||||
|
|
||||||
let mut open_repository = git::repository::open::mock();
|
|
||||||
open_repository
|
|
||||||
.expect_find_default_remote()
|
|
||||||
.returning(move |_direction| Some(repo_details_mock.git_remote()));
|
|
||||||
|
|
||||||
let result = validate_default_remotes(&*open_repository, &repo_details);
|
|
||||||
println!("{result:?}");
|
|
||||||
assert!(result.is_ok());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn should_fail_where_no_default_push_remote() {
|
|
||||||
let fs = given::a_filesystem();
|
|
||||||
let repo_details = given::repo_details(&fs);
|
|
||||||
let repo_details_mock = repo_details.clone();
|
|
||||||
|
|
||||||
let mut open_repository = git::repository::open::mock();
|
|
||||||
open_repository
|
|
||||||
.expect_find_default_remote()
|
|
||||||
.returning(move |direction| match direction {
|
|
||||||
Direction::Push => None,
|
|
||||||
Direction::Fetch => Some(repo_details_mock.git_remote()),
|
|
||||||
});
|
|
||||||
|
|
||||||
let result = validate_default_remotes(&*open_repository, &repo_details);
|
|
||||||
println!("{result:?}");
|
|
||||||
assert!(result.is_err());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn should_fail_where_no_default_fetch_remote() {
|
|
||||||
let fs = given::a_filesystem();
|
|
||||||
let repo_details = given::repo_details(&fs);
|
|
||||||
let repo_details_mock = repo_details.clone();
|
|
||||||
|
|
||||||
let mut open_repository = git::repository::open::mock();
|
|
||||||
open_repository
|
|
||||||
.expect_find_default_remote()
|
|
||||||
.returning(move |direction| match direction {
|
|
||||||
Direction::Push => Some(repo_details_mock.git_remote()),
|
|
||||||
Direction::Fetch => None,
|
|
||||||
});
|
|
||||||
|
|
||||||
let result = validate_default_remotes(&*open_repository, &repo_details);
|
|
||||||
println!("{result:?}");
|
|
||||||
assert!(result.is_err());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn should_fail_where_invalid_default_push_remote() {
|
|
||||||
let fs = given::a_filesystem();
|
|
||||||
let repo_details = given::repo_details(&fs);
|
|
||||||
let repo_details_mock = repo_details.clone();
|
|
||||||
|
|
||||||
let mut open_repository = git::repository::open::mock();
|
|
||||||
open_repository
|
|
||||||
.expect_find_default_remote()
|
|
||||||
.returning(move |direction| match direction {
|
|
||||||
Direction::Push => Some(given::a_git_remote()),
|
|
||||||
Direction::Fetch => Some(repo_details_mock.git_remote()),
|
|
||||||
});
|
|
||||||
|
|
||||||
let result = validate_default_remotes(&*open_repository, &repo_details);
|
|
||||||
println!("{result:?}");
|
|
||||||
assert!(result.is_err());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn should_fail_where_invalid_default_fetch_remote() {
|
|
||||||
let fs = given::a_filesystem();
|
|
||||||
let repo_details = given::repo_details(&fs);
|
|
||||||
let repo_details_mock = repo_details.clone();
|
|
||||||
|
|
||||||
let mut open_repository = git::repository::open::mock();
|
|
||||||
open_repository
|
|
||||||
.expect_find_default_remote()
|
|
||||||
.returning(move |direction| match direction {
|
|
||||||
Direction::Push => Some(repo_details_mock.git_remote()),
|
|
||||||
Direction::Fetch => Some(given::a_git_remote()),
|
|
||||||
});
|
|
||||||
|
|
||||||
let result = validate_default_remotes(&*open_repository, &repo_details);
|
|
||||||
println!("{result:?}");
|
|
||||||
assert!(result.is_err());
|
|
||||||
}
|
|
||||||
}
|
|
3
crates/git/src/repository/tests/mod.rs
Normal file
3
crates/git/src/repository/tests/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
use crate as git;
|
||||||
|
|
||||||
|
mod validate;
|
94
crates/git/src/repository/tests/validate.rs
Normal file
94
crates/git/src/repository/tests/validate.rs
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
use super::*;
|
||||||
|
use git::{repository::Direction, tests::given, validation::remotes::validate_default_remotes};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_ok_a_valid_repo() {
|
||||||
|
let fs = given::a_filesystem();
|
||||||
|
let repo_details = given::repo_details(&fs);
|
||||||
|
let repo_details_mock = repo_details.clone();
|
||||||
|
|
||||||
|
let mut open_repository = git::repository::open::mock();
|
||||||
|
open_repository
|
||||||
|
.expect_find_default_remote()
|
||||||
|
.returning(move |_direction| Some(repo_details_mock.git_remote()));
|
||||||
|
|
||||||
|
let result = validate_default_remotes(&*open_repository, &repo_details);
|
||||||
|
println!("{result:?}");
|
||||||
|
assert!(result.is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_fail_where_no_default_push_remote() {
|
||||||
|
let fs = given::a_filesystem();
|
||||||
|
let repo_details = given::repo_details(&fs);
|
||||||
|
let repo_details_mock = repo_details.clone();
|
||||||
|
|
||||||
|
let mut open_repository = git::repository::open::mock();
|
||||||
|
open_repository
|
||||||
|
.expect_find_default_remote()
|
||||||
|
.returning(move |direction| match direction {
|
||||||
|
Direction::Push => None,
|
||||||
|
Direction::Fetch => Some(repo_details_mock.git_remote()),
|
||||||
|
});
|
||||||
|
|
||||||
|
let result = validate_default_remotes(&*open_repository, &repo_details);
|
||||||
|
println!("{result:?}");
|
||||||
|
assert!(result.is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_fail_where_no_default_fetch_remote() {
|
||||||
|
let fs = given::a_filesystem();
|
||||||
|
let repo_details = given::repo_details(&fs);
|
||||||
|
let repo_details_mock = repo_details.clone();
|
||||||
|
|
||||||
|
let mut open_repository = git::repository::open::mock();
|
||||||
|
open_repository
|
||||||
|
.expect_find_default_remote()
|
||||||
|
.returning(move |direction| match direction {
|
||||||
|
Direction::Push => Some(repo_details_mock.git_remote()),
|
||||||
|
Direction::Fetch => None,
|
||||||
|
});
|
||||||
|
|
||||||
|
let result = validate_default_remotes(&*open_repository, &repo_details);
|
||||||
|
println!("{result:?}");
|
||||||
|
assert!(result.is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_fail_where_invalid_default_push_remote() {
|
||||||
|
let fs = given::a_filesystem();
|
||||||
|
let repo_details = given::repo_details(&fs);
|
||||||
|
let repo_details_mock = repo_details.clone();
|
||||||
|
|
||||||
|
let mut open_repository = git::repository::open::mock();
|
||||||
|
open_repository
|
||||||
|
.expect_find_default_remote()
|
||||||
|
.returning(move |direction| match direction {
|
||||||
|
Direction::Push => Some(given::a_git_remote()),
|
||||||
|
Direction::Fetch => Some(repo_details_mock.git_remote()),
|
||||||
|
});
|
||||||
|
|
||||||
|
let result = validate_default_remotes(&*open_repository, &repo_details);
|
||||||
|
println!("{result:?}");
|
||||||
|
assert!(result.is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_fail_where_invalid_default_fetch_remote() {
|
||||||
|
let fs = given::a_filesystem();
|
||||||
|
let repo_details = given::repo_details(&fs);
|
||||||
|
let repo_details_mock = repo_details.clone();
|
||||||
|
|
||||||
|
let mut open_repository = git::repository::open::mock();
|
||||||
|
open_repository
|
||||||
|
.expect_find_default_remote()
|
||||||
|
.returning(move |direction| match direction {
|
||||||
|
Direction::Push => Some(repo_details_mock.git_remote()),
|
||||||
|
Direction::Fetch => Some(given::a_git_remote()),
|
||||||
|
});
|
||||||
|
|
||||||
|
let result = validate_default_remotes(&*open_repository, &repo_details);
|
||||||
|
println!("{result:?}");
|
||||||
|
assert!(result.is_err());
|
||||||
|
}
|
Loading…
Reference in a new issue