rustix_bl/
lib.rs

1// An attribute to hide warnings for unused code.
2#![allow(dead_code)]
3#![allow(unused_imports)]
4#![allow(unused_variables)]
5
6#[macro_use]
7extern crate typescriptify_derive;
8extern crate typescriptify;
9
10#[macro_use]
11pub extern crate derive_builder;
12pub extern crate lmdb;
13
14pub extern crate serde;
15pub extern crate serde_json;
16pub extern crate serde_yaml;
17
18pub extern crate byteorder;
19
20
21pub extern crate suffix_rs;
22
23pub extern crate bincode;
24#[macro_use]
25pub extern crate serde_derive;
26
27#[macro_use]
28pub extern crate quick_error;
29
30
31pub mod left_threaded_avl_tree;
32pub mod datastore;
33
34pub mod rustix_backend;
35
36pub mod persistencer;
37
38pub mod rustix_event_shop;
39
40pub mod errors;
41
42pub mod config;
43
44
45use std::collections::HashSet;
46use config::StaticConfig;
47
48pub fn build_transient_backend() -> rustix_backend::RustixBackend
49{
50    return build_transient_backend_with(20, 20);
51}
52
53pub fn build_transient_backend_with(
54    users_per_page: u8,
55    top_users: u8,
56) -> rustix_backend::RustixBackend {
57    let mut config = StaticConfig::default();
58    config.users_per_page = users_per_page as usize;
59    config.users_in_top_users = top_users as usize;
60    config.top_drinks_per_user = 4;
61
62    return rustix_backend::RustixBackend {
63        datastore: datastore::Datastore::default(),
64        persistencer: persistencer::FilePersister::new(config).unwrap(),
65    };
66}
67
68pub fn build_persistent_backend(dir: &std::path::Path) -> rustix_backend::RustixBackend {
69    let mut config = StaticConfig::default_persistence(dir.to_str().unwrap());
70
71    return rustix_backend::RustixBackend {
72        datastore: datastore::Datastore::default(),
73        persistencer: persistencer::FilePersister::new(config).unwrap(),
74    };
75}
76
77
78#[cfg(test)]
79mod tests {
80
81
82    extern crate tempdir;
83
84    use rustix_backend::WriteBackend;
85
86    use super::*;
87
88
89    #[test]
90    fn it_add_user() {
91        let dir = tempdir::TempDir::new("temptestdir").unwrap();
92
93        let mut backend = build_persistent_backend(dir.as_ref());
94
95        println!("{:?}", backend);
96 {
97                backend.create_user("klaus".to_string());
98                assert_eq!(
99                    backend.datastore.users.get(&0u32).unwrap().username,
100                    "klaus".to_string()
101                );
102            }
103
104    }
105
106
107    #[test]
108    fn it_transient_add_user() {
109        let mut b = build_transient_backend();
110        b.create_user("klaus".to_string());
111        assert_eq!(
112            b.datastore.users.get(&0u32).unwrap().username,
113            "klaus".to_string()
114        );
115    }
116
117
118}