Improve rules migration ITs
@@ -56,38 +56,57 @@ fn upgrade(
#[cfg(test)]
mod test {
use super::*;
- use crate::config::MatcherConfigReader;
use tempfile::TempDir;
#[test]
- fn should_create_a_new_draft_cloning_from_current_config_with_root_filter() -> Result<(), Box<dyn std::error::Error>> {
+ fn should_migrate_the_monitoring_rules() {
// Arrange
- let tempdir = tempfile::tempdir()?;
+ let tempdir = tempfile::tempdir().unwrap();
let (config_dir, rules_dir, drafts_dir) = prepare_temp_dirs(&tempdir);
+ let configs = parse_config_files(&config_dir, &rules_dir, &drafts_dir).unwrap();
+
+ let matcher_config_before = configs.matcher_config.get_config().unwrap();
// Act
- let result = upgrade_rules(&config_dir, &rules_dir, &drafts_dir);
+ upgrade_rules(&config_dir, &rules_dir, &drafts_dir).unwrap();
// Assert
- assert!(result.is_ok());
+ let matcher_config_after = configs.matcher_config.get_config().unwrap();
+ assert_ne!(matcher_config_before, matcher_config_after);
- Ok(())
+ match matcher_config_before {
+ MatcherConfig::Filter {nodes: before_nodes, ..} => {
+ match matcher_config_after {
+ MatcherConfig::Filter {nodes: after_nodes, ..} => {
+ assert_eq!(before_nodes.len(), after_nodes.len());
+
+ let ToDo = 0;
+ // ToDo: check the monitoring rules was migrated
+ assert!(false)
+ },
+ _ => assert!(false)
+ }
+ },
+ _ => assert!(false)
+ }
}
+ #[test]
+ fn upgrade_fn_should_migrate_the_monitoring_rules() {
+ unimplemented!()
+ }
fn prepare_temp_dirs(tempdir: &TempDir) -> (String, String, String) {
- let config_dir = "./config".to_owned();
- let draft_dir = "/draft".to_owned();
- let rules_dir = "/rules".to_owned();
-
- let source_rules_dir = format!("{}/{}", config_dir, rules_dir);
-
- let dest_drafts_dir = format!("{}/{}", tempdir.path().to_str().unwrap(), draft_dir);
- let dest_rules_dir = format!("{}/{}", tempdir.path().to_str().unwrap(), rules_dir);
+ let source_config_dir = "./config/".to_owned();
+ let dest_config_dir = tempdir.path().to_str().unwrap().to_owned();
let mut copy_options = fs_extra::dir::CopyOptions::new();
copy_options.copy_inside = true;
- fs_extra::dir::copy(&source_rules_dir, &dest_rules_dir, &copy_options).unwrap();
- (config_dir, rules_dir, draft_dir)
+ fs_extra::dir::copy(&source_config_dir, &dest_config_dir, &copy_options).unwrap();
+
+ let draft_dir = "/draft".to_owned();
+ let rules_dir = "/rules.d".to_owned();
+
+ (format!("{}/config", dest_config_dir), rules_dir, draft_dir)
}
}
\ No newline at end of file
