-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: debug fixes and version bumps
- Loading branch information
Showing
20 changed files
with
312 additions
and
218 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
//! Client Library: Client Functions, Structs, Traits | ||
#![allow(unused_qualifications)] | ||
include!("grpc.rs"); | ||
|
||
use super::*; | ||
|
||
#[cfg(not(feature = "stub_client"))] | ||
use lib_common::grpc::ClientConnect; | ||
use lib_common::grpc::{Client, GrpcClient}; | ||
use rpc_service_client::RpcServiceClient; | ||
/// GrpcClient implementation of the RpcServiceClient | ||
pub type TemplateRustClient = GrpcClient<RpcServiceClient<Channel>>; | ||
|
||
cfg_if::cfg_if! { | ||
if #[cfg(feature = "stub_backends")] { | ||
use svc_template_rust::grpc::server::{RpcServiceServer, ServerImpl}; | ||
lib_common::grpc_mock_client!(RpcServiceClient, RpcServiceServer, ServerImpl); | ||
super::log_macros!("grpc", "app::client::mock::template_rust"); | ||
} else { | ||
lib_common::grpc_client!(RpcServiceClient); | ||
super::log_macros!("grpc", "app::client::template_rust"); | ||
} | ||
} | ||
|
||
#[cfg(not(feature = "stub_client"))] | ||
#[async_trait] | ||
impl crate::service::Client<RpcServiceClient<Channel>> for TemplateRustClient { | ||
type ReadyRequest = ReadyRequest; | ||
type ReadyResponse = ReadyResponse; | ||
|
||
async fn is_ready( | ||
&self, | ||
request: Self::ReadyRequest, | ||
) -> Result<tonic::Response<Self::ReadyResponse>, tonic::Status> { | ||
grpc_info!("(is_ready) {} client.", self.get_name()); | ||
grpc_debug!("(is_ready) request: {:?}", request); | ||
self.get_client().await?.is_ready(request).await | ||
} | ||
} | ||
|
||
#[cfg(feature = "stub_client")] | ||
#[async_trait] | ||
impl crate::service::Client<RpcServiceClient<Channel>> for TemplateRustClient { | ||
type ReadyRequest = ReadyRequest; | ||
type ReadyResponse = ReadyResponse; | ||
|
||
async fn is_ready( | ||
&self, | ||
request: Self::ReadyRequest, | ||
) -> Result<tonic::Response<Self::ReadyResponse>, tonic::Status> { | ||
grpc_warn!("(is_ready MOCK) {} client.", self.get_name()); | ||
grpc_debug!("(is_ready MOCK) request: {:?}", request); | ||
Ok(tonic::Response::new(ReadyResponse { ready: true })) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::service::Client as ServiceClient; | ||
|
||
use super::*; | ||
|
||
#[tokio::test] | ||
#[cfg(not(feature = "stub_client"))] | ||
async fn test_client_connect() { | ||
let name = "template_rust"; | ||
let (server_host, server_port) = | ||
lib_common::grpc::get_endpoint_from_env("GRPC_HOST", "GRPC_PORT"); | ||
|
||
let client: TemplateRustClient = GrpcClient::new_client(&server_host, server_port, name); | ||
assert_eq!(client.get_name(), name); | ||
|
||
let connection = client.get_client().await; | ||
println!("{:?}", connection); | ||
assert!(connection.is_ok()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_client_is_ready_request() { | ||
let name = "template_rust"; | ||
let (server_host, server_port) = | ||
lib_common::grpc::get_endpoint_from_env("GRPC_HOST", "GRPC_PORT"); | ||
|
||
let client: TemplateRustClient = GrpcClient::new_client(&server_host, server_port, name); | ||
assert_eq!(client.get_name(), name); | ||
|
||
let result = client.is_ready(ReadyRequest {}).await; | ||
println!("{:?}", result); | ||
assert!(result.is_ok()); | ||
assert_eq!(result.unwrap().into_inner().ready, true); | ||
} | ||
} |
Oops, something went wrong.