Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(chocolatey#3489) Introduce WireMock.Net
In order to fully test out the code path where the attempt to write the .chocolateyPending file was failing, we needed to be able to return a 503/504 error from the server. Realistically, this isn't feasible, since it would mean having a server in place, that would be able to respond with the right responses, at the right time. After digging around for a little bit, I found the WireMock.Net project, which seemed to do exactly what was needed, namely: > WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. I took this for a spin, and was able to start/stop the server within our test harnesses, and then was able to mock the required HTTP requests, to get to the point during an Upgrade scenario, to then send a 503 response. This then started the code path for the .chocolateyPending file, and I was able to make assertions that the lib/lib-bad/lib-bkp folders worked as expected. The only "change" that was needed to a normal test scenario, was to change this line: Configuration.Sources = "http://localhost:24626/api/v2/"; to force Chocolatey CLI to direct requests to the WireMock.Net server. There is likely LOTS of things that we could start doing with this server, and there is likely some code that needs to be added to encapsulate the creation of the responses, to make them more re-usable, but for now, the required responses for this code path has been hard-coded into the responses. NOTE: There are a LOT of packages added in this commit, and all of them came in as a result of installing the WireMock.Net package. Since this is a test project, i.e. we are not shipping any of these, I don't believe this to be a concern.
- Loading branch information