Skip to content

Commit

Permalink
(chocolatey#3489) Introduce WireMock.Net
Browse files Browse the repository at this point in the history
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
gep13 committed Aug 15, 2024
1 parent 86c88e0 commit 1f30bee
Show file tree
Hide file tree
Showing 4 changed files with 964 additions and 9 deletions.
60 changes: 57 additions & 3 deletions src/chocolatey.tests.integration/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<loadFromRemoteSources enabled="true"/>
<loadFromRemoteSources enabled="true" />
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="NJsonSchema" publicKeyToken="c2f9c3bdfae56102" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.7.2.0" newVersion="10.7.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Stef.Validation" publicKeyToken="8f3400880c321038" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.1.1.0" newVersion="0.1.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.5.1" newVersion="4.0.5.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.Cng" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.AspNetCore.Server.IIS" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.6.0" newVersion="2.2.6.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="FluentAssertions" publicKeyToken="33f2691a05b67b6a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.11.0.0" newVersion="6.11.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /></startup></configuration>
Loading

0 comments on commit 1f30bee

Please sign in to comment.