diff --git a/src/bastion/src/system/global_state.rs b/src/bastion/src/system/global_state.rs index fd265922..f2f7f4c8 100644 --- a/src/bastion/src/system/global_state.rs +++ b/src/bastion/src/system/global_state.rs @@ -15,7 +15,6 @@ use std::borrow::Borrow; #[derive(Debug)] pub struct GlobalState { - //table: LOTable, table: LOTable>>>, } @@ -106,6 +105,43 @@ mod tests { assert_eq!(instance.contains::(), true); } + #[test] + fn test_read_and_write() { + let mut instance = GlobalState::new(); + + #[derive(Debug, PartialEq, Clone)] + struct Hello { + foo: bool, + bar: usize, + } + + let expected = Hello { foo: true, bar: 42 }; + + instance.insert(expected.clone()); + + instance.read(|actual: &Hello| { + assert_eq!(&expected, actual); + }); + + let expected_updated = Hello { + foo: false, + bar: 43, + }; + + instance.write::(|to_update| { + let updated = Hello { + foo: !to_update.foo, + bar: to_update.bar + 1, + }; + + updated + }); + + instance.read(|updated: &Hello| { + assert_eq!(updated, &expected_updated); + }); + } + #[test] fn test_contains_returns_true() { let mut instance = GlobalState::new();