alexliesenfeld / httpmock

HTTP mocking library for Rust.
MIT License
435 stars 40 forks source link

Specifying port without standalone mock server. #99

Closed git-noise closed 4 months ago

git-noise commented 4 months ago

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 commented 4 months ago

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

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 commented 4 months ago

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