public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Philipp Hufnagl <p.hufnagl@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v7 4/4] tests: check if include/exclude behavior works correctly
Date: Tue,  2 Jan 2024 12:06:55 +0100	[thread overview]
Message-ID: <20240102110655.155329-5-p.hufnagl@proxmox.com> (raw)
In-Reply-To: <20240102110655.155329-1-p.hufnagl@proxmox.com>

This checks if including and excluding works as expected. That the
filter are added out of order is on purpose since it sould make no
difference.

Signed-off-by: Philipp Hufnagl <p.hufnagl@proxmox.com>
---
 tests/sync_jobs.rs | 76 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 tests/sync_jobs.rs

diff --git a/tests/sync_jobs.rs b/tests/sync_jobs.rs
new file mode 100644
index 00000000..45b46f14
--- /dev/null
+++ b/tests/sync_jobs.rs
@@ -0,0 +1,76 @@
+use pbs_api_types::{BackupGroup, BackupType, GroupFilter};
+use std::str::FromStr;
+
+#[test]
+fn test_no_filters() {
+    let group_filters = vec![];
+
+    let do_backup = vec![
+        "vm/101", "vm/102", "vm/103", "vm/104", "vm/105", "vm/106", "vm/107", "vm/108", "vm/109",
+    ];
+
+    for id in do_backup {
+        assert!(BackupGroup::new(BackupType::Vm, id).apply_filters(&group_filters));
+    }
+}
+
+#[test]
+fn test_include_filters() {
+    let group_filters = vec![GroupFilter::from_str("regex:.*10[2-8]").unwrap()];
+
+    let do_backup = vec![
+        "vm/102", "vm/103", "vm/104", "vm/105", "vm/106", "vm/107", "vm/108",
+    ];
+
+    let dont_backup = vec!["vm/101", "vm/109"];
+
+    for id in do_backup {
+        assert!(BackupGroup::new(BackupType::Vm, id).apply_filters(&group_filters));
+    }
+
+    for id in dont_backup {
+        assert!(!BackupGroup::new(BackupType::Vm, id).apply_filters(&group_filters));
+    }
+}
+
+#[test]
+fn test_exclude_filters() {
+    let group_filters = vec![
+        GroupFilter::from_str("exclude:regex:.*10[1-3]").unwrap(),
+        GroupFilter::from_str("exclude:regex:.*10[5-7]").unwrap(),
+    ];
+
+    let do_backup = vec!["vm/104", "vm/108", "vm/109"];
+
+    let dont_backup = vec!["vm/101", "vm/102", "vm/103", "vm/105", "vm/106", "vm/107"];
+
+    for id in do_backup {
+        assert!(BackupGroup::new(BackupType::Vm, id).apply_filters(&group_filters));
+    }
+    for id in dont_backup {
+        assert!(!BackupGroup::new(BackupType::Vm, id).apply_filters(&group_filters));
+    }
+}
+
+#[test]
+fn test_include_and_exclude_filters() {
+    let group_filters = vec![
+        GroupFilter::from_str("exclude:regex:.*10[1-3]").unwrap(),
+        GroupFilter::from_str("regex:.*10[2-8]").unwrap(),
+        GroupFilter::from_str("exclude:regex:.*10[5-7]").unwrap(),
+    ];
+
+    let do_backup = vec!["vm/104", "vm/108"];
+
+    let dont_backup = vec![
+        "vm/101", "vm/102", "vm/103", "vm/105", "vm/106", "vm/107", "vm/109",
+    ];
+
+    for id in do_backup {
+        assert!(BackupGroup::new(BackupType::Vm, id).apply_filters(&group_filters));
+    }
+
+    for id in dont_backup {
+        assert!(!BackupGroup::new(BackupType::Vm, id).apply_filters(&group_filters));
+    }
+}
-- 
2.39.2





  parent reply	other threads:[~2024-01-02 11:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-02 11:06 [pbs-devel] [PATCH proxmox-backup v7 0/4] fix #4315: datastore: Exclude entries from sync Philipp Hufnagl
2024-01-02 11:06 ` [pbs-devel] [PATCH proxmox-backup v7 1/4] fix #4315: jobs: modify GroupFilter so include/exclude is tracked Philipp Hufnagl
2024-01-02 11:06 ` [pbs-devel] [PATCH proxmox-backup v7 2/4] ui: Show if Filter includes or excludes Philipp Hufnagl
2024-01-02 11:06 ` [pbs-devel] [PATCH proxmox-backup v7 3/4] docs: document new include/exclude paramenter Philipp Hufnagl
2024-01-22 15:13   ` Thomas Lamprecht
2024-01-02 11:06 ` Philipp Hufnagl [this message]
2024-01-02 13:33 ` [pbs-devel] [PATCH proxmox-backup v7 0/4] fix #4315: datastore: Exclude entries from sync Lukas Wagner
2024-01-10  9:14 ` [pbs-devel] applied-series: " Wolfgang Bumiller

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=20240102110655.155329-5-p.hufnagl@proxmox.com \
    --to=p.hufnagl@proxmox.com \
    --cc=pbs-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal