tests: restore unlinked test file
This commit is contained in:
parent
fa5fa809d9
commit
2ec5ae1d51
6 changed files with 67 additions and 31 deletions
|
@ -14,3 +14,12 @@ impl TryFrom<gix::Url> for RemoteUrl {
|
||||||
Ok(Self(parsed))
|
Ok(Self(parsed))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl RemoteUrl {
|
||||||
|
pub fn matches(&self, other: &Self) -> bool {
|
||||||
|
tracing::debug!(host = ?self.host, fullname = ?self.fullname, token = ?self.token, "a");
|
||||||
|
tracing::debug!(host = ?other.host, fullname = ?other.fullname, token = ?other.token,"b");
|
||||||
|
self.host.eq(&other.host)
|
||||||
|
&& self.fullname.eq(&other.fullname)
|
||||||
|
&& self.token.eq(&other.token)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -81,9 +81,13 @@ impl RepoDetails {
|
||||||
let user = self.forge.user();
|
let user = self.forge.user();
|
||||||
use secrecy::ExposeSecret;
|
use secrecy::ExposeSecret;
|
||||||
let token = self.forge.token().expose_secret();
|
let token = self.forge.token().expose_secret();
|
||||||
|
let auth_delim = match token.is_empty() {
|
||||||
|
true => "",
|
||||||
|
false => ":",
|
||||||
|
};
|
||||||
let hostname = self.forge.hostname();
|
let hostname = self.forge.hostname();
|
||||||
let repo_path = &self.repo_path;
|
let repo_path = &self.repo_path;
|
||||||
format!("https://{user}:{token}@{hostname}/{repo_path}.git").into()
|
format!("https://{user}{auth_delim}{token}@{hostname}/{repo_path}.git").into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::result_large_err)]
|
#[allow(clippy::result_large_err)]
|
||||||
|
@ -118,7 +122,7 @@ impl RepoDetails {
|
||||||
tracing::debug!("No remote url to assert against");
|
tracing::debug!("No remote url to assert against");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
if found != expected {
|
if !found.matches(&expected) {
|
||||||
tracing::debug!(?found, ?expected, "urls differ");
|
tracing::debug!(?found, ?expected, "urls differ");
|
||||||
match self.gitdir.storage_path_type() {
|
match self.gitdir.storage_path_type() {
|
||||||
StoragePathType::External => {
|
StoragePathType::External => {
|
||||||
|
|
|
@ -23,13 +23,13 @@ pub fn validate_default_remotes(
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
info!(config = %remote_url, push = %push_remote, fetch = %fetch_remote, "Check remotes match");
|
info!(config = %remote_url, push = %push_remote, fetch = %fetch_remote, "Check remotes match");
|
||||||
if remote_url != push_remote {
|
if !remote_url.matches(&push_remote) {
|
||||||
return Err(Error::MismatchDefaultPushRemote {
|
return Err(Error::MismatchDefaultPushRemote {
|
||||||
found: push_remote,
|
found: push_remote,
|
||||||
expected: remote_url,
|
expected: remote_url,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if remote_url != fetch_remote {
|
if !remote_url.matches(&fetch_remote) {
|
||||||
return Err(Error::MismatchDefaultFetchRemote {
|
return Err(Error::MismatchDefaultFetchRemote {
|
||||||
found: fetch_remote,
|
found: fetch_remote,
|
||||||
expected: remote_url,
|
expected: remote_url,
|
||||||
|
|
|
@ -27,6 +27,8 @@ actix-rt = { workspace = true }
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
# Testing
|
# Testing
|
||||||
assert2 = { workspace = true }
|
assert2 = { workspace = true }
|
||||||
|
secrecy = { workspace = true }
|
||||||
|
test-log = { workspace = true }
|
||||||
|
|
||||||
[lints.clippy]
|
[lints.clippy]
|
||||||
nursery = { level = "warn", priority = -1 }
|
nursery = { level = "warn", priority = -1 }
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
//
|
//
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
|
|
||||||
use git_next_core::git::RepositoryFactory;
|
use git_next_core::git::RepositoryFactory;
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
//
|
//
|
||||||
use assert2::let_assert;
|
use assert2::let_assert;
|
||||||
use git::{repository::Direction, validation::remotes::validate_default_remotes};
|
use git_next_core::{
|
||||||
use git_next_config::{
|
self as core,
|
||||||
self as config, ForgeType, GitDir, Hostname, RepoBranches, RepoConfig, RepoConfigSource,
|
git::{self, repository::Direction, validation::remotes::validate_default_remotes},
|
||||||
RepoPath,
|
ApiToken, ForgeType, GitDir, Hostname, RepoBranches, RepoConfig, RepoConfigSource, RepoPath,
|
||||||
|
StoragePathType, User,
|
||||||
};
|
};
|
||||||
use git_next_git as git;
|
use secrecy::Secret;
|
||||||
|
|
||||||
type Result<T> = core::result::Result<T, Box<dyn std::error::Error>>;
|
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_repo_config_load() -> Result<()> {
|
fn test_repo_config_load() -> Result<()> {
|
||||||
|
@ -34,7 +35,7 @@ fn test_repo_config_load() -> Result<()> {
|
||||||
#[test]
|
#[test]
|
||||||
fn gitdir_should_display_as_pathbuf() {
|
fn gitdir_should_display_as_pathbuf() {
|
||||||
//given
|
//given
|
||||||
let gitdir = GitDir::from("foo/dir");
|
let gitdir = GitDir::new("foo/dir".into(), StoragePathType::External);
|
||||||
//when
|
//when
|
||||||
let result = format!("{}", gitdir);
|
let result = format!("{}", gitdir);
|
||||||
//then
|
//then
|
||||||
|
@ -48,50 +49,59 @@ fn gitdir_should_display_as_pathbuf() {
|
||||||
fn repo_details_find_default_push_remote_finds_correct_remote() -> Result<()> {
|
fn repo_details_find_default_push_remote_finds_correct_remote() -> Result<()> {
|
||||||
let cli_crate_dir = std::env::current_dir().map_err(git::validation::remotes::Error::Io)?;
|
let cli_crate_dir = std::env::current_dir().map_err(git::validation::remotes::Error::Io)?;
|
||||||
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()));
|
||||||
let mut repo_details = git::common::repo_details(
|
let mut repo_details = git::repo_details(
|
||||||
1,
|
1,
|
||||||
git::Generation::default(),
|
git::Generation::default(),
|
||||||
config::common::forge_details(1, ForgeType::MockForge),
|
core::common::forge_details(1, ForgeType::MockForge),
|
||||||
None,
|
None,
|
||||||
GitDir::new(root), // Server GitDir - should be ignored
|
GitDir::new(root.to_path_buf(), StoragePathType::External), // Server GitDir - should be ignored
|
||||||
);
|
);
|
||||||
repo_details.forge = repo_details
|
repo_details.forge = repo_details
|
||||||
.forge
|
.forge
|
||||||
|
.with_user(User::new("git".to_string()))
|
||||||
|
.with_token(ApiToken::new(Secret::new("".to_string())))
|
||||||
.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 gitdir = &repo_details.gitdir;
|
let open_repository = git::repository::factory::real().open(&repo_details)?;
|
||||||
let open_repository = git::repository::real().open(gitdir)?;
|
|
||||||
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"
|
||||||
);
|
);
|
||||||
let config_git_remote = repo_details.git_remote();
|
let_assert!(Some(config_git_remote) = repo_details.remote_url());
|
||||||
|
|
||||||
assert_eq!(
|
assert!(
|
||||||
found_git_remote, config_git_remote,
|
found_git_remote.matches(&config_git_remote),
|
||||||
"Default Push Remote must match config"
|
"Default Push Remote must match config"
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test_log::test]
|
||||||
fn gitdir_validate_should_pass_a_valid_git_repo() -> Result<()> {
|
fn gitdir_validate_should_pass_a_valid_git_repo() -> Result<()> {
|
||||||
let cli_crate_dir = std::env::current_dir().map_err(git::validation::remotes::Error::Io)?;
|
let cli_crate_dir = std::env::current_dir().map_err(git::validation::remotes::Error::Io)?;
|
||||||
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()));
|
||||||
let mut repo_details = git::common::repo_details(
|
let mut repo_details = git::repo_details(
|
||||||
1,
|
1,
|
||||||
git::Generation::default(),
|
git::Generation::default(),
|
||||||
config::common::forge_details(1, ForgeType::MockForge),
|
core::common::forge_details(1, ForgeType::MockForge),
|
||||||
None,
|
None,
|
||||||
GitDir::new(root), // Server GitDir - should be ignored
|
GitDir::new(root.to_path_buf(), StoragePathType::External), // Server GitDir - should be ignored
|
||||||
)
|
)
|
||||||
.with_repo_path(RepoPath::new("kemitix/git-next".to_string()));
|
.with_repo_path(RepoPath::new("kemitix/git-next".to_string()));
|
||||||
repo_details.forge = repo_details
|
repo_details.forge = repo_details
|
||||||
.forge
|
.forge
|
||||||
|
.with_user(User::new("git".to_string()))
|
||||||
|
.with_token(ApiToken::new(Secret::new("".to_string())))
|
||||||
.with_hostname(Hostname::new("git.kemitix.net"));
|
.with_hostname(Hostname::new("git.kemitix.net"));
|
||||||
let gitdir = &repo_details.gitdir;
|
tracing::debug!("opening...");
|
||||||
let repository = git::repository::real().open(gitdir)?;
|
let_assert!(
|
||||||
|
Ok(repository) = git::repository::factory::real().open(&repo_details),
|
||||||
|
"open repository"
|
||||||
|
);
|
||||||
|
tracing::debug!("open okay");
|
||||||
|
tracing::info!(?repository, "FOO");
|
||||||
|
tracing::info!(?repo_details, "BAR");
|
||||||
validate_default_remotes(&*repository, &repo_details)?;
|
validate_default_remotes(&*repository, &repo_details)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -103,16 +113,24 @@ fn gitdir_validate_should_fail_a_git_repo_with_wrong_remote() -> Result<()> {
|
||||||
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)
|
||||||
);
|
);
|
||||||
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()));
|
||||||
let repo_details = git::common::repo_details(
|
let mut repo_details = git::repo_details(
|
||||||
1,
|
1,
|
||||||
git::Generation::default(),
|
git::Generation::default(),
|
||||||
config::common::forge_details(1, ForgeType::MockForge),
|
core::common::forge_details(1, ForgeType::MockForge),
|
||||||
None,
|
None,
|
||||||
GitDir::new(root), // Server GitDir - should be ignored
|
GitDir::new(root.to_path_buf(), StoragePathType::External), // Server GitDir - should be ignored
|
||||||
)
|
)
|
||||||
.with_repo_path(RepoPath::new("hello/world".to_string()));
|
.with_repo_path(RepoPath::new("kemitix/git-next".to_string()));
|
||||||
let gitdir = &repo_details.gitdir;
|
repo_details.forge = repo_details
|
||||||
let repository = git::repository::real().open(gitdir)?;
|
.forge
|
||||||
|
.with_user(User::new("git".to_string()))
|
||||||
|
.with_token(ApiToken::new(Secret::new("".to_string())))
|
||||||
|
.with_hostname(Hostname::new("git.kemitix.net"));
|
||||||
|
let repository = git::repository::factory::real().open(&repo_details)?;
|
||||||
|
let mut repo_details = repo_details.clone();
|
||||||
|
repo_details.forge = repo_details
|
||||||
|
.forge
|
||||||
|
.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(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue