cjstehno / ersatz

🤖 A simulated HTTP server for testing client code with configurable responses.
https://cjstehno.github.io/ersatz
Apache License 2.0
47 stars 5 forks source link

Ersatz proxy support in 3.x #167

Closed radarsh closed 1 year ago

radarsh commented 1 year ago

I have been a long time user of this library and now I am looking at migrating from 1.9.x to the latest 3.x version. The main blocker preventing me from doing so is the lack of support for ErsatzProxy. Granted, I don't have as many tests utilising ErsatzProxy as I have using ErsatzServer but those handful of tests are still important for my application as they test that code processes proxy settings correctly and that the actual proxied endpoint is invoked.

The code that is being tested using ErsatzProxy is being relied on by hundreds of developers in a large enterprise which in turn is used to develop products that affects millions of users globally, in case you were wondering about the appetite.

I am basically coming to this issue from https://cjstehno.github.io/ersatz/docs/user_guide.html#_migrating_to_3_0 where you asked us to show interest in the form of an issue or discussion.

So, can we please have it back in 3.x? Thanks.

cjstehno commented 1 year ago

I'll see what I can do.

cjstehno commented 1 year ago

Actually, it was basically a stand-alone component anyway, it should not be a big deal to rebuild it. I will add it to the next release. If I can pull together some time, I will see if I can cut a release within a month or two.

radarsh commented 1 year ago

Thank you. Really appreciate the work you do with this library.

cjstehno commented 1 year ago

Just curious, is is this an open source project, or would you be interested in building off a branch and trying it out when it's ready?

radarsh commented 1 year ago

It's not an open source project unfortunately but I would be happy to build off a branch and try it out internally.

cjstehno commented 1 year ago

I had an idea for what I feel is a better version of the old proxy server, and I'd like to see if it would satisfy your use case.

I am adding a "forwarding" feature as a new type of response provider in the main expectations API, so that you could configure something like the following:

ersatz.expectations(expect -> {
    expect.GET("/some/path", req -> {
        // optional request matching
        req.forward("http://someother:1234");
    });
});

which would forward the request to the provided host/port and then return its response as the returned response. To me this seems like it would accomplish the same thing as the old proxy, but you'd also get the request matching for free.

Is there something in your case that I am misunderstanding?

Note: if its a matter of changing a lot of test config - I could bring back the old style as well for a release (deprecated) so that you'd have time to change things over. I am more interested in whether this idea can eventually replace it.

cjstehno commented 1 year ago

@radarsh You can checkout the new-proxy-impl branch and see if that will take care of your use case. Note that I am doing what I mentioned above - the stand-alone proxy server will be around until release 4.0 and then it will be removed again. Please let me know if the new "forwarding" functionality will work for you, and if not, what is missing?

Unless you find anything, I will plan on cutting the 3.2 release sometime next week.

cjstehno commented 1 year ago

This has been added to release 3.2, which will be released on Monday.

cjstehno commented 1 year ago

The 3.2 release has been published to the maven central repo - it may take some time to fully propagate.