-
I'm currently working on a solution that uses Yarp as a reverse proxy. And we have implemented a TransformProvider which has a fair amount of logic that needs to be unit tested. I could test that by mocking a lot, if not all, of its dependencies. But then I'm mimicking a lot of existing Yarp code. I prefer to test the TransformProvider by "arranging" the Yarp cluster en routes configuration. And then create a host and a client, and call an api using the client. So I can do some assertions to see that the TransformProvider is doing the right thing. What I'm looking for is guidance on how to properly unit or integration test, in this case, the TransformProvider. And in general how to unit test the custom code that is used for Yarp configuration. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I'd say it depends on what your transforms are doing. E.g. it might be as simple as something along the lines of In most cases it's also simple to create fake request objects ( If you really need to test the end-to-end behavior, YARP itself uses this |
Beta Was this translation helpful? Give feedback.
I'd say it depends on what your transforms are doing. E.g. it might be as simple as something along the lines of
https://github.com/microsoft/reverse-proxy/blob/69acefbc5db6a14d2eb04fb959e58c0724d88e9c/test/ReverseProxy.Tests/Transforms/PathStringTransformTests.cs#L12-L25
In most cases it's also simple to create fake request objects (
new DefaultHttpContext()
) to populate theRequestTransformContext
.What sort of issues did you run into?
If you really need to test the end-to-end behavior, YARP itself uses this
TestEnvironment
helper for some tests to start the proxy & backend servers and proxy a real HTTP request.