Skip to content

Commit

Permalink
Add test for replaying OutputEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkydeveloper committed Aug 16, 2024
1 parent b04e89c commit a56aeb9
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions src/tests/input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ use crate::service_protocol::messages::{
use assert2::let_assert;
use test_log::test;

fn echo_handler(vm: &mut CoreVM) {
let_assert!(Input { input, .. } = vm.sys_input().unwrap());
assert_eq!(input, b"my-data".to_vec());

vm.sys_write_output(NonEmptyValue::Success(input)).unwrap();
vm.sys_end().unwrap();
}

#[test]
fn echo() {
let mut output = VMTestCase::new(Version::V1)
Expand All @@ -22,13 +30,7 @@ fn echo() {
value: Bytes::from_static(b"my-data"),
..InputEntryMessage::default()
})
.run(|vm| {
let_assert!(Input { input, .. } = vm.sys_input().unwrap());
assert_eq!(input, b"my-data".to_vec());

vm.sys_write_output(NonEmptyValue::Success(input)).unwrap();
vm.sys_end().unwrap();
});
.run(echo_handler);

assert_eq!(
output.next_decoded::<OutputEntryMessage>().unwrap(),
Expand Down Expand Up @@ -91,3 +93,34 @@ fn headers() {
);
assert_eq!(output.next(), None);
}

#[test]
fn replay_output_too() {
let mut output = VMTestCase::new(Version::V1)
.input(StartMessage {
id: Bytes::from_static(b"123"),
debug_id: "123".to_string(),
known_entries: 2,
state_map: vec![],
partial_state: false,
key: "".to_string(),
})
.input(InputEntryMessage {
headers: vec![],
value: Bytes::from_static(b"my-data"),
..InputEntryMessage::default()
})
.input(OutputEntryMessage {
result: Some(output_entry_message::Result::Value(Bytes::from_static(
b"my-data",
))),
..OutputEntryMessage::default()
})
.run(echo_handler);

assert_eq!(
output.next_decoded::<EndMessage>().unwrap(),
EndMessage::default()
);
assert_eq!(output.next(), None);
}

0 comments on commit a56aeb9

Please sign in to comment.