all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH proxmox 5/5] notify: Add test for State
Date: Wed,  4 Feb 2026 17:13:44 +0100	[thread overview]
Message-ID: <20260204161354.458814-6-a.bied-charreton@proxmox.com> (raw)
In-Reply-To: <20260204161354.458814-1-a.bied-charreton@proxmox.com>

Add test verifying basic functionality and state persistence.

Signed-off-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
---
 proxmox-notify/src/lib.rs | 56 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 55 insertions(+), 1 deletion(-)

diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs
index 3bd83ce4..f4fd3aa2 100644
--- a/proxmox-notify/src/lib.rs
+++ b/proxmox-notify/src/lib.rs
@@ -683,10 +683,25 @@ mod tests {
         messages: Rc<RefCell<Vec<Notification>>>,
     }
 
+    #[derive(Default, Clone, Serialize, Deserialize)]
+    struct MockEndpointState {
+        notifications_sent: usize,
+    }
+
+    impl EndpointState for MockEndpointState {}
+
     impl Endpoint for MockEndpoint {
-        fn send(&self, message: &Notification, _: &mut State) -> Result<(), Error> {
+        fn send(&self, message: &Notification, state: &mut State) -> Result<(), Error> {
+            let endpoint_state = state.get_or_default::<MockEndpointState>(self.name)?;
             self.messages.borrow_mut().push(message.clone());
 
+            state.set(
+                self.name,
+                &MockEndpointState {
+                    notifications_sent: endpoint_state.notifications_sent + 1,
+                },
+            )?;
+
             Ok(())
         }
 
@@ -791,4 +806,43 @@ mod tests {
 
         Ok(())
     }
+
+    #[test]
+    fn test_endpoint_with_state() -> Result<(), Error> {
+        let mut state = State::default();
+        let mock = MockEndpoint::new("endpoint");
+
+        let mut bus = Bus::default();
+        bus.add_endpoint(Box::new(mock.clone()));
+
+        let matcher = MatcherConfig {
+            target: vec!["endpoint".into()],
+            ..Default::default()
+        };
+
+        bus.add_matcher(matcher);
+
+        // Send directly to endpoint
+        bus.send(
+            &Notification::from_template(
+                Severity::Info,
+                "test",
+                Default::default(),
+                Default::default(),
+            ),
+            &mut state,
+        );
+
+        let endpoint_state = state.get::<MockEndpointState>("endpoint")?.unwrap();
+
+        assert_eq!(endpoint_state.notifications_sent, 1);
+
+        state.persist(context().state_file_path())?;
+
+        let persisted_state = State::from_path(context().state_file_path())?;
+
+        assert_eq!(state, persisted_state);
+
+        Ok(())
+    }
 }
-- 
2.47.3




  parent reply	other threads:[~2026-02-04 16:14 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-04 16:13 [RFC cluster/docs/manager/proxmox{,-perl-rs,-widget-toolkit} 00/15] fix #7238: Add XOAUTH2 authentication support for SMTP notification targets Arthur Bied-Charreton
2026-02-04 16:13 ` [PATCH proxmox 1/5] notify: Introduce xoauth2 module Arthur Bied-Charreton
2026-02-04 16:13 ` [PATCH proxmox 2/5] notify: Add state file handling Arthur Bied-Charreton
2026-02-04 16:13 ` [PATCH proxmox 3/5] notify: Update Endpoint trait and Bus to use State Arthur Bied-Charreton
2026-02-04 16:13 ` [PATCH proxmox 4/5] notify: smtp: add OAuth2/XOAUTH2 authentication support Arthur Bied-Charreton
2026-02-04 16:13 ` Arthur Bied-Charreton [this message]
2026-02-04 16:13 ` [PATCH proxmox-perl-rs 1/1] notify: update bindings with new OAuth2 parameters Arthur Bied-Charreton
2026-02-04 16:13 ` [PATCH proxmox-widget-toolkit 1/2] utils: Add OAuth2 flow handlers Arthur Bied-Charreton
2026-02-04 16:13 ` [PATCH proxmox-widget-toolkit 2/2] notifications: Add opt-in OAuth2 support for SMTP targets Arthur Bied-Charreton
2026-02-04 16:13 ` [PATCH pve-manager 1/5] notifications: Add OAuth2 parameters to schema and add/update endpoints Arthur Bied-Charreton
2026-02-04 16:13 ` [PATCH pve-manager 2/5] notifications: Add refresh-targets endpoint Arthur Bied-Charreton
2026-02-04 16:13 ` [PATCH pve-manager 3/5] notifications: Trigger notification target refresh in pveupdate Arthur Bied-Charreton
2026-02-04 16:13 ` [PATCH pve-manager 4/5] notifications: Handle OAuth2 callback in login handler Arthur Bied-Charreton
2026-02-04 16:13 ` [PATCH pve-manager 5/5] notifications: Opt into OAuth2 authentication Arthur Bied-Charreton
2026-02-04 16:13 ` [PATCH pve-cluster 1/1] notifications: Add refresh_targets subroutine to PVE::Notify Arthur Bied-Charreton
2026-02-04 16:13 ` [PATCH pve-docs 1/1] notifications: Add section about OAuth2 to SMTP targets docs Arthur Bied-Charreton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260204161354.458814-6-a.bied-charreton@proxmox.com \
    --to=a.bied-charreton@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal