145 lines
4.1 KiB
Rust
145 lines
4.1 KiB
Rust
use std::{collections::HashSet, error::Error, path::PathBuf};
|
|
|
|
use fomod_manager::{
|
|
instance::{files_to_install_mod, insert_mod_to_instance},
|
|
types::{Link, RootConfig},
|
|
};
|
|
|
|
fn get_parent() -> PathBuf {
|
|
PathBuf::from(file!()).parent().unwrap().to_owned()
|
|
}
|
|
|
|
fn load_root() -> RootConfig {
|
|
RootConfig::load_from_file(get_parent().join("data/root_config_complex.toml")).unwrap()
|
|
}
|
|
|
|
#[test]
|
|
fn add_plain() -> Result<(), Box<dyn Error>> {
|
|
let root_config = load_root();
|
|
let mut instance = root_config.load_instance_by_id("instance_minimal")?;
|
|
let mod_to_install = root_config
|
|
.mod_by_id("add_test_plain")
|
|
.expect("Mod not found");
|
|
let files_to_add = files_to_install_mod(&root_config, &instance, &mod_to_install)?;
|
|
|
|
insert_mod_to_instance(&mut instance, &mod_to_install, &files_to_add, 0)?;
|
|
|
|
let installed_mods = instance.mods();
|
|
|
|
assert_eq!(installed_mods.len(), 1);
|
|
|
|
let the_mod = installed_mods.first().expect("Asserted before");
|
|
|
|
assert_eq!(the_mod.mod_id(), "add_test_plain");
|
|
assert_eq!(the_mod.priority(), 0);
|
|
|
|
let expected_files: HashSet<_> = [Link::new("plugin.esp", "Data/plugin.esp")]
|
|
.into_iter()
|
|
.collect();
|
|
|
|
assert_eq!(
|
|
*the_mod.files(),
|
|
expected_files,
|
|
"Installed files missmatch"
|
|
);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn add_nested() -> Result<(), Box<dyn Error>> {
|
|
let root_config = load_root();
|
|
let mut instance = root_config.load_instance_by_id("instance_minimal")?;
|
|
let mod_to_install = root_config
|
|
.mod_by_id("add_test_nested")
|
|
.expect("Mod not found");
|
|
let files_to_add = files_to_install_mod(&root_config, &instance, &mod_to_install)?;
|
|
|
|
insert_mod_to_instance(&mut instance, &mod_to_install, &files_to_add, 0)?;
|
|
|
|
let installed_mods = instance.mods();
|
|
|
|
assert_eq!(installed_mods.len(), 1);
|
|
|
|
let the_mod = installed_mods.first().expect("Asserted before");
|
|
|
|
assert_eq!(the_mod.mod_id(), "add_test_nested");
|
|
assert_eq!(the_mod.priority(), 0);
|
|
|
|
let expected_files: HashSet<_> = [Link::new("Data/plugin.esp", "Data/plugin.esp")]
|
|
.into_iter()
|
|
.collect();
|
|
|
|
assert_eq!(
|
|
*the_mod.files(),
|
|
expected_files,
|
|
"Installed files missmatch"
|
|
);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn add_root() -> Result<(), Box<dyn Error>> {
|
|
let root_config = load_root();
|
|
let mut instance = root_config.load_instance_by_id("instance_minimal")?;
|
|
let mod_to_install = root_config
|
|
.mod_by_id("add_test_root")
|
|
.expect("Mod not found");
|
|
let files_to_add = files_to_install_mod(&root_config, &instance, &mod_to_install)?;
|
|
|
|
insert_mod_to_instance(&mut instance, &mod_to_install, &files_to_add, 0)?;
|
|
|
|
let installed_mods = instance.mods();
|
|
|
|
assert_eq!(installed_mods.len(), 1, "No mod was added");
|
|
|
|
let the_mod = installed_mods.first().expect("Asserted before");
|
|
|
|
assert_eq!(the_mod.mod_id(), "add_test_root");
|
|
assert_eq!(the_mod.priority(), 0);
|
|
|
|
let expected_files: HashSet<_> = [Link::new("skse.exe", "skse.exe")].into_iter().collect();
|
|
|
|
assert_eq!(
|
|
*the_mod.files(),
|
|
expected_files,
|
|
"Installed files missmatch"
|
|
);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn add_filter() -> Result<(), Box<dyn Error>> {
|
|
let root_config = load_root();
|
|
let mut instance = root_config.load_instance_by_id("instance_minimal")?;
|
|
let mod_to_install = root_config
|
|
.mod_by_id("add_test_filter")
|
|
.expect("Mod not found");
|
|
let files_to_add = files_to_install_mod(&root_config, &instance, &mod_to_install)?;
|
|
|
|
insert_mod_to_instance(&mut instance, &mod_to_install, &files_to_add, 0)?;
|
|
|
|
let installed_mods = instance.mods();
|
|
|
|
assert_eq!(installed_mods.len(), 1, "No mod was added");
|
|
|
|
let the_mod = installed_mods.first().expect("Asserted before");
|
|
|
|
assert_eq!(the_mod.mod_id(), "add_test_filter");
|
|
assert_eq!(the_mod.priority(), 0);
|
|
|
|
let expected_files: HashSet<_> = [Link::new("plugin.esp", "plugin.esp")]
|
|
.into_iter()
|
|
.collect();
|
|
|
|
assert_eq!(
|
|
*the_mod.files(),
|
|
expected_files,
|
|
"Installed files missmatch"
|
|
);
|
|
|
|
Ok(())
|
|
}
|