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, serde::Serialize, serde::Deserialize)]
14#[serde(rename_all = "camelCase")]
15pub struct HelloWorldRequest {}
16
17#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
21#[serde(rename_all = "camelCase")]
22pub struct HelloWorldResponse {
23 pub message: String,
25}
26
27pub struct Test {
32 inner: v1::test_client::TestClient<tonic::transport::Channel>,
33 timeout: Option<std::time::Duration>,
34}
35
36impl Test {
37 pub fn new(channel: tonic::transport::Channel) -> Self {
39 Self {
40 inner: v1::test_client::TestClient::new(channel),
41 timeout: None,
42 }
43 }
44
45 pub fn with_timeout(mut self, timeout: std::time::Duration) -> Self {
48 self.timeout = Some(timeout);
49 self
50 }
51
52 pub async fn hello_world(
54 &mut self,
55 request: HelloWorldRequest,
56 ) -> Result<String, GestaltError> {
57 let mut tonic_request = tonic::Request::new(to_wire_hello_world_request(request));
58 if let Some(timeout) = self.timeout {
59 tonic_request.set_timeout(timeout);
60 }
61 let response = from_wire_hello_world_response(
62 self.inner.hello_world(tonic_request).await?.into_inner(),
63 );
64 Ok(response.message)
65 }
66
67 pub async fn hello_world_raw(
69 &mut self,
70 request: HelloWorldRequest,
71 ) -> Result<HelloWorldResponse, GestaltError> {
72 let mut tonic_request = tonic::Request::new(to_wire_hello_world_request(request));
73 if let Some(timeout) = self.timeout {
74 tonic_request.set_timeout(timeout);
75 }
76 let response = self.inner.hello_world(tonic_request).await?;
77 Ok(from_wire_hello_world_response(response.into_inner()))
78 }
79}