refactor: split git::repository::tests module
All checks were successful
Rust / build (push) Successful in 1m19s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful

This commit is contained in:
Paul Campbell 2024-07-05 20:12:11 +01:00
parent 56756cab70
commit 5ab075c181
3 changed files with 97 additions and 100 deletions

View file

@ -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());
}
}

View file

@ -0,0 +1,3 @@
use crate as git;
mod validate;

View 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());
}