Feature Request
make codec::decode::Streaming a trait.
This will allow easier mocking needed for testing of grpc calls using client streaming.
Crates
tonic
tonic-build
Motivation
currently when I have a grpc call with client streaming like ByteStream::Write I get a rust function with this signature:
async fn write(&self, request: Request<Streaming<WriteRequest>>) -> Result<Response<WriteResponse>, Status>
If I want to test this function I would need to create a Streaming object which is quite complicated.
It would be much easier if the generated function write would be generic accepting a argument implementing the trait Stream and Streaming would implement this.
Proposal
Adding a new trait
trait Stream {
type Item;
async fn message<'_>(&'_ mut self) -> Result<Option<Self::Item>, Status>;
async fn trailers<'_>(&'_ mut self) -> Result<Option<MetadataMap>, Status>;
}
and generate function definitions for ByteStream::write with such a signature
async fn write<S: Stream<Item = WriteRequest >>(&self, request: Request<S>);
This would allow to create simple Mocks which implement Stream for testing.
And otherwise Streaming is still used, which must then implement Stream.
Alternatives
Please let me know if you know alternative how testing can be simplified.
Feature Request
make codec::decode::Streaming a trait.
This will allow easier mocking needed for testing of grpc calls using client streaming.
Crates
tonictonic-buildMotivation
currently when I have a grpc call with client streaming like ByteStream::Write I get a rust function with this signature:
If I want to test this function I would need to create a
Streamingobject which is quite complicated.It would be much easier if the generated function
writewould be generic accepting a argument implementing the traitStreamandStreamingwould implement this.Proposal
Adding a new trait
and generate function definitions for
ByteStream::writewith such a signatureThis would allow to create simple Mocks which implement
Streamfor testing.And otherwise
Streamingis still used, which must then implementStream.Alternatives
Please let me know if you know alternative how testing can be simplified.