summaryrefslogtreecommitdiff
path: root/tests/db.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/db.rs')
-rw-r--r--tests/db.rs249
1 files changed, 0 insertions, 249 deletions
diff --git a/tests/db.rs b/tests/db.rs
deleted file mode 100644
index 992899f..0000000
--- a/tests/db.rs
+++ /dev/null
@@ -1,249 +0,0 @@
1use std::{fs::{File, create_dir_all, remove_dir_all}, path::Path, sync::Once};
2
3use modlist::{config::{Cfg, Apis}, db::{mods_insert, db_setup, mods_get_all_ids, mods_get_id, mods_remove, userlist_insert, lists_insert, userlist_get_all_ids, userlist_remove, mods_get_versions, userlist_get_applicable_versions, lists_remove, lists_get, lists_get_all_ids, userlist_get_all_current_version_ids, userlist_change_versions, s_userlist_update_download, userlist_get_all_downloads, config_change_current_list, config_get_current_list, s_config_update_version, s_config_create_version, s_config_get_version}, Modloader, List};
4
5static INIT: Once = Once::new();
6
7fn setup() -> Cfg {
8 let db_pathstr = "./test_tmp/db";
9
10 let config = Cfg { data: String::from(db_pathstr), apis: Apis { modrinth: String::from("-") } };
11
12 INIT.call_once(|| {
13 let db_path = Path::new(db_pathstr);
14 if db_path.exists() { remove_dir_all(db_pathstr).unwrap(); };
15 create_dir_all(db_path).unwrap();
16 let db_filestr = format!("{}/data.db", db_pathstr);
17 File::create(db_filestr).unwrap();
18 println!("INIT TEST DB");
19 db_setup(config.clone()).unwrap();
20 });
21 config
22}
23
24#[test]
25fn test_mods_insert() {
26 let config = setup();
27
28 mods_insert(config.clone(), String::from("I"), String::from("INSERT_TEST"), vec![String::from("INSERT_VER1"), String::from("INSERT_VER2")]).unwrap();
29 let ids = mods_get_all_ids(config).unwrap();
30
31 assert!(ids.contains(&String::from("I")));
32}
33
34#[test]
35fn test_mods_get_all_ids() {
36 let config = setup();
37
38 mods_insert(config.clone(), String::from("GAI1"), String::from("GETALLIDS_TEST1"), vec![String::from("GAI1_VER1"), String::from("GAI1_VER2")]).unwrap();
39 mods_insert(config.clone(), String::from("GAI2"), String::from("GETALLIDS_TEST2"), vec![String::from("GAI2_VER1"), String::from("GAI2_VER2")]).unwrap();
40 let ids = mods_get_all_ids(config).unwrap();
41
42 assert!(ids.contains(&String::from("GAI1")));
43 assert!(ids.contains(&String::from("GAI2")));
44}
45
46#[test]
47fn test_mods_get_id() {
48 let config = setup();
49
50 mods_insert(config, String::from("GI"), String::from("GETID_TEST"), vec![String::from("GI_VER1"), String::from("GI_VER2")]).unwrap();
51}
52
53#[test]
54fn test_mods_remove() {
55 let config = setup();
56
57 mods_insert(config.clone(), String::from("R"), String::from("REMOVE_TEST"), vec![String::from("R_VER1"), String::from("R_VER2")]).unwrap();
58 let ids = mods_get_all_ids(config.clone()).unwrap();
59 assert!(ids.contains(&String::from("R")));
60 mods_remove(config.clone(), String::from("R")).unwrap();
61 assert!(mods_get_id(config, String::from("REMOVE_TEST")).is_err());
62}
63
64#[test]
65fn test_mods_get_versions() {
66 let config = setup();
67
68 mods_insert(config.clone(), String::from("M_GVs1"), String::from("M_GVs_TEST1"), vec![String::from("M_GVs1_VER1"), String::from("M_GVs1_VER2")]).unwrap();
69 mods_insert(config.clone(), String::from("M_GVs2"), String::from("M_GVs_TEST2"), vec![String::from("M_GVs2_VER1"), String::from("M_GVs2_VER2")]).unwrap();
70 let versions = mods_get_versions(config, vec![String::from("M_GVs1"), String::from("M_GVs2")]).unwrap();
71
72 assert!(versions.contains(&modlist::db::DBModlistVersions { mod_id: String::from("M_GVs1"), versions: String::from("M_GVs1_VER1|M_GVs1_VER2") }));
73 assert!(versions.contains(&modlist::db::DBModlistVersions { mod_id: String::from("M_GVs2"), versions: String::from("M_GVs2_VER1|M_GVs2_VER2") }));
74}
75
76//user_list
77#[test]
78fn test_userlist_insert() {
79 let config = setup();
80
81 lists_insert(config.clone(), String::from("UL_I_LIST"), String::from("UL_I_MC"), Modloader::Fabric, String::from("UL_I_FOLDER")).unwrap();
82 userlist_insert(config, String::from("UL_I_LIST"), String::from("UL_I"), String::from("UL_I_VER1"), vec![String::from("UL_I_VER1"), String::from("UL_I_VER2")], String::from("localhost:8080/dl/UL_I_VER1.test")).unwrap();
83}
84
85#[test]
86fn test_userlist_get_all_ids() {
87 let config = setup();
88
89 lists_insert(config.clone(), String::from("UL_GAI_LIST"), String::from("UL_GAI_MC"), Modloader::Fabric, String::from("UL_GAI_FOLDER")).unwrap();
90 userlist_insert(config.clone(), String::from("UL_GAI_LIST"), String::from("UL_GAI1"), String::from("UL_GAI1_VER1"), vec![String::from("UL_GAI2_VER1"), String::from("UL_GAI1_VER2")], String::from("localhost:8080/dl/UL_GAI1_VER1.test")).unwrap();
91 userlist_insert(config.clone(), String::from("UL_GAI_LIST"), String::from("UL_GAI2"), String::from("UL_GAI2_VER1"), vec![String::from("UL_GAI2_VER1"), String::from("UL_GAI2_VER2")], String::from("localhost:8080/dl/UL_GAI2_VER1.test")).unwrap();
92 let ids = userlist_get_all_ids(config, String::from("UL_GAI_LIST")).unwrap();
93
94 assert!(ids.contains(&String::from("UL_GAI1")));
95 assert!(ids.contains(&String::from("UL_GAI2")));
96}
97
98#[test]
99fn test_userlist_remove() {
100 let config = setup();
101
102 lists_insert(config.clone(), String::from("UL_R_LIST"), String::from("UL_R_MC"), Modloader::Fabric, String::from("UL_R_FOLDER")).unwrap();
103 userlist_insert(config.clone(), String::from("UL_R_LIST"), String::from("UL_R"), String::from("UL_R_VER1"), vec![String::from("UL_R_VER1"), String::from("UL_R_VER2")], String::from("localhost:8080/dl/UL_R_VER1.test")).unwrap();
104 let ids = userlist_get_all_ids(config.clone(), String::from("UL_R_LIST")).unwrap();
105 assert!(ids.contains(&String::from("UL_R")));
106 userlist_remove(config.clone(), String::from("UL_R_LIST"), String::from("UL_R")).unwrap();
107 assert!(userlist_get_all_ids(config, String::from("UL_R_LIST")).is_err())
108}
109
110#[test]
111fn test_userlist_get_applicable_versions() {
112 let config = setup();
113
114 lists_insert(config.clone(), String::from("UL_GAV_LIST"), String::from("UL_GAV_MC"), Modloader::Fabric, String::from("UL_GAV_FOLDER")).unwrap();
115 userlist_insert(config.clone(), String::from("UL_GAV_LIST"), String::from("UL_GAV"), String::from("UL_GAV_VER1"), vec![String::from("UL_GAV_VER1"), String::from("UL_GAV_VER2")], String::from("localhost:8080/dl/UL_GAV_VER1.test")).unwrap();
116 assert_eq!(userlist_get_applicable_versions(config, String::from("UL_GAV_LIST"), String::from("UL_GAV")).unwrap(), String::from("UL_GAV_VER1|UL_GAV_VER2"));
117}
118
119#[test]
120fn test_userlist_get_all_current_version_ids() {
121 let config = setup();
122
123 lists_insert(config.clone(), String::from("UL_GACVI_LIST"), String::from("UL_GACVI_MC"), Modloader::Fabric, String::from("UL_GACVI_FOLDER")).unwrap();
124 userlist_insert(config.clone(), String::from("UL_GACVI_LIST"), String::from("UL_GACVI1"), String::from("UL_GACVI1_VER1"), vec![String::from("UL_GACVI2_VER1"), String::from("UL_GACVI1_VER2")], String::from("localhost:8080/dl/UL_GACVI1_VER1.test")).unwrap();
125 userlist_insert(config.clone(), String::from("UL_GACVI_LIST"), String::from("UL_GACVI2"), String::from("UL_GACVI2_VER1"), vec![String::from("UL_GACVI2_VER1"), String::from("UL_GACVI2_VER2")], String::from("localhost:8080/dl/UL_GACVI2_VER1.test")).unwrap();
126
127 let ids = userlist_get_all_current_version_ids(config, String::from("UL_GACVI_LIST")).unwrap();
128
129 assert!(ids.contains(&String::from("UL_GACVI1_VER1")));
130 assert!(ids.contains(&String::from("UL_GACVI2_VER1")));
131}
132
133#[test]
134fn test_userlist_change_versions() {
135 let config = setup();
136
137 lists_insert(config.clone(), String::from("UL_CV_LIST"), String::from("UL_CV_MC"), Modloader::Fabric, String::from("UL_CV_FOLDER")).unwrap();
138 userlist_insert(config.clone(), String::from("UL_CV_LIST"), String::from("UL_CV"), String::from("UL_CV_VER1"), vec![String::from("UL_CV_VER1"), String::from("UL_CV_VER2")], String::from("localhost:8080/dl/UL_CV_VER1.test")).unwrap();
139 let versions = userlist_get_all_current_version_ids(config.clone(), String::from("UL_CV_LIST")).unwrap();
140 assert!(versions.contains(&String::from("UL_CV_VER1")));
141
142 userlist_change_versions(config.clone(), String::from("UL_CV_LIST"), String::from("UL_CV_VER3"), String::from("UL_CV_VER1|UL_CV_VER2|UL_CV_VER3"), String::from("localhost:8080/dl/UL_CV_VER3.test"), String::from("UL_CV")).unwrap();
143 let versions = userlist_get_all_current_version_ids(config, String::from("UL_CV_LIST")).unwrap();
144 assert!(!versions.contains(&String::from("UL_CV_VER1")));
145 assert!(versions.contains(&String::from("UL_CV_VER3")));
146}
147
148#[test]
149fn test_userlist_get_all_downloads() {
150 let config = setup();
151
152 lists_insert(config.clone(), String::from("UL_GAD_LIST"), String::from("UL_GAD_MC"), Modloader::Fabric, String::from("UL_GAD_FOLDER")).unwrap();
153 userlist_insert(config.clone(), String::from("UL_GAD_LIST"), String::from("UL_GAD1"), String::from("UL_GAD1_VER1"), vec![String::from("UL_GAD1_VER1"), String::from("UL_GAD1_VER1")], String::from("localhost:8080/dl/UL_GAD1_VER1.test")).unwrap();
154 userlist_insert(config.clone(), String::from("UL_GAD_LIST"), String::from("UL_GAD2"), String::from("UL_GAD2_VER1"), vec![String::from("UL_GAD2_VER1"), String::from("UL_GAD2_VER1")], String::from("localhost:8080/dl/UL_GAD2_VER1.test")).unwrap();
155 let links = userlist_get_all_downloads(config, String::from("UL_GAD_LIST")).unwrap();
156
157 assert!(links.contains(&String::from("localhost:8080/dl/UL_GAD1_VER1.test")));
158 assert!(links.contains(&String::from("localhost:8080/dl/UL_GAD2_VER1.test")));
159}
160
161
162//lists
163#[test]
164fn test_lists_insert() {
165 let config = setup();
166
167 lists_insert(config, String::from("L_I_LIST"), String::from("L_I_MC"), Modloader::Fabric, String::from("L_I_FOLDER")).unwrap();
168}
169
170#[test]
171fn test_lists_remove() {
172 let config = setup();
173
174 lists_insert(config.clone(), String::from("L_R_LIST"), String::from("L_R_MC"), Modloader::Fabric, String::from("L_R_FOLDER")).unwrap();
175 lists_remove(config, String::from("L_R_LIST")).unwrap();
176}
177
178#[test]
179fn test_lists_get() {
180 let config = setup();
181
182 lists_insert(config.clone(), String::from("L_G_LIST"), String::from("L_G_MC"), Modloader::Fabric, String::from("L_G_FOLDER")).unwrap();
183
184 assert_eq!(lists_get(config, String::from("L_G_LIST")).unwrap(), List { id: String::from("L_G_LIST"), mc_version: String::from("L_G_MC"), modloader: Modloader::Fabric, download_folder: String::from("L_G_FOLDER") });
185}
186
187#[test]
188fn test_lists_get_all_ids() {
189 let config = setup();
190
191 lists_insert(config.clone(), String::from("L_GAI1_LIST"), String::from("L_GAI1_MC"), Modloader::Fabric, String::from("L_GAI1_FOLDER")).unwrap();
192 lists_insert(config.clone(), String::from("L_GAI2_LIST"), String::from("L_GAI2_MC"), Modloader::Fabric, String::from("L_GAI2_FOLDER")).unwrap();
193 let ids = lists_get_all_ids(config).unwrap();
194
195 assert!(ids.contains(&String::from("L_GAI1_LIST")));
196 assert!(ids.contains(&String::from("L_GAI2_LIST")));
197}
198
199//config
200#[test]
201fn test_config_change_current_list() {
202 let config = setup();
203
204 config_change_current_list(config, String::from("C_CCL_LIST")).unwrap();
205}
206
207#[test]
208fn test_config_get_current_list() {
209 let config = setup();
210
211 config_change_current_list(config.clone(), String::from("C_GCL_LIST")).unwrap();
212 assert_eq!(config_get_current_list(config).unwrap(), String::from("C_GCL_LIST"));
213}
214
215//setup
216#[test]
217fn test_s_userlist_update_download() {
218 let config = setup();
219
220 lists_insert(config.clone(), String::from("UL_UD_LIST"), String::from("UL_UD_MC"), Modloader::Fabric, String::from("UL_UD_FOLDER")).unwrap();
221 userlist_insert(config.clone(), String::from("UL_UD_LIST"), String::from("UL_UD"), String::from("UL_UD_VER1"), vec![String::from("UL_UD_VER1"), String::from("UL_UD_VER1")], String::from("localhost:8080/dl/UL_UD_VER1.test")).unwrap();
222 s_userlist_update_download(config.clone(), String::from("UL_UD_LIST"), String::from("UL_UD"), String::from("localhost:8080/dl/UL_UD_VER1X.test")).unwrap();
223 let links = userlist_get_all_downloads(config, String::from("UL_UD_LIST")).unwrap();
224
225 assert!(links.contains(&String::from("localhost:8080/dl/UL_UD_VER1X.test")));
226 assert!(!links.contains(&String::from("localhost:8080/dl/UL_UD_VER1.test")));
227}
228
229#[test]
230fn test_s_config_create_version() {
231 let config = setup();
232
233 s_config_create_version(config).unwrap();
234}
235
236#[test]
237fn test_s_config_update_version() {
238 let config = setup();
239
240 s_config_update_version(config, String::from("S_C_UV")).unwrap();
241}
242
243#[test]
244fn test_s_config_get_version() {
245 let config = setup();
246
247 s_config_update_version(config.clone(), String::from("S_C_GV")).unwrap();
248 assert_eq!(s_config_get_version(config).unwrap(), String::from("S_C_GV"));
249}