Looking for unit test/mock guidance
- Dominant language
- Rust
- Stars
- 12.5k
- Forks
- 1.3k
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 24
Description
Hi,
I'm looking for an example on how to unit test/mock gRPC responses for a client. For instance, I have the following code:
```rust
async fn main() -> Result<()> {
let client = GrpcClient::connect(...);
grpc_call(client).await?;
}
async fn grpc_call(mut client: GrpcClient) -> Result<()> {
let result = client.grpc_call(Request::new(GrpcRequest {/* valid input */})).await?;
// do something with result
Ok(())
}
```
Now I would like to do something like this:
```rust
#[cfg(test)]
mod tests {
#[test]
fn test_grpc_call() {
// setup mock client, with
// code for asserting that the request has the correct fields set, and
// return a mock response
grpc_call(mock_client).expect("should work");
}
}
````
I can't find any examples on how to setup any kind of mocking/testing generated clients. Is anyone doing this in their repo, and if so can you please point me to a working example?
I've looked at https://github.com/hyperium/tonic/blob/master/examples/src/mock/mock.rs, but that doesn't have any tests so I'm insure how to use it (if it is even possible to do what I want with that example).
Contributor guide
Assessment
This issue has not been assessed yet.