// use crate::{self as actor}; use actix::prelude::*; use actor::{ messages::{CloneRepo, MessageToken}, RepoActor, RepoActorLog, }; use assert2::let_assert; use config::{ server::{Webhook, WebhookUrl}, webhook::forge_notification::Body, BranchName, ForgeAlias, ForgeConfig, ForgeNotification, ForgeType, GitDir, RegisteredWebhook, RepoAlias, RepoBranches, RepoConfig, ServerRepoConfig, WebhookAuth, WebhookId, }; use git::{ repository::{factory::MockRepositoryFactory, open::MockOpenRepositoryLike, Direction}, Generation, GitRemote, MockForgeLike, RepoDetails, }; use git_next_actor_macros::message; use git_next_config as config; use git_next_git as git; use mockall::predicate::eq; use std::{ collections::{BTreeMap, HashMap}, sync::{Arc, RwLock}, }; type TestResult = Result<(), Box>; mod branch; mod expect; pub mod given; mod handlers; mod load; mod when; impl RepoActorLog { pub fn no_message_contains(&self, needle: impl AsRef + std::fmt::Display) -> TestResult { if self.find_in_messages(needle.as_ref())? { tracing::error!(?self, ""); panic!("found unexpected message: {needle}"); } Ok(()) } pub fn require_message_containing( &self, needle: impl AsRef + std::fmt::Display, ) -> TestResult { if !self.find_in_messages(needle.as_ref())? { tracing::error!(?self, ""); panic!("expected message not found: {needle}"); } Ok(()) } fn find_in_messages( &self, needle: impl AsRef, ) -> Result> { let found = self .read() .map_err(|e| e.to_string())? .iter() .any(|message| message.contains(needle.as_ref())); Ok(found) } } message!(ExamineActor => RepoActorView: "Request a view of the current state of the [RepoActor]."); impl Handler for RepoActor { type Result = RepoActorView; fn handle(&mut self, _msg: ExamineActor, _ctx: &mut Self::Context) -> Self::Result { let repo_actor: &Self = self; Self::Result::from(repo_actor) } } #[derive(Debug, MessageResponse)] pub struct RepoActorView { pub sleep_duration: std::time::Duration, pub generation: git::Generation, pub message_token: MessageToken, pub repo_details: git::RepoDetails, pub webhook: config::server::Webhook, pub webhook_id: Option, // INFO: if [None] then no webhook is configured pub webhook_auth: Option, // INFO: if [None] then no webhook is configured pub last_main_commit: Option, pub last_next_commit: Option, pub last_dev_commit: Option, pub log: Option, } impl From<&RepoActor> for RepoActorView { fn from(repo_actor: &RepoActor) -> Self { Self { sleep_duration: repo_actor.sleep_duration, generation: repo_actor.generation, message_token: repo_actor.message_token, repo_details: repo_actor.repo_details.clone(), webhook: repo_actor.webhook.clone(), webhook_id: repo_actor.webhook_id.clone(), webhook_auth: repo_actor.webhook_auth.clone(), last_main_commit: repo_actor.last_main_commit.clone(), last_next_commit: repo_actor.last_next_commit.clone(), last_dev_commit: repo_actor.last_dev_commit.clone(), log: repo_actor.log.clone(), } } }