xref: /tonic/tests/integration_tests/src/lib.rs (revision a562a3ce)
1 pub mod pb {
2     tonic::include_proto!("test");
3     tonic::include_proto!("stream");
4 }
5 
6 pub mod mock {
7     use std::{
8         pin::Pin,
9         task::{Context, Poll},
10     };
11 
12     use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
13     use tonic::transport::server::Connected;
14 
15     #[derive(Debug)]
16     pub struct MockStream(pub tokio::io::DuplexStream);
17 
18     impl Connected for MockStream {
19         type ConnectInfo = ();
20 
21         /// Create type holding information about the connection.
22         fn connect_info(&self) -> Self::ConnectInfo {}
23     }
24 
25     impl AsyncRead for MockStream {
26         fn poll_read(
27             mut self: Pin<&mut Self>,
28             cx: &mut Context<'_>,
29             buf: &mut ReadBuf<'_>,
30         ) -> Poll<std::io::Result<()>> {
31             Pin::new(&mut self.0).poll_read(cx, buf)
32         }
33     }
34 
35     impl AsyncWrite for MockStream {
36         fn poll_write(
37             mut self: Pin<&mut Self>,
38             cx: &mut Context<'_>,
39             buf: &[u8],
40         ) -> Poll<std::io::Result<usize>> {
41             Pin::new(&mut self.0).poll_write(cx, buf)
42         }
43 
44         fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
45             Pin::new(&mut self.0).poll_flush(cx)
46         }
47 
48         fn poll_shutdown(
49             mut self: Pin<&mut Self>,
50             cx: &mut Context<'_>,
51         ) -> Poll<std::io::Result<()>> {
52             Pin::new(&mut self.0).poll_shutdown(cx)
53         }
54     }
55 }
56