fix: start validating repo after registering webhook
All checks were successful
Rust / build (push) Successful in 1m29s
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

Clone Repo wasn't sending the second message, so workaround: have it be
sent after registering the webhook.
This commit is contained in:
Paul Campbell 2024-06-30 16:54:26 +01:00
parent 55d8ccb0bd
commit 68005d757d
5 changed files with 33 additions and 59 deletions

View file

@ -21,12 +21,11 @@ ReceiveCIStatus --> [*] :on Fail
AdvanceNext --> ValidateRepo
ReceiveRepoConfig --> ValidateRepo
ReceiveRepoConfig --> RegisterWebhook
RegisterWebhook --> WebhookRegistered
WebhookRegistered --> [*]
WebhookRegistered --> ValidateRepo
AdvanceMain --> LoadConfigFromRepo :on repo config
AdvanceMain --> ValidateRepo :on server config

View file

@ -32,11 +32,6 @@ impl Handler<actor::messages::CloneRepo> for actor::RepoActor {
actor::messages::RegisterWebhook::new(),
&self.log,
);
actor::do_send(
ctx.address(),
actor::messages::ValidateRepo::new(self.message_token),
&self.log,
);
}
}
Err(err) => {

View file

@ -9,9 +9,14 @@ impl Handler<actor::messages::WebhookRegistered> for actor::RepoActor {
fn handle(
&mut self,
msg: actor::messages::WebhookRegistered,
_ctx: &mut Self::Context,
ctx: &mut Self::Context,
) -> Self::Result {
self.webhook_id.replace(msg.webhook_id().clone());
self.webhook_auth.replace(msg.webhook_auth().clone());
actor::do_send(
ctx.address(),
actor::messages::ValidateRepo::new(self.message_token),
&self.log,
);
}
}

View file

@ -1,5 +1,4 @@
//
use super::*;
#[actix::test]
@ -105,31 +104,6 @@ async fn when_server_has_no_repo_config_should_send_load_from_repo() -> TestResu
Ok(())
}
/// The server config can optionally include the names of the main, next and dev
/// branches. When it does we should go straight to sending a [ValidateRepo] message.
#[actix::test]
async fn when_server_has_repo_config_should_send_validate_repo() -> TestResult {
//given
let fs = given::a_filesystem();
let (mut open_repository, repo_details) = given::an_open_repository(&fs);
#[allow(clippy::unwrap_used)]
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.require_message_containing("send: ValidateRepo")?;
Ok(())
}
/// The server config can optionally include the names of the main, next and dev
/// branches. When it does we should register the webhook by sending [RegisterWebhook] message.
#[actix::test]
@ -212,28 +186,3 @@ async fn opened_repo_with_no_default_fetch_should_not_proceed() -> TestResult {
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.read()
.map_err(|e| e.to_string())
.map(|l| assert!(l.iter().any(|l| l.contains("send: ValidateRepo"))))?;
Ok(())
}

View file

@ -28,3 +28,29 @@ async fn should_store_webhook_details() -> TestResult {
assert_eq!(view.webhook_auth, Some(webhook_auth));
Ok(())
}
#[actix::test]
async fn should_send_validate_repo_message() -> TestResult {
//given
let fs = given::a_filesystem();
let (open_repository, repo_details) = given::an_open_repository(&fs);
let webhook_id = given::a_webhook_id();
let webhook_auth = given::a_webhook_auth();
//when
let (addr, log) = when::start_actor_with_open_repository(
Box::new(open_repository),
repo_details,
given::a_forge(),
);
addr.send(actor::messages::WebhookRegistered::new((
webhook_id.clone(),
webhook_auth.clone(),
)))
.await?;
System::current().stop();
//then
log.require_message_containing("send: ValidateRepo")?;
Ok(())
}