Skip to content

Commit

Permalink
Added Ignitions test for read and write
Browse files Browse the repository at this point in the history
  • Loading branch information
Relrin committed Jun 25, 2021
1 parent 627646b commit 9db03d1
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/bastion/src/system/global_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use std::borrow::Borrow;

#[derive(Debug)]
pub struct GlobalState {
//table: LOTable<TypeId, GlobalDataContainer>,
table: LOTable<TypeId, Arc<AtomicBox<Box<dyn Any + Send + Sync>>>>,
}

Expand Down Expand Up @@ -106,6 +105,43 @@ mod tests {
assert_eq!(instance.contains::<TestData>(), 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::<Hello, _>(|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();
Expand Down

0 comments on commit 9db03d1

Please sign in to comment.