1use crate::codec::test::{from_wire_hello_world_response, to_wire_hello_world_request};
6use crate::generated::v1;
7use crate::rpc_support::GestaltError;
8
9#[derive(Clone, Debug, Default, PartialEq)]
14pub struct HelloWorldRequest {}
15
16#[derive(Clone, Debug, Default, PartialEq)]
20pub struct HelloWorldResponse {
21 pub message: String,
23}
24
25pub struct Test {
30 inner: v1::test_client::TestClient<tonic::transport::Channel>,
31 timeout: Option<std::time::Duration>,
32}
33
34impl Test {
35 pub fn new(channel: tonic::transport::Channel) -> Self {
37 Self {
38 inner: v1::test_client::TestClient::new(channel),
39 timeout: None,
40 }
41 }
42
43 pub fn with_timeout(mut self, timeout: std::time::Duration) -> Self {
46 self.timeout = Some(timeout);
47 self
48 }
49
50 pub async fn hello_world(
52 &mut self,
53 request: HelloWorldRequest,
54 ) -> Result<String, GestaltError> {
55 let mut tonic_request = tonic::Request::new(to_wire_hello_world_request(request));
56 if let Some(timeout) = self.timeout {
57 tonic_request.set_timeout(timeout);
58 }
59 let response = from_wire_hello_world_response(
60 self.inner.hello_world(tonic_request).await?.into_inner(),
61 );
62 Ok(response.message)
63 }
64
65 pub async fn hello_world_raw(
67 &mut self,
68 request: HelloWorldRequest,
69 ) -> Result<HelloWorldResponse, GestaltError> {
70 let mut tonic_request = tonic::Request::new(to_wire_hello_world_request(request));
71 if let Some(timeout) = self.timeout {
72 tonic_request.set_timeout(timeout);
73 }
74 let response = self.inner.hello_world(tonic_request).await?;
75 Ok(from_wire_hello_world_response(response.into_inner()))
76 }
77}