use crate::codec::test::{from_wire_hello_world_response, to_wire_hello_world_request};
use crate::generated::v1;
use crate::rpc_support::GestaltError;
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct HelloWorldRequest {}
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct HelloWorldResponse {
pub message: String,
}
pub struct Test {
inner: v1::test_client::TestClient<tonic::transport::Channel>,
timeout: Option<std::time::Duration>,
}
impl Test {
pub fn new(channel: tonic::transport::Channel) -> Self {
Self {
inner: v1::test_client::TestClient::new(channel),
timeout: None,
}
}
pub fn with_timeout(mut self, timeout: std::time::Duration) -> Self {
self.timeout = Some(timeout);
self
}
pub async fn hello_world(
&mut self,
request: HelloWorldRequest,
) -> Result<String, GestaltError> {
let mut tonic_request = tonic::Request::new(to_wire_hello_world_request(request));
if let Some(timeout) = self.timeout {
tonic_request.set_timeout(timeout);
}
let response = from_wire_hello_world_response(
self.inner.hello_world(tonic_request).await?.into_inner(),
);
Ok(response.message)
}
pub async fn hello_world_raw(
&mut self,
request: HelloWorldRequest,
) -> Result<HelloWorldResponse, GestaltError> {
let mut tonic_request = tonic::Request::new(to_wire_hello_world_request(request));
if let Some(timeout) = self.timeout {
tonic_request.set_timeout(timeout);
}
let response = self.inner.hello_world(tonic_request).await?;
Ok(from_wire_hello_world_response(response.into_inner()))
}
}