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:
parent
cc4420241f
commit
8880c6b62c
1 changed files with 53 additions and 34 deletions
|
|
@ -1,8 +1,5 @@
|
||||||
use crate::SyncCommand;
|
|
||||||
use enum_dispatch::enum_dispatch;
|
use enum_dispatch::enum_dispatch;
|
||||||
use mio::Token;
|
use mio::Token;
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::rc::Rc;
|
|
||||||
use ws::{Result, Sender};
|
use ws::{Result, Sender};
|
||||||
|
|
||||||
#[enum_dispatch(Client)]
|
#[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)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) struct MockClient {
|
pub(crate) struct MockClient {
|
||||||
received: Rc<RefCell<Vec<String>>>,
|
received: Rc<RefCell<Vec<String>>>,
|
||||||
|
|
@ -73,7 +79,19 @@ impl MockClient {
|
||||||
self.received.borrow_mut().clear()
|
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]
|
#[enum_dispatch]
|
||||||
#[derive(PartialEq, Clone, Debug)]
|
#[derive(PartialEq, Clone, Debug)]
|
||||||
pub(crate) enum Client {
|
pub(crate) enum Client {
|
||||||
|
|
@ -81,6 +99,7 @@ pub(crate) enum Client {
|
||||||
Mock(MockClient),
|
Mock(MockClient),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
impl Client {
|
impl Client {
|
||||||
pub fn mock(token: usize) -> Self {
|
pub fn mock(token: usize) -> Self {
|
||||||
Client::Mock(MockClient::new(token))
|
Client::Mock(MockClient::new(token))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue