pub struct TestHarness {
pub node: Node,
pub events: EventStream,
pub daemon: MockDaemon,
}Expand description
A node, its event stream, and the daemon it is talking to.
Fields§
§node: NodeThe node under test.
events: EventStreamIts event stream.
daemon: MockDaemonThe daemon on the other end.
Implementations§
Source§impl TestHarness
impl TestHarness
Sourcepub const DEFAULT_NODE: &'static str = "node-under-test"
pub const DEFAULT_NODE: &'static str = "node-under-test"
The node id TestHarness::start uses.
Sourcepub const DEFAULT_INPUT: &'static str = "in"
pub const DEFAULT_INPUT: &'static str = "in"
The input TestHarness::start declares.
Sourcepub const DEFAULT_OUTPUT: &'static str = "out"
pub const DEFAULT_OUTPUT: &'static str = "out"
The output TestHarness::start declares.
Sourcepub fn start() -> Result<Self>
pub fn start() -> Result<Self>
Starts a daemon and one node with a single input and output.
§Errors
NodeError::Testing when the harness cannot be started.
Sourcepub fn with_spec(spec: NodeSpawnSpec) -> Result<Self>
pub fn with_spec(spec: NodeSpawnSpec) -> Result<Self>
Sourcepub fn pair(
producer: &str,
output: &str,
consumer: &str,
input: &str,
) -> Result<(Self, Self)>
pub fn pair( producer: &str, output: &str, consumer: &str, input: &str, ) -> Result<(Self, Self)>
Starts a daemon with a producer and a consumer wired to each other.
producer publishes on output; consumer reads it as input. The
returned pair is (producer, consumer).
§Errors
Sourcepub fn default_spec(daemon: &MockDaemon) -> Result<NodeSpawnSpec>
pub fn default_spec(daemon: &MockDaemon) -> Result<NodeSpawnSpec>
The default specification: one input, one output, both wired to a notional peer.
§Errors
NodeError::Id when the built-in names fail the grammar, which they
cannot.
Sourcepub fn feed_input(&self, input: &str, payload: Vec<u8>) -> Result<()>
pub fn feed_input(&self, input: &str, payload: Vec<u8>) -> Result<()>
Delivers one message to a named input.
§Errors
NodeError::Id for a malformed name, plus whatever
MockDaemon::send_input reports.
Sourcepub fn next_event(&mut self) -> Result<Event>
pub fn next_event(&mut self) -> Result<Event>
Reads the next event, failing rather than hanging.
§Errors
NodeError::Timeout when nothing arrives in DEFAULT_WAIT, and
NodeError::Stopped when the stream has ended.