From 086cd7db3334284815adf37d2e53e151ec5db8e2 Mon Sep 17 00:00:00 2001
From: Philipp Hufnagl
Date: Tue, 2 Jan 2024 12:06:55 +0100
Subject: [PATCH] tests: check if include/exclude behavior works correctly
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
---
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));
+ }
+}