#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://github.com/ow-mods/ow-mod-man/blob/main/.github/assets/logo-core.png?raw=true"
)]
#![warn(missing_docs)]
pub mod alerts;
pub mod analytics;
pub mod config;
pub mod constants;
pub mod db;
pub mod download;
pub mod file;
pub mod game;
pub mod io;
pub mod mods;
pub mod owml;
pub mod open;
pub mod progress;
pub mod remove;
pub mod socket;
pub mod toggle;
pub mod updates;
pub mod validate;
pub mod search;
pub mod protocol;
#[cfg(test)]
pub(crate) mod test_utils {
use std::path::{Path, PathBuf};
use tempfile::TempDir;
use crate::{
config::Config,
db::{LocalDatabase, RemoteDatabase},
download::install_mod_from_zip,
mods::local::{LocalMod, UnsafeLocalMod},
};
pub struct TestContext {
pub temp_dir: TempDir,
pub owml_dir: PathBuf,
pub config: Config,
pub local_db: LocalDatabase,
pub remote_db: RemoteDatabase,
}
pub fn make_test_dir() -> TempDir {
TempDir::new().unwrap()
}
pub fn get_test_file(path: &str) -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
.join("test_files")
.join(path)
}
impl TestContext {
pub fn new() -> Self {
let temp_dir = make_test_dir();
let owml_dir = temp_dir.path().join("OWML");
let mut config = Config::default(Some(temp_dir.path().join("settings.json"))).unwrap();
config.owml_path = owml_dir.to_str().unwrap().to_string();
let local_db = LocalDatabase::default();
let remote_db = RemoteDatabase::default();
Self {
temp_dir,
owml_dir,
config,
local_db,
remote_db,
}
}
pub fn join_mods_folder(&self, path: &str) -> PathBuf {
self.owml_dir.join("Mods").join(path)
}
pub fn get_test_path(&self, unique_name: &str) -> PathBuf {
if let Some(local_mod) = self.local_db.get_mod(unique_name) {
PathBuf::from(&local_mod.mod_path)
} else {
self.owml_dir.join("Mods").join(unique_name)
}
}
pub fn fetch_local_db(&mut self) {
self.local_db = LocalDatabase::fetch(&self.config.owml_path).unwrap();
}
pub async fn fetch_remote_db(&mut self) {
self.remote_db = RemoteDatabase::fetch(&self.config.database_url)
.await
.unwrap();
}
pub fn insert_test_mod(&mut self, local_mod: &LocalMod) {
self.local_db.mods.insert(
local_mod.manifest.unique_name.clone(),
UnsafeLocalMod::Valid(Box::new(local_mod.clone())),
);
}
pub fn install_test_zip(&mut self, zip_name: &str, refresh: bool) -> LocalMod {
let zip_path = get_test_file(zip_name);
let local_mod = install_mod_from_zip(&zip_path, &self.config, &self.local_db).unwrap();
if refresh {
self.fetch_local_db();
}
local_mod
}
}
}