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

Improve httpmock's standalone capabilities #6

Closed
wants to merge 4 commits into from

Conversation

flaper87
Copy link

This PR does a couple of things:

  • Allow for keeping mocks after runs by setting the HTTPMOCK_KEEP_MOCKS variable
  • Allow for serving all existing mocks by accessing __mocks/

With this variable httpmock won't delete all mocks during the setup/cleanup
steps. This is useful when using httpmock as a standalone, shared, service
to test multiple services. More importantly, it helps preserving mocks accross
runs for later use
@alexliesenfeld
Copy link
Owner

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
Copy link
Author

@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
Copy link
Owner

alexliesenfeld commented Jun 21, 2020

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
Copy link
Author

that sounds fantastic! I am happy to wait 🙏

Feel free to close this PR too ☺️

@alexliesenfeld alexliesenfeld mentioned this pull request Jul 6, 2020
@flaper87
Copy link
Author

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

@flaper87 flaper87 closed this Aug 17, 2020
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

Successfully merging this pull request may close these issues.

None yet

2 participants