LukeMathWalker/wiremock-rs

enable starting on fixed port

beltram opened this issue · 4 comments

Hi,
I really liked your crate and started using it to implement mine which aims at turning original Wiremock stubs into mocks.
I have in mind proposing this as a cli or even a Helm chart. So far so good ; the only thing I miss is being able to enforce the server's port at startup.
Something like this would be awesome:

MockServer::start(8080).await

Thanks again for your work !

Wow, super cool!
I'd be happy to mention the project in the README of wiremock itself once you have it in a working state 😁

I would not change start to take a port, but we can definitely add a new method (e.g. start_on) that takes in a std::net::TcpListener as input.

Hi again,
I kinda struggle implementing this since servers are now behind a pool. This makes sense since anytime the pool creates a new server it can bind itself to the next available free port. This does not work anymore for a fixed port.

This leaves 2 options for implementing this I'd like to have your opinion on:

  • turn BareMockServer public & implement start_on(TcpListener) there.
  • create a MockServerConfig struct holding for now just an address (maybe later other fields). Then have a pool per MockServerConfig ; something like HashMap<MockServerConfig, Pool<BareMockServer, Infaillible>>. Users would then invoke MockServer::start_with(config) and get/wait for a server from the pool with their desired config to become available

Hope this is clear enough, which one do you prefer ?

I think there is a third way - let me give it a shot 👌

Released in 0.4.3 😁