Hi I have a simple application that has one gRPC method it works as expected however I do not know how to correctly integration test it. (I'm new to rust too). i.e. I would like to call gRPC add_merchant method and check if the response contains correct values.
I have following structure:
app
proto
merchant.proto
src
main.rs
merchant.rs
tests
merchant_test.rs
build.rs
Cargo.toml
merchant.proto
syntax = "proto3";
package merchant;
service MerchantService {
rpc AddMerchant (Merchant) returns (Merchant);
}
message Merchant {
string name = 1;
}
merchant.rs
mod merchant;
use merchant::merchant_service_server::MerchantServiceServer;
use merchant::MerchantServiceImpl;
use tonic::transport::Server;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr = "127.0.0.1:50051".parse()?;
let merchant = MerchantServiceImpl::default();
Server::builder()
.add_service(MerchantServiceServer::new(merchant))
.serve(addr)
.await?;
Ok(())
}
main.rs
use tonic::{Request, Response, Status};
use crate::merchant::merchant_service_server::MerchantService;
tonic::include_proto!("merchant");
#[derive(Debug, Default)]
pub struct MerchantServiceImpl {
}
#[tonic::async_trait]
impl MerchantService for MerchantServiceImpl {
async fn add_merchant(&self, request: Request<Merchant>) ->
Result<Response<Merchant>, Status> {
let response = Merchant {
name: "name".to_string()
};
Ok(Response::new(response))
}
}
How should merchant_test.rs look like?