fix(test): tests requiring .git pass when not present
All checks were successful
Rust / build (push) Successful in 6m12s
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
Release Please / Release-plz (push) Successful in 1m32s

These are tests that assume they are running in a locally checked out
git repository. If that isn't the case, e.g. when using jujutsu, then
the tests should not fail. They will continue to run as normal under
CI conditions as those do use a locally checked out git repository.
This commit is contained in:
Paul Campbell 2024-09-12 10:37:46 +01:00
parent 80af909ab0
commit 566125f5c0

View file

@ -62,7 +62,10 @@ fn repo_details_find_default_push_remote_finds_correct_remote() -> Result<()> {
.with_token(ApiToken::new(Secret::new(String::new()))) .with_token(ApiToken::new(Secret::new(String::new())))
.with_hostname(Hostname::new("git.kemitix.net")); .with_hostname(Hostname::new("git.kemitix.net"));
repo_details.repo_path = RepoPath::new("kemitix/git-next".to_string()); repo_details.repo_path = RepoPath::new("kemitix/git-next".to_string());
let open_repository = git::repository::factory::real().open(&repo_details)?; let Ok(open_repository) = git::repository::factory::real().open(&repo_details) else {
// .git directory may not be present on dev environment
return Ok(());
};
let_assert!( let_assert!(
Some(found_git_remote) = open_repository.find_default_remote(Direction::Push), Some(found_git_remote) = open_repository.find_default_remote(Direction::Push),
"Default Push Remote not found" "Default Push Remote not found"
@ -95,10 +98,10 @@ fn gitdir_validate_should_pass_a_valid_git_repo() -> Result<()> {
.with_token(ApiToken::new(Secret::new(String::new()))) .with_token(ApiToken::new(Secret::new(String::new())))
.with_hostname(Hostname::new("git.kemitix.net")); .with_hostname(Hostname::new("git.kemitix.net"));
tracing::debug!("opening..."); tracing::debug!("opening...");
let_assert!( let Ok(repository) = git::repository::factory::real().open(&repo_details) else {
Ok(repository) = git::repository::factory::real().open(&repo_details), // .git directory may not be present on dev environment
"open repository" return Ok(());
); };
tracing::debug!("open okay"); tracing::debug!("open okay");
tracing::info!(?repository, "FOO"); tracing::info!(?repository, "FOO");
tracing::info!(?repo_details, "BAR"); tracing::info!(?repo_details, "BAR");
@ -108,11 +111,13 @@ fn gitdir_validate_should_pass_a_valid_git_repo() -> Result<()> {
} }
#[test] #[test]
fn gitdir_validate_should_fail_a_git_repo_with_wrong_remote() -> Result<()> { fn gitdir_validate_should_fail_a_git_repo_with_wrong_remote() {
let_assert!( let_assert!(
Ok(cli_crate_dir) = std::env::current_dir().map_err(git::validation::remotes::Error::Io) Ok(cli_crate_dir) = std::env::current_dir().map_err(git::validation::remotes::Error::Io)
); );
eprintln!("cli_crate_dir: {cli_crate_dir:?}");
let_assert!(Some(Some(root)) = cli_crate_dir.parent().map(|p| p.parent())); let_assert!(Some(Some(root)) = cli_crate_dir.parent().map(|p| p.parent()));
eprintln!("root: {root:?}");
let mut repo_details = git::repo_details( let mut repo_details = git::repo_details(
1, 1,
git::Generation::default(), git::Generation::default(),
@ -126,14 +131,15 @@ fn gitdir_validate_should_fail_a_git_repo_with_wrong_remote() -> Result<()> {
.with_user(User::new("git".to_string())) .with_user(User::new("git".to_string()))
.with_token(ApiToken::new(Secret::new(String::new()))) .with_token(ApiToken::new(Secret::new(String::new())))
.with_hostname(Hostname::new("git.kemitix.net")); .with_hostname(Hostname::new("git.kemitix.net"));
let repository = git::repository::factory::real().open(&repo_details)?; let Ok(repository) = git::repository::factory::real().open(&repo_details) else {
// .git directory may not be present on dev environment
return;
};
let mut repo_details = repo_details.clone(); let mut repo_details = repo_details.clone();
repo_details.forge = repo_details repo_details.forge = repo_details
.forge .forge
.with_hostname(Hostname::new("code.kemitix.net")); .with_hostname(Hostname::new("code.kemitix.net"));
let_assert!(Err(_) = validate_default_remotes(&*repository, &repo_details)); let_assert!(Err(_) = validate_default_remotes(&*repository, &repo_details));
Ok(())
} }
#[test] #[test]