Logs in testsPush log lines with a MockBox

push_log on a MockBox sends a LOG frame that arrives on logs() like a real one.

EXAMPLE
use medius::{Device, LogLevel, MockBox};
use std::time::Duration;

#[test]
fn logs_reach_the_stream() {
    let mock = MockBox::new();
    let device = Device::with_mock(mock.clone());
    let stream = device.logs();

    mock.push_log(LogLevel::Warn, "overheating");

    let line = stream.recv_timeout(Duration::from_secs(1)).unwrap();
    assert_eq!(line.level, LogLevel::Warn);
    assert_eq!(line.text, "overheating");
}

Testing async codeMockBox behind an AsyncDevice

Mock an AsyncDevice with Device::with_mock then into_async. block_on drives the futures with no async runtime. A silent box never replies, so a query resolves to Err(Error::QueryTimeout).

EXAMPLE
use futures::executor::block_on;
use medius::{Device, Error, MockBox, Version};

let mock = MockBox::new().with_version(Version {
    proto_ver: 9, fw_major: 1, fw_minor: 2, fw_patch: 3, mac: [0; 6], name: "Loki".into(),
});
let device = Device::with_mock(mock).into_async();
let v = block_on(device.query_version())?;
assert_eq!((v.fw_major, v.fw_minor, v.fw_patch), (1, 2, 3));

// a silent box times out:
let device = Device::with_mock(MockBox::new().silent()).into_async();
assert!(matches!(block_on(device.query_version()).unwrap_err(), Error::QueryTimeout));