summaryrefslogtreecommitdiff
path: root/tests/db_integration.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2022-11-07 22:29:35 +0100
committerfxqnlr <[email protected]>2022-11-07 22:29:35 +0100
commit889dc4f87b05d838b25428478a8c42dac454a5cf (patch)
treec4b09ae53a74a7f0afc1e095a4b66a1b00e67244 /tests/db_integration.rs
parentea50af892c4268ae06f6df40ee435eadd076228d (diff)
downloadmodlist-889dc4f87b05d838b25428478a8c42dac454a5cf.tar
modlist-889dc4f87b05d838b25428478a8c42dac454a5cf.tar.gz
modlist-889dc4f87b05d838b25428478a8c42dac454a5cf.zip
finished rusqlite; added all db tests
Diffstat (limited to 'tests/db_integration.rs')
-rw-r--r--tests/db_integration.rs115
1 files changed, 0 insertions, 115 deletions
diff --git a/tests/db_integration.rs b/tests/db_integration.rs
deleted file mode 100644
index 8c3d194..0000000
--- a/tests/db_integration.rs
+++ /dev/null
@@ -1,115 +0,0 @@
1use std::{fs::{File, create_dir_all}, path::Path, sync::Once};
2
3use modlist::{config::{Cfg, Apis}, db::{mods_insert, db_setup, user_dbversion, mods_get_all_ids, mods_get_id, mods_remove, userlist_insert, lists_insert, userlist_get_all_ids, userlist_remove}, Modloader};
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), downloads: String::from("-"), clean_remove: false, apis: Apis { modrinth: String::from("-") } };
11
12 INIT.call_once(|| {
13 let db_path = Path::new(db_pathstr);
14 create_dir_all(db_path).unwrap();
15 let db_filestr = format!("{}/data.db", db_pathstr);
16 File::create(db_filestr).unwrap();
17 println!("INIT TEST DB");
18 db_setup(config.clone()).unwrap();
19 });
20 config
21}
22
23#[test]
24fn test_user_dbversion() {
25 let config = setup();
26
27 assert_eq!(user_dbversion(config).unwrap(), "0.2");
28}
29
30#[test]
31fn test_mods_insert() {
32 let config = setup();
33
34 mods_insert(config.clone(), String::from("I"), String::from("INSERT_TEST"), vec![String::from("INSERT_VER1"), String::from("INSERT_VER2")]).unwrap();
35 let ids = mods_get_all_ids(config).unwrap();
36
37 assert!(ids.contains(&String::from("I")));
38}
39
40#[test]
41fn test_mods_get_all_ids() {
42 let config = setup();
43
44 mods_insert(config.clone(), String::from("GAI1"), String::from("GETALLIDS_TEST1"), vec![String::from("GAI1_VER1"), String::from("GAI1_VER2")]).unwrap();
45 mods_insert(config.clone(), String::from("GAI2"), String::from("GETALLIDS_TEST2"), vec![String::from("GAI2_VER1"), String::from("GAI2_VER2")]).unwrap();
46 let ids = mods_get_all_ids(config).unwrap();
47
48 assert!(ids.contains(&String::from("GAI1")));
49 assert!(ids.contains(&String::from("GAI2")));
50}
51
52#[test]
53fn test_mods_get_id() {
54 let config = setup();
55
56 mods_insert(config.clone(), String::from("GI"), String::from("GETID_TEST"), vec![String::from("GI_VER1"), String::from("GI_VER2")]).unwrap();
57 let id = mods_get_id(config, String::from("GETID_TEST")).unwrap();
58
59 assert_eq!(id, String::from("GI"));
60}
61
62#[test]
63fn test_mods_remove() {
64 let config = setup();
65
66 mods_insert(config.clone(), String::from("R"), String::from("REMOVE_TEST"), vec![String::from("R_VER1"), String::from("R_VER2")]).unwrap();
67 let ids = mods_get_all_ids(config.clone()).unwrap();
68 assert!(ids.contains(&String::from("R")));
69 mods_remove(config.clone(), String::from("R")).unwrap();
70 assert!(mods_get_id(config, String::from("REMOVE_TEST")).is_err());
71}
72
73//user_list
74#[test]
75fn test_userlist_insert() {
76 let config = setup();
77
78 lists_insert(config.clone(), String::from("UL_I_LIST"), String::from("UL_I_MC"), Modloader::Fabric).unwrap();
79 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();
80 //let list = mods_get_all_ids(config).unwrap();
81
82 //assert!(ids.contains(&String::from("I")));
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).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).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//lists
110#[test]
111fn test_lists_insert() {
112 let config = setup();
113
114 lists_insert(config, String::from("TESTLIST"), String::from("L_I_LIST"), Modloader::Fabric).unwrap();
115}