test: update tests to check for email config parsing
All checks were successful
Rust / build (push) Successful in 1m18s
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-08-02 18:46:29 +01:00
parent 7b056cb879
commit 9fb70f98d6
2 changed files with 29 additions and 12 deletions

View file

@ -8,7 +8,7 @@ use std::{
str::FromStr,
};
use derive_more::Display;
use derive_more::{Constructor, Display};
use kxio::fs::FileSystem;
use secrecy::Secret;
use serde::{Deserialize, Serialize};
@ -204,19 +204,13 @@ impl ServerStorage {
Ord,
derive_more::AsRef,
serde::Deserialize,
Constructor,
)]
pub struct Shout {
webhook: Option<OutboundWebhook>,
email: Option<EmailConfig>,
}
impl Shout {
pub const fn new_webhook(webhook: OutboundWebhook) -> Self {
Self {
webhook: Some(webhook),
email: None,
}
}
pub const fn webhook(&self) -> Option<&OutboundWebhook> {
self.webhook.as_ref()
}

View file

@ -475,6 +475,13 @@ mod server {
.webhook_secret()
.map(|secret| secret.expose_secret().clone())
.unwrap_or_default();
let_assert!(Some(shout_email) = shout.email());
let shout_email_from = shout_email.from();
let shout_email_to = shout_email.to();
let_assert!(Some(shout_email_smtp) = shout_email.smtp());
let shout_email_smtp_hostname = shout_email_smtp.hostname();
let shout_email_smtp_username = shout_email_smtp.username();
let shout_email_smtp_password = shout_email_smtp.password();
let forge_alias = server_config
.forges()
.next()
@ -521,6 +528,15 @@ url = "{listen_url}"
[shout]
webhook = {{ url = "{shout_webhook_url}", secret = "{shout_webhook_secret}" }}
[shout.email]
from = "{shout_email_from}"
to = "{shout_email_to}"
[shout.email.smtp]
hostname = "{shout_email_smtp_hostname}"
username = "{shout_email_smtp_username}"
password = "{shout_email_smtp_password}"
[storage]
path = {storage_path:?}
@ -692,7 +708,7 @@ mod push {
}
mod given {
use crate::server::{Listen, ListenUrl, OutboundWebhook, Shout};
use crate::server::{EmailConfig, Listen, ListenUrl, OutboundWebhook, Shout, SmtpConfig};
use super::*;
use rand::Rng as _;
@ -716,7 +732,7 @@ mod given {
pub fn a_server_config() -> ServerConfig {
ServerConfig::new(
a_listen(),
a_notification_config(),
a_shout(),
a_server_storage(),
some_forge_configs(),
)
@ -746,11 +762,18 @@ mod given {
pub fn an_outbound_webhook() -> OutboundWebhook {
OutboundWebhook::new(a_name(), a_name())
}
pub fn an_email_config() -> EmailConfig {
EmailConfig::new(
a_name(),
a_name(),
Some(SmtpConfig::new(a_name(), a_name(), a_name())),
)
}
pub fn a_server_storage() -> ServerStorage {
ServerStorage::new(a_name().into())
}
pub fn a_notification_config() -> Shout {
Shout::new_webhook(an_outbound_webhook())
pub fn a_shout() -> Shout {
Shout::new(Some(an_outbound_webhook()), Some(an_email_config()))
}
pub fn some_forge_configs() -> BTreeMap<String, ForgeConfig> {
[(a_name(), a_forge_config())].into()