sfackler / rust-native-tls

Apache License 2.0
470 stars 195 forks source link

How to mock TlsStream<TcpStream> to test network communication? #239

Closed eminfedar closed 1 year ago

eminfedar commented 1 year ago

Hello!

I want to test my network stream input & outputs and I'm using TlsStream<TcpStream> wrapper on my raw TcpStream, but I couldn't find a way to create a mock TlsStream struct.

For regular TcpStream, if I just make function parameter mut stream: TcpStream to -> mut stream: impl Read + Write + Unpin I can put my custom MockTcpStream here to test reads & writes. (like here: https://rust-lang.github.io/async-book/09_example/03_tests.html)

How can I create an TlsStream mock to test my network communication? To see which inputs gives which outputs?

Thanks!

sfackler commented 1 year ago

A TlsStream is also an impl Read + Write + Unpin. What is the specific thing you're looking to test?

eminfedar commented 1 year ago

Oh yes it is! I just dived into documentations and probably didn't see it. Thanks it works!