1#![doc = include_str!("../README.md")]
2#![doc(
3 html_logo_url = "https://github.com/ow-mods/ow-mod-man/blob/main/.github/assets/logo-core.png?raw=true"
4)]
5#![warn(missing_docs)]
6
7pub mod alerts;
9
10pub mod analytics;
12
13pub mod config;
15
16pub mod constants;
18
19pub mod db;
21
22pub mod download;
24
25pub mod file;
27
28pub mod game;
30
31pub mod io;
33
34pub mod mods;
36
37pub mod owml;
39
40pub mod open;
42
43pub mod progress;
45
46pub mod remove;
48
49pub mod socket;
51
52pub mod toggle;
54
55pub mod updates;
57
58pub mod validate;
60
61pub mod search;
63
64pub mod protocol;
66
67#[cfg(test)]
69pub(crate) mod test_utils {
70 use std::path::{Path, PathBuf};
71
72 use tempfile::TempDir;
73
74 use crate::{
75 config::Config,
76 db::{LocalDatabase, RemoteDatabase},
77 download::install_mod_from_zip,
78 mods::local::{LocalMod, UnsafeLocalMod},
79 };
80
81 pub struct TestContext {
83 pub temp_dir: TempDir,
85 pub owml_dir: PathBuf,
87 pub config: Config,
89 pub local_db: LocalDatabase,
91 pub remote_db: RemoteDatabase,
93 }
94
95 pub fn make_test_dir() -> TempDir {
97 TempDir::new().unwrap()
98 }
99
100 pub fn get_test_file(path: &str) -> PathBuf {
102 Path::new(env!("CARGO_MANIFEST_DIR"))
103 .join("test_files")
104 .join(path)
105 }
106
107 impl TestContext {
108 pub fn new() -> Self {
115 let temp_dir = make_test_dir();
116 let owml_dir = temp_dir.path().join("OWML");
117 let mut config = Config::default(Some(temp_dir.path().join("settings.json"))).unwrap();
118 config.owml_path = owml_dir.to_str().unwrap().to_string();
119 let local_db = LocalDatabase::default();
120 let remote_db = RemoteDatabase::default();
121 Self {
122 temp_dir,
123 owml_dir,
124 config,
125 local_db,
126 remote_db,
127 }
128 }
129
130 pub fn join_mods_folder(&self, path: &str) -> PathBuf {
132 self.owml_dir.join("Mods").join(path)
133 }
134
135 pub fn get_test_path(&self, unique_name: &str) -> PathBuf {
137 if let Some(local_mod) = self.local_db.get_mod(unique_name) {
138 PathBuf::from(&local_mod.mod_path)
139 } else {
140 self.owml_dir.join("Mods").join(unique_name)
141 }
142 }
143
144 pub fn fetch_local_db(&mut self) {
146 self.local_db = LocalDatabase::fetch(&self.config.owml_path).unwrap();
147 }
148
149 pub async fn fetch_remote_db(&mut self) {
151 self.remote_db = RemoteDatabase::fetch(&self.config.database_url)
152 .await
153 .unwrap();
154 }
155
156 pub fn insert_test_mod(&mut self, local_mod: &LocalMod) {
158 self.local_db.mods.insert(
159 local_mod.manifest.unique_name.clone(),
160 UnsafeLocalMod::Valid(Box::new(local_mod.clone())),
161 );
162 }
163
164 pub fn install_test_zip(&mut self, zip_name: &str, refresh: bool) -> LocalMod {
166 let zip_path = get_test_file(zip_name);
167 let local_mod = install_mod_from_zip(&zip_path, &self.config, &self.local_db).unwrap();
168 if refresh {
169 self.fetch_local_db();
170 }
171 local_mod
172 }
173 }
174}