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

Specifying port without standalone mock server. #99

Closed
git-noise opened this issue Feb 9, 2024 · 2 comments
Closed

Specifying port without standalone mock server. #99

git-noise opened this issue Feb 9, 2024 · 2 comments

Comments

@git-noise
Copy link

Hello and thanks for httpmock,

I am reaching out to check if there is an alternative way to specify the port to use for a mock server.
I found issue #78, however the solution described there - i.e. using a standalone mock server and then connect to it - requires the "remote" capabilities.
As per #82, this involves a more significant dependency tree, as well as OpenSSL.

In my specific use-case - httpmock is used within a CI/CD environment that leverages containers. The issue arises for tools that are configured using environment variables, which may not be properly settable after the container has started - hence requiring to know the port beforehand.
A standalone mock solves it, but - beyond what I highlighted above - it also limits the ability to have internal mocks per tests set, as one would need to spin one mock "externally", identify its port, configure the test environment, and then run the tests.

Many thanks and let me know if I missed something,
Best,

@alexliesenfeld
Copy link
Owner

alexliesenfeld commented Feb 27, 2024

Thank you for reaching out. I’d like to explain the functionality a bit clearer:

  • For a standalone mock server, you can choose a specific port. This server can be used in multiple test cases. But, because it uses only one port, we can't run tests in parallel (since there's just one server on one port, only one test can run at a time). To manage this, httpmock makes sure tests that need the mock server run sequentially to prevent multiple tests from trying to use the server at the same time. This approach does allow you to have separate mocks for each test, though.
  • For a test-specific mock server (not standalone), httpmock uses a pool of mock servers to enable running tests in parallel. However, you can't choose a specific port for these servers because they are created as needed and must pick any available port on the system.

Despite the additional dependencies, using a standalone server seems to fit your needs better.

Tip: You can set up a test-specific standalone mock server on a specific port, but I'm not sure if this is going to be helpful in your case. Here’s a test example that uses it: https://github.com/alexliesenfeld/httpmock/blob/master/tests/examples/standalone_tests.rs

Regarding the OpenSSL dependency, there is this PR that should address this in the future.

@alexliesenfeld
Copy link
Owner

Closing now. Feel free to reopen if you think there is still a missing feature.

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