Example of using a server as the `GrpcService` in a client
- Dominant language
- Rust
- Stars
- 12.5k
- Forks
- 1.3k
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 24
Description
I wanted to write some end-to-end tests for code that uses a tonic client. I wanted to have a mock server _without_ needing to mock the gRPC client.
I started with the [`mock`](https://github.com/hyperium/tonic/blob/master/examples/src/mock/mock.rs) example which uses a duplex stream for in-process I/O, but that felt overly complicated. I then started looking at the `GrpcService` trait and creating an implementation that would use my mock server directly.
While writing that implementation, I discovered that tonic servers _already implement this trait_. You can simply pass a server to a client and it works.
```rust
let server = GreetServiceServer::new(Greeter::default());
let client = GreetServiceClient::new(server);
```
I couldn't find any examples of this pattern in the repo and it's very handy for testing.
Would you be willing to accept a PR to add an example demonstrating this? Would it be preferable to **replace** the `mock` example with this pattern?
Contributor guide
Assessment
This issue has not been assessed yet.