2024-06-27 21:10:41 +01:00
|
|
|
//
|
|
|
|
use actix::prelude::*;
|
2024-07-25 09:02:43 +01:00
|
|
|
|
|
|
|
use crate::{
|
2024-07-28 08:58:32 +01:00
|
|
|
git,
|
|
|
|
repo::{
|
|
|
|
messages::{CloneRepo, MessageToken},
|
2024-08-05 07:39:38 +01:00
|
|
|
ActorLog, RepoActor,
|
2024-07-28 08:58:32 +01:00
|
|
|
},
|
2024-06-27 21:10:41 +01:00
|
|
|
};
|
2024-07-28 08:58:32 +01:00
|
|
|
|
2024-07-25 09:02:43 +01:00
|
|
|
use git_next_core::{
|
2024-07-26 06:49:09 +01:00
|
|
|
git::{
|
2024-07-28 08:58:32 +01:00
|
|
|
commit::Sha,
|
|
|
|
forge::commit::Status,
|
2024-07-26 06:49:09 +01:00
|
|
|
repository::{
|
2024-07-28 08:58:32 +01:00
|
|
|
factory::{mock, MockRepositoryFactory, RepositoryFactory},
|
2024-07-26 06:49:09 +01:00
|
|
|
open::{MockOpenRepositoryLike, OpenRepositoryLike},
|
|
|
|
Direction,
|
|
|
|
},
|
2024-07-28 08:58:32 +01:00
|
|
|
Commit, ForgeLike, Generation, MockForgeLike, RepoDetails,
|
2024-07-26 06:49:09 +01:00
|
|
|
},
|
2024-07-25 09:02:43 +01:00
|
|
|
message,
|
2024-07-28 08:58:32 +01:00
|
|
|
webhook::{forge_notification::Body, Push},
|
2024-07-25 09:02:43 +01:00
|
|
|
BranchName, ForgeAlias, ForgeConfig, ForgeNotification, ForgeType, GitDir, Hostname,
|
|
|
|
RegisteredWebhook, RemoteUrl, RepoAlias, RepoBranches, RepoConfig, RepoConfigSource,
|
|
|
|
ServerRepoConfig, StoragePathType, WebhookAuth, WebhookId,
|
2024-06-27 21:10:41 +01:00
|
|
|
};
|
2024-07-25 09:02:43 +01:00
|
|
|
|
|
|
|
use assert2::let_assert;
|
2024-06-27 21:10:41 +01:00
|
|
|
use mockall::predicate::eq;
|
2024-07-28 08:58:32 +01:00
|
|
|
use tracing::{debug, error};
|
2024-07-25 09:02:43 +01:00
|
|
|
|
2024-06-27 21:10:41 +01:00
|
|
|
use std::{
|
|
|
|
collections::{BTreeMap, HashMap},
|
2024-06-30 13:17:33 +01:00
|
|
|
sync::{Arc, RwLock},
|
2024-06-27 21:10:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
type TestResult = Result<(), Box<dyn std::error::Error>>;
|
|
|
|
|
|
|
|
mod branch;
|
|
|
|
mod expect;
|
|
|
|
pub mod given;
|
|
|
|
mod handlers;
|
|
|
|
mod load;
|
|
|
|
mod when;
|
|
|
|
|
2024-08-05 07:39:38 +01:00
|
|
|
impl ActorLog {
|
2024-06-27 21:10:41 +01:00
|
|
|
pub fn no_message_contains(&self, needle: impl AsRef<str> + std::fmt::Display) -> TestResult {
|
|
|
|
if self.find_in_messages(needle.as_ref())? {
|
2024-07-28 08:58:32 +01:00
|
|
|
error!(?self, "");
|
2024-06-27 21:10:41 +01:00
|
|
|
panic!("found unexpected message: {needle}");
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn require_message_containing(
|
|
|
|
&self,
|
|
|
|
needle: impl AsRef<str> + std::fmt::Display,
|
|
|
|
) -> TestResult {
|
|
|
|
if !self.find_in_messages(needle.as_ref())? {
|
2024-07-28 08:58:32 +01:00
|
|
|
error!(?self, "");
|
2024-06-27 21:10:41 +01:00
|
|
|
panic!("expected message not found: {needle}");
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn find_in_messages(
|
|
|
|
&self,
|
|
|
|
needle: impl AsRef<str>,
|
|
|
|
) -> Result<bool, Box<dyn std::error::Error>> {
|
|
|
|
let found = self
|
2024-06-30 12:40:17 +01:00
|
|
|
.read()
|
2024-06-27 21:10:41 +01:00
|
|
|
.map_err(|e| e.to_string())?
|
|
|
|
.iter()
|
|
|
|
.any(|message| message.contains(needle.as_ref()));
|
|
|
|
Ok(found)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-29 14:56:20 +01:00
|
|
|
message!(ExamineActor => RepoActorView: "Request a view of the current state of the [RepoActor].");
|
2024-06-27 21:10:41 +01:00
|
|
|
impl Handler<ExamineActor> 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 {
|
2024-07-28 08:58:32 +01:00
|
|
|
pub repo_details: RepoDetails,
|
2024-07-25 09:02:43 +01:00
|
|
|
pub webhook_id: Option<WebhookId>, // INFO: if [None] then no webhook is configured
|
|
|
|
pub webhook_auth: Option<WebhookAuth>, // INFO: if [None] then no webhook is configured
|
2024-07-28 08:58:32 +01:00
|
|
|
pub last_main_commit: Option<Commit>,
|
|
|
|
pub last_next_commit: Option<Commit>,
|
|
|
|
pub last_dev_commit: Option<Commit>,
|
2024-06-27 21:10:41 +01:00
|
|
|
}
|
|
|
|
impl From<&RepoActor> for RepoActorView {
|
|
|
|
fn from(repo_actor: &RepoActor) -> Self {
|
|
|
|
Self {
|
|
|
|
repo_details: repo_actor.repo_details.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(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|