alexliesenfeld / httpmock

HTTP mocking library for Rust.
MIT License
436 stars 38 forks source link

Improve httpmock's standalone capabilities #6

Closed flaper87 closed 3 years ago

flaper87 commented 4 years ago

This PR does a couple of things:

alexliesenfeld commented 4 years ago

Thanks for your PR! What is your use case for this implementation? I am asking because usually tests should be self-contained and isolated, so basically setup all mocks required by the test run themselfes.

flaper87 commented 4 years ago

@alexliesenfeld Arguably, this may not fit in the goals you have for this project. Let me elaborate on my use-case and see if you have a better idea on how to do this:

I have a set of projects that would benefit from having a "mock server" available where they can define their own mocked APIs, run their queries, etc. I would like this mock server to always be running and to have some APIs persisted as it would help testing the integration of a more complex architecture. Real scenario:

I have a Kubernetes cluster that uses nginx-ingress. The logs coming from nginx ingres are collected using filebeat and then sent to a Logstash instance that parses these events and stores, does some operations, and then eventually stores them somewhere.

I'd like to write tests that would create the mocked API endpoints in httpmock, and use it as a backend for the nginx-ingress in order to test the whole workflow.

Instead of setting it up everytime, I would like httpmock to be always active and accessible not only by me but also other folks in the team. The delete_all call would make this impossible as we may delete each other's endpoints.

I could probably also write my own code that doesn't use this macro but I would rather not, especially considering that it would be possible to allow for my use-case by simply adding this option. Although, I realize that the implications of adding an option like this is rarely "simple" in the long run.

Let me know what you think, hope I was clear enough.

alexliesenfeld commented 4 years ago

I understand. There will be a couple of bigger changes in the next few releases and your requirements might become implicitly met. I recommend to come back and check again in a few weeks.

Running a standalone httpmock instance in a Kubernetes cluster would also require some kind of persistence to avoid losing state when the pod gets rescheduled, but that might be a story on top.

I will keep this PR open for now.

flaper87 commented 4 years ago

that sounds fantastic! I am happy to wait 🙏

Feel free to close this PR too ☺️

flaper87 commented 3 years ago

Going to close this now, no need to keep it open :)