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
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_variables)]
#[macro_use]
extern crate typescriptify_derive;
extern crate typescriptify;
#[macro_use]
pub extern crate derive_builder;
pub extern crate lmdb;
pub extern crate serde;
pub extern crate serde_json;
pub extern crate serde_yaml;
pub extern crate byteorder;
pub extern crate suffix_rs;
pub extern crate bincode;
#[macro_use]
pub extern crate serde_derive;
#[macro_use]
pub extern crate quick_error;
pub mod left_threaded_avl_tree;
pub mod datastore;
pub mod rustix_backend;
pub mod persistencer;
pub mod rustix_event_shop;
pub mod errors;
pub mod config;
use std::collections::HashSet;
use config::StaticConfig;
pub fn build_transient_backend() -> rustix_backend::RustixBackend
{
return build_transient_backend_with(20, 20);
}
pub fn build_transient_backend_with(
users_per_page: u8,
top_users: u8,
) -> rustix_backend::RustixBackend {
let mut config = StaticConfig::default();
config.users_per_page = users_per_page as usize;
config.users_in_top_users = top_users as usize;
config.top_drinks_per_user = 4;
return rustix_backend::RustixBackend {
datastore: datastore::Datastore::default(),
persistencer: persistencer::FilePersister::new(config).unwrap(),
};
}
pub fn build_persistent_backend(dir: &std::path::Path) -> rustix_backend::RustixBackend {
let mut config = StaticConfig::default_persistence(dir.to_str().unwrap());
return rustix_backend::RustixBackend {
datastore: datastore::Datastore::default(),
persistencer: persistencer::FilePersister::new(config).unwrap(),
};
}
#[cfg(test)]
mod tests {
extern crate tempdir;
use rustix_backend::WriteBackend;
use super::*;
#[test]
fn it_add_user() {
let dir = tempdir::TempDir::new("temptestdir").unwrap();
let mut backend = build_persistent_backend(dir.as_ref());
println!("{:?}", backend);
{
backend.create_user("klaus".to_string());
assert_eq!(
backend.datastore.users.get(&0u32).unwrap().username,
"klaus".to_string()
);
}
}
#[test]
fn it_transient_add_user() {
let mut b = build_transient_backend();
b.create_user("klaus".to_string());
assert_eq!(
b.datastore.users.get(&0u32).unwrap().username,
"klaus".to_string()
);
}
}