Paul Campbell
ffab1986a7
Some checks failed
ci/woodpecker/cron/cron-docker-builder Pipeline was successful
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
Rust / build (push) Has been cancelled
ci/woodpecker/push/tag-created Pipeline was successful
208 lines
6.7 KiB
Rust
208 lines
6.7 KiB
Rust
//
|
|
|
|
use super::*;
|
|
|
|
#[actix::test]
|
|
async fn should_clone() -> TestResult {
|
|
//given
|
|
let fs = given::a_filesystem();
|
|
let (mut open_repository, /* mut */ repo_details) = given::an_open_repository(&fs);
|
|
// #[allow(clippy::unwrap_used)]
|
|
// let repo_config = repo_details.repo_config.take().unwrap();
|
|
|
|
given::has_all_valid_remote_defaults(&mut open_repository, &repo_details);
|
|
// handles_validate_repo_message(&mut open_repository, repo_config.branches());
|
|
|
|
// factory clones an open repository
|
|
let mut repository_factory = MockRepositoryFactory::new();
|
|
let cloned = Arc::new(Mutex::new(vec![]));
|
|
let cloned_ref = cloned.clone();
|
|
repository_factory
|
|
.expect_git_clone()
|
|
.times(2)
|
|
.return_once(move |_| {
|
|
let _ = cloned_ref.lock().map(|mut l| l.push(()));
|
|
Ok(Box::new(open_repository))
|
|
});
|
|
|
|
//when
|
|
let (addr, _log) = when::start_actor(repository_factory, repo_details, given::a_forge());
|
|
addr.send(CloneRepo::new()).await?;
|
|
System::current().stop();
|
|
|
|
//then
|
|
cloned
|
|
.lock()
|
|
.map_err(|e| e.to_string())
|
|
.map(|o| assert_eq!(o.len(), 1))?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[actix::test]
|
|
async fn should_open() -> TestResult {
|
|
//given
|
|
let fs = given::a_filesystem();
|
|
let (mut open_repository, /* mut */ repo_details) = given::an_open_repository(&fs);
|
|
// #[allow(clippy::unwrap_used)]
|
|
// let repo_config = repo_details.repo_config.take().unwrap();
|
|
|
|
given::has_all_valid_remote_defaults(&mut open_repository, &repo_details);
|
|
// handles_validate_repo_message(&mut open_repository, repo_config.branches());
|
|
|
|
// factory opens a repository
|
|
let mut repository_factory = MockRepositoryFactory::new();
|
|
let opened = Arc::new(Mutex::new(vec![]));
|
|
let opened_ref = opened.clone();
|
|
repository_factory
|
|
.expect_open()
|
|
.times(1)
|
|
.return_once(move |_| {
|
|
let _ = opened_ref.lock().map(|mut l| l.push(()));
|
|
Ok(Box::new(open_repository))
|
|
});
|
|
fs.dir_create(&repo_details.gitdir)?;
|
|
|
|
//when
|
|
let (addr, _log) = when::start_actor(repository_factory, repo_details, given::a_forge());
|
|
addr.send(CloneRepo::new()).await?;
|
|
System::current().stop();
|
|
|
|
//then
|
|
opened
|
|
.lock()
|
|
.map_err(|e| e.to_string())
|
|
.map(|o| assert_eq!(o.len(), 1))?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
/// The server config can optionally include the names of the main, next and dev
|
|
/// branches. When it doesn't we should load the .git-next.yaml from from the
|
|
/// repo and get the branch names from there.
|
|
#[actix::test]
|
|
async fn when_server_has_no_repo_config_load_from_repo_and_validate() -> TestResult {
|
|
//given
|
|
let fs = given::a_filesystem();
|
|
let (mut open_repository, mut repo_details) = given::an_open_repository(&fs);
|
|
#[allow(clippy::unwrap_used)]
|
|
let repo_config = repo_details.repo_config.take().unwrap();
|
|
|
|
given::has_all_valid_remote_defaults(&mut open_repository, &repo_details);
|
|
|
|
// load config from repo
|
|
let (load_config_from_repo_open_repository, read_files) =
|
|
given::open_repository_for_loading_config_from_repo(&repo_config);
|
|
expect::duplicate(&mut open_repository, load_config_from_repo_open_repository);
|
|
|
|
// handles_validate_repo_message(&mut open_repository, repo_config.branches());
|
|
|
|
let mut repository_factory = MockRepositoryFactory::new();
|
|
expect::open_repository(&mut repository_factory, open_repository);
|
|
fs.dir_create(&repo_details.gitdir)?;
|
|
let branch = repo_details.branch.clone();
|
|
|
|
//when
|
|
let (addr, _log) = when::start_actor(repository_factory, repo_details, given::a_forge());
|
|
addr.send(CloneRepo::new()).await?;
|
|
System::current().stop();
|
|
|
|
//then
|
|
tracing::debug!("{read_files:#?}");
|
|
let file_name = PathBuf::from(".git-next.toml".to_string());
|
|
read_files
|
|
.lock()
|
|
.map_err(|e| e.to_string())
|
|
.map(|files| assert_eq!(files.clone(), vec![(branch, file_name)]))?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[test_log::test(actix::test)]
|
|
async fn opened_repo_with_no_default_push_should_not_proceed() -> TestResult {
|
|
//given
|
|
let fs = given::a_filesystem();
|
|
let (mut open_repository, repo_details) = given::an_open_repository(&fs);
|
|
|
|
given::has_remote_defaults(
|
|
&mut open_repository,
|
|
HashMap::from([
|
|
(Direction::Push, None),
|
|
(Direction::Fetch, Some(repo_details.git_remote())),
|
|
]),
|
|
);
|
|
|
|
let mut repository_factory = MockRepositoryFactory::new();
|
|
expect::open_repository(&mut repository_factory, open_repository);
|
|
fs.dir_create(&repo_details.gitdir)?;
|
|
|
|
//when
|
|
let (addr, log) = when::start_actor(repository_factory, repo_details, given::a_forge());
|
|
addr.send(CloneRepo::new()).await?;
|
|
System::current().stop();
|
|
|
|
//then
|
|
log.lock()
|
|
.map_err(|e| e.to_string())
|
|
// doesn't log that it sent any messages to load config or validate the repo
|
|
.map(|l| assert_eq!(l.clone(), vec!["open failed"]))?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[test_log::test(actix::test)]
|
|
async fn opened_repo_with_no_default_fetch_should_not_proceed() -> TestResult {
|
|
//given
|
|
let fs = given::a_filesystem();
|
|
let (mut open_repository, repo_details) = given::an_open_repository(&fs);
|
|
|
|
given::has_remote_defaults(
|
|
&mut open_repository,
|
|
HashMap::from([
|
|
(Direction::Push, Some(repo_details.git_remote())),
|
|
(Direction::Fetch, None),
|
|
]),
|
|
);
|
|
|
|
let mut repository_factory = MockRepositoryFactory::new();
|
|
expect::open_repository(&mut repository_factory, open_repository);
|
|
fs.dir_create(&repo_details.gitdir)?;
|
|
|
|
//when
|
|
let (addr, log) = when::start_actor(repository_factory, repo_details, given::a_forge());
|
|
addr.send(CloneRepo::new()).await?;
|
|
System::current().stop();
|
|
|
|
//then
|
|
log.lock()
|
|
.map_err(|e| e.to_string())
|
|
// doesn't log that it sent any messages to load config or validate the repo
|
|
.map(|l| assert_eq!(l.clone(), vec!["open failed"]))?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[test_log::test(actix::test)]
|
|
async fn valid_repo_with_default_remotes_should_assess_branch_positions() -> TestResult {
|
|
//given
|
|
let fs = given::a_filesystem();
|
|
let (mut open_repository, repo_details) = given::an_open_repository(&fs);
|
|
|
|
given::has_all_valid_remote_defaults(&mut open_repository, &repo_details);
|
|
|
|
let mut repository_factory = MockRepositoryFactory::new();
|
|
expect::open_repository(&mut repository_factory, open_repository);
|
|
fs.dir_create(&repo_details.gitdir)?;
|
|
|
|
//when
|
|
let (addr, log) = when::start_actor(repository_factory, repo_details, given::a_forge());
|
|
addr.send(CloneRepo::new()).await?;
|
|
System::current().stop();
|
|
|
|
//then
|
|
log.lock()
|
|
.map_err(|e| e.to_string())
|
|
.map(|l| assert!(l.iter().any(|l| l.contains("send: ValidateRepo"))))?;
|
|
|
|
Ok(())
|
|
}
|