-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathvoid.rs
59 lines (51 loc) · 1.32 KB
/
void.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use super::EventBus;
use crate::{Error, Event};
use async_trait::async_trait;
#[derive(Default)]
pub struct VoidBus;
impl VoidBus {
pub fn new() -> Self {
Self
}
}
#[async_trait]
impl EventBus for VoidBus {
type E = Event;
async fn send_event(&self, _: &Self::E) -> Result<(), Error> {
Err(Error::InternalError("send_event is not supported"))
}
async fn send_events(&self, _: &[Self::E]) -> Result<(), Error> {
Err(Error::InternalError("send_events is not supported"))
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::Product;
#[tokio::test]
async fn test_send_event() {
let bus = VoidBus;
let event = Event::Created {
product: Product {
id: "123".to_string(),
name: "test".to_string(),
price: 10.0,
},
};
let result = bus.send_event(&event).await;
assert!(result.is_err());
}
#[tokio::test]
async fn test_send_events() {
let bus = VoidBus;
let event = Event::Created {
product: Product {
id: "123".to_string(),
name: "test".to_string(),
price: 10.0,
},
};
let result = bus.send_events(&[event]).await;
assert!(result.is_err());
}
}