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