Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
wuan committed May 22, 2023
1 parent 610dbb6 commit 1818dea
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/dilation/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ impl ManagerMachine {
#[cfg(test)]
mod test {
use crate::core::{MySide, TheirSide};
use crate::transit::{DirectHint, RelayHint};

use super::*;

Expand All @@ -244,6 +245,10 @@ mod test {
self.command = Some(command);
Ok(())
}

fn reset(&mut self) {
self.command = None;
}
}

#[test]
Expand All @@ -270,8 +275,25 @@ mod test {
assert_eq!(
handler.command,
Some(ManagerCommand::Protocol(ProtocolCommand::SendPlease {
side: side,
side: side.clone(),
}))
)
);

let direct_hint = DirectHint::new("host", 123);
let relay_hint: RelayHint;
let hints = Hints::new(vec!(direct_hint), vec!());

handler.reset();
// generate an input Event and see if we get the desired state and output Actions
manager_fsm.process(
ManagerEvent::RxHints { hints },
&side,
&mut |cmd| handler.handle_command(cmd),
);

assert_eq!(manager_fsm.get_current_state(), Some(State::Connecting));
assert_eq!( handler.command, None );
assert_eq!(manager_fsm.their_hints.direct_tcp.len(), 1);
assert_eq!(manager_fsm.their_hints.relay.len(), 0);
}
}

0 comments on commit 1818dea

Please sign in to comment.