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
mod background_sync;
mod disk;
#[cfg(feature = "s3")]
mod s3;
pub use background_sync::*;
pub use disk::*;
#[cfg(feature = "s3")]
pub use s3::*;
#[cfg(test)]
pub mod tests {
use chrono::Utc;
use serde_json::json;
use feattle_core::persist::{CurrentValue, CurrentValues, HistoryEntry, Persist, ValueHistory};
pub async fn test_persistence<P: Persist>(persistence: P) {
assert_eq!(persistence.load_current().await.unwrap(), None);
assert_eq!(persistence.load_history("key").await.unwrap(), None);
let feattles = vec![(
"key".to_string(),
CurrentValue {
modified_at: Utc::now(),
modified_by: "someone".to_owned(),
value: json!(17i32),
},
)]
.into_iter()
.collect();
let current_values = CurrentValues {
version: 17,
date: Utc::now(),
feattles,
};
persistence.save_current(¤t_values).await.unwrap();
assert_eq!(
persistence.load_current().await.unwrap(),
Some(current_values)
);
let history = ValueHistory {
entries: vec![HistoryEntry {
value: json!(17i32),
value_overview: "overview".to_owned(),
modified_at: Utc::now(),
modified_by: "someone else".to_owned(),
}],
};
persistence.save_history("key", &history).await.unwrap();
assert_eq!(
persistence.load_history("key").await.unwrap(),
Some(history)
);
assert_eq!(persistence.load_history("key2").await.unwrap(), None);
}
}