Add test (#41)

* Code refactoring

* Cleanup

* Added test and moved test files

* Cleanup

* Removed test mod file

* Tests reorganizing

* Removed test file
This commit was merged in pull request #41.
This commit is contained in:
KD
2025-03-25 22:43:42 -04:00
committed by GitHub
parent aa946a0a05
commit 92eb31a687
2 changed files with 113 additions and 68 deletions
-68
View File
@@ -166,71 +166,3 @@ impl ActionManager {
return parsed;
}
}
#[cfg(test)]
mod tests {
use crate::managers::action_managers::ActionManager;
#[test]
fn minimum_action_and_args() {
let args: Vec<String> = vec![
"icarus-dm".to_string(),
"download".to_string(),
"-u".to_string(),
"jamborie".to_string(),
"-p".to_string(),
"somethingsecr3t!".to_string(),
"-h".to_string(),
"https://music-server.com".to_string(),
];
let arg_count = args.len() as i32;
let minimum_arg_count = 8;
assert!(arg_count >= minimum_arg_count);
let mut act_mgr = ActionManager {
action: String::new(),
flags: Vec::new(),
params: args,
param_count: arg_count,
};
act_mgr.initialize();
let ica = act_mgr.retrieve_icarus_action();
let action = &ica.action;
let flags = &ica.flags;
assert!(action != "");
assert!(flags.len() > 2);
assert!(
!(action != "download"
&& action != "upload"
&& action != "retrieve"
&& action != "upload-meta")
);
let mut all_flags_found = false;
let mut found_count = 0;
let mut flags_already_read = Vec::new();
for flag in flags {
if flags_already_read.contains(&flag.flag) {
continue;
}
if flag.flag == "-u" {
found_count += 1;
flags_already_read.push(flag.flag.clone());
} else if flag.flag == "-p" {
found_count += 1;
flags_already_read.push(flag.flag.clone());
} else if flag.flag == "-h" {
found_count += 1;
flags_already_read.push(flag.flag.clone());
}
}
all_flags_found = found_count == 3;
assert_eq!(found_count, 3, "Three flags are required: -u, -p, -h");
assert!(all_flags_found, "All flags have not been found");
}
}