From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id CA4FABA6B7 for ; Thu, 14 Dec 2023 13:42:11 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 932A5169F1 for ; Thu, 14 Dec 2023 13:42:11 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 14 Dec 2023 13:42:10 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 9F6EB475D8 for ; Thu, 14 Dec 2023 13:42:10 +0100 (CET) From: Lukas Wagner To: pve-devel@lists.proxmox.com Date: Thu, 14 Dec 2023 13:42:08 +0100 Message-Id: <20231214124208.219312-2-l.wagner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214124208.219312-1-l.wagner@proxmox.com> References: <20231214124208.219312-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.004 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH proxmox 2/2] notify: add separate context for unit-tests X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Dec 2023 12:42:11 -0000 ... as using PVEContext for tests is brittle and annoying for some tests. Signed-off-by: Lukas Wagner --- proxmox-notify/src/context/mod.rs | 10 +++++----- proxmox-notify/src/context/test.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 proxmox-notify/src/context/test.rs diff --git a/proxmox-notify/src/context/mod.rs b/proxmox-notify/src/context/mod.rs index b419641..cc68603 100644 --- a/proxmox-notify/src/context/mod.rs +++ b/proxmox-notify/src/context/mod.rs @@ -7,6 +7,8 @@ pub mod common; pub mod pbs; #[cfg(feature = "pve-context")] pub mod pve; +#[cfg(test)] +mod test; /// Product-specific context pub trait Context: Send + Sync + Debug { @@ -22,12 +24,10 @@ pub trait Context: Send + Sync + Debug { fn default_config(&self) -> &'static str; } -#[cfg(not(feature = "pve-context"))] +#[cfg(not(test))] static CONTEXT: Mutex> = Mutex::new(None); -// The test unfortunately require context... -// TODO: Check if we can make this nicer... -#[cfg(feature = "pve-context")] -static CONTEXT: Mutex> = Mutex::new(Some(&pve::PVE_CONTEXT)); +#[cfg(test)] +static CONTEXT: Mutex> = Mutex::new(Some(&test::TestContext)); /// Set the product-specific context pub fn set_context(context: &'static dyn Context) { diff --git a/proxmox-notify/src/context/test.rs b/proxmox-notify/src/context/test.rs new file mode 100644 index 0000000..61f794a --- /dev/null +++ b/proxmox-notify/src/context/test.rs @@ -0,0 +1,26 @@ +use crate::context::Context; + +#[derive(Debug)] +pub struct TestContext; + +impl Context for TestContext { + fn lookup_email_for_user(&self, _user: &str) -> Option { + Some("test@example.com".into()) + } + + fn default_sendmail_author(&self) -> String { + "Proxmox VE".into() + } + + fn default_sendmail_from(&self) -> String { + "root".into() + } + + fn http_proxy_config(&self) -> Option { + None + } + + fn default_config(&self) -> &'static str { + "" + } +} -- 2.39.2