diff options
author | fxqnlr <[email protected]> | 2022-11-06 23:06:54 +0100 |
---|---|---|
committer | fxqnlr <[email protected]> | 2022-11-06 23:06:54 +0100 |
commit | ea50af892c4268ae06f6df40ee435eadd076228d (patch) | |
tree | dce2f1fed88f168552b8069d22d9176d7dd2879d /tests/db_integration.rs | |
parent | c33b8be79e8cfac9e2fa76c1f63c85e020cdf4a0 (diff) | |
download | modlist-ea50af892c4268ae06f6df40ee435eadd076228d.tar modlist-ea50af892c4268ae06f6df40ee435eadd076228d.tar.gz modlist-ea50af892c4268ae06f6df40ee435eadd076228d.zip |
halfswitch to rusqlite; db tests
Diffstat (limited to 'tests/db_integration.rs')
-rw-r--r-- | tests/db_integration.rs | 115 |
1 files changed, 112 insertions, 3 deletions
diff --git a/tests/db_integration.rs b/tests/db_integration.rs index f580595..8c3d194 100644 --- a/tests/db_integration.rs +++ b/tests/db_integration.rs | |||
@@ -1,6 +1,115 @@ | |||
1 | mod db; | 1 | use std::{fs::{File, create_dir_all}, path::Path, sync::Once}; |
2 | |||
3 | use 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 | |||
5 | static INIT: Once = Once::new(); | ||
6 | |||
7 | fn 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] | ||
24 | fn test_user_dbversion() { | ||
25 | let config = setup(); | ||
26 | |||
27 | assert_eq!(user_dbversion(config).unwrap(), "0.2"); | ||
28 | } | ||
29 | |||
30 | #[test] | ||
31 | fn 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] | ||
41 | fn 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] | ||
53 | fn 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] | ||
63 | fn 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] | ||
75 | fn 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] | ||
86 | fn 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 | } | ||
2 | 97 | ||
3 | #[test] | 98 | #[test] |
4 | fn test_add() { | 99 | fn test_userlist_remove() { |
5 | db::setup(); | 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] | ||
111 | fn test_lists_insert() { | ||
112 | let config = setup(); | ||
113 | |||
114 | lists_insert(config, String::from("TESTLIST"), String::from("L_I_LIST"), Modloader::Fabric).unwrap(); | ||
6 | } | 115 | } |