Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for lower-level TCP and UDP connections #204

Open
nyurik opened this issue Sep 29, 2024 · 4 comments
Open

Support for lower-level TCP and UDP connections #204

nyurik opened this issue Sep 29, 2024 · 4 comments

Comments

@nyurik
Copy link
Contributor

nyurik commented Sep 29, 2024

Mockito does a great job at the HTTP level, but at times I would like to test lower level clients that send UDP or TCP packets. While this is clearly different from the server.mock(...) -> Mock object, some of the mockito infrastructure may still apply.

Usage example:

let mut s = mockito::Server::new();

s.mock_udp()
  .match_size(3) // expect 3-byte message
  .match_body(b'123') // expect message matching these bytes
  .with_body(b'456') // respond with these bytes
  .create();

Other matching could help examine the received data, validate it, respond differently depending on the content, etc

P.S. https://github.com/thomasarmel/socket-server-mocker is a similar effort that might benefit from joining mockito project?

@nyurik

This comment was marked as resolved.

@nyurik

This comment was marked as resolved.

Repository owner deleted a comment Sep 30, 2024
@lipanski
Copy link
Owner

lipanski commented Oct 1, 2024

@nyurik sounds interesting but I think I would have to introduce a new type TcpServer (and UdpServer) since otherwise the validation rules on the existing and new matchers would get quite complex and hard to follow (internally). at that point I wonder if https://github.com/thomasarmel/socket-server-mocker is enough to cover your use case or what are you missing from that crate? generally I try to keep mockito fairly minimal/contained, even though we're way beyond minimal by now 😸

@nyurik
Copy link
Contributor Author

nyurik commented Oct 1, 2024

Yeah, I was a bit torn on that one too. We would definitely need separate TCP and UDP servers. The infrastructure to keep a pool of them, communication channels between the server and the testing framework, assertion that a mock has been executed, and possibly other plumbing might be relevant. Async stuff might also be highly desirable, and a bit of a pain to duplicate.

HTTP is fundamentally based on request response, while (in theory) TCP / UDP could be more of an independent two way communication / time based /..., although of course most cases it will still be a simple request/response, only at a lower - bytes level.

So if it would be possible to reuse the plumbing, while providing separate set of servers and expectation API, it would be a good addition to your lib - one stop network testing harness. If not, than yeah, a separate lib that replicates a lot of the hard work you did.

The biggest issue with the socket-server-mocker is that it is relatively new and has some rough around the edges spots that will need to be worked through.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants