WIP: refactor: CloneRepo use actor::do_send to send LoadConfigFromRepo
All checks were successful
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-06-29 20:04:26 +01:00
parent f038ab508b
commit 46ceceec46
2 changed files with 38 additions and 13 deletions

View file

@ -20,9 +20,11 @@ impl Handler<actor::messages::CloneRepo> for actor::RepoActor {
tracing::debug!("open okay");
self.open_repository.replace(repository);
if self.repo_details.repo_config.is_none() {
tracing::debug!("Handler: CloneRepo: Sending: LoadConfigFromRepo");
actor::logger(&self.log, "send: LoadConfigFromRepo");
ctx.address().do_send(actor::messages::LoadConfigFromRepo);
actor::do_send(
ctx.address(),
actor::messages::LoadConfigFromRepo,
&self.log,
);
} else {
tracing::debug!("Handler: CloneRepo: Sending: ValidateRepo");
actor::logger(&self.log, "send: ValidateRepo");

View file

@ -91,12 +91,34 @@ async fn when_server_has_no_repo_config_load_from_repo_and_validate() -> TestRes
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);
let branches = repo_config.branches().clone();
let mut load_config_from_repo_open_repository = MockOpenRepositoryLike::new();
let load_file_log = RepoActorLog::default();
let load_file_log_ref = Some(load_file_log.clone());
load_config_from_repo_open_repository
.expect_read_file()
.return_once(move |branch_name, file_name| {
let branch_name = branch_name.clone();
let file_name = file_name.to_path_buf();
actor::logger(
&load_file_log_ref,
format!("read_file:${branch_name}:${file_name:?}"),
);
let contents = format!(
r#"
[branches]
main = "{}"
next = "{}"
dev = "{}"
"#,
branches.main(),
branches.next(),
branches.dev()
);
Ok(contents)
});
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)?;
@ -108,12 +130,13 @@ async fn when_server_has_no_repo_config_load_from_repo_and_validate() -> TestRes
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)]))?;
load_file_log.require_message_containing("read_file:branch:file")?;
// 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(())
}