From 9db03d161faf0bc328e620c110afb68d48e6d68c Mon Sep 17 00:00:00 2001 From: Valeryi Savich Date: Fri, 25 Jun 2021 10:55:40 +0200 Subject: [PATCH] Added Ignitions test for read and write --- src/bastion/src/system/global_state.rs | 38 +++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) 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();