I have an Http Client which uses a proxy in real life to send a request to an API. I am trying to use WireMock to run my http client tests and mock the responses for the API. However, I could not manage to make Wiremock work with a proxy setup. I have tried all the relevant combinations and still couldn't manage to get a successful test.
I have tried viaProxy
configuration and also proxiedWith
but not sure if I am using them correctly. The documentation is not helping much either.
The client code has the following config:
private val httpsProxySettings: ConnectionPoolSettings =
ConnectionPoolSettings(actorSystem)
.withConnectionSettings(ClientConnectionSettings(actorSystem))
.withTransport(
ClientTransport.httpsProxy(
InetSocketAddress.createUnresolved(PROXY_HOST, PROXY_PORT)
)
)
And the test configuration is along the lines of:
val wireMockServer = new WireMockServer(
wireMockConfig().port(API_PORT).proxyVia(PROXY_HOST, PROXY_PORT)
)
wireMockServer.start()
WireMock.configureFor("localhost", API_PORT)
wireMockServer.stubFor(
put(anyUrl())
.willReturn(
aResponse()
.withStatus(201)
// .proxiedFrom(API_HOST)
)
)