1
0
Fork 0
mirror of https://codeberg.org/demostf/sync.git synced 2026-06-03 08:34:08 +02:00

mocks are only for tests

This commit is contained in:
Robin Appelman 2019-06-14 16:13:14 +02:00
commit 8880c6b62c

View file

@ -1,8 +1,5 @@
use crate::SyncCommand;
use enum_dispatch::enum_dispatch;
use mio::Token;
use std::cell::RefCell;
use std::rc::Rc;
use ws::{Result, Sender};
#[enum_dispatch(Client)]
@ -31,6 +28,15 @@ impl From<Sender> for SenderClient {
}
}
#[cfg(test)]
mod mock {
use crate::client::ClientTrait;
use crate::SyncCommand;
use mio::Token;
use std::cell::RefCell;
use std::rc::Rc;
use ws::Result;
#[derive(Clone, Debug)]
pub(crate) struct MockClient {
received: Rc<RefCell<Vec<String>>>,
@ -73,7 +79,19 @@ impl MockClient {
self.received.borrow_mut().clear()
}
}
}
#[cfg(test)]
pub(crate) use mock::MockClient;
#[cfg(not(test))]
#[enum_dispatch]
#[derive(PartialEq, Clone, Debug)]
pub(crate) enum Client {
Sender(SenderClient),
}
#[cfg(test)]
#[enum_dispatch]
#[derive(PartialEq, Clone, Debug)]
pub(crate) enum Client {
@ -81,6 +99,7 @@ pub(crate) enum Client {
Mock(MockClient),
}
#[cfg(test)]
impl Client {
pub fn mock(token: usize) -> Self {
Client::Mock(MockClient::new(token))