diff --git a/crates/git/src/repository/tests.rs b/crates/git/src/repository/tests.rs deleted file mode 100644 index 5ac458fd..00000000 --- a/crates/git/src/repository/tests.rs +++ /dev/null @@ -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()); - } -} diff --git a/crates/git/src/repository/tests/mod.rs b/crates/git/src/repository/tests/mod.rs new file mode 100644 index 00000000..100149f5 --- /dev/null +++ b/crates/git/src/repository/tests/mod.rs @@ -0,0 +1,3 @@ +use crate as git; + +mod validate; diff --git a/crates/git/src/repository/tests/validate.rs b/crates/git/src/repository/tests/validate.rs new file mode 100644 index 00000000..15cb7051 --- /dev/null +++ b/crates/git/src/repository/tests/validate.rs @@ -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()); +}