From 849c494d2dcda324ba376fa45801e64a581aa39d Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Thu, 15 Aug 2024 03:16:14 -0700 Subject: [PATCH] (#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. --- src/chocolatey.tests.integration/App.config | 60 ++- .../chocolatey.tests.integration.csproj | 350 ++++++++++++++- .../packages.config | 164 ++++++- .../scenarios/UpgradeScenarios.cs | 402 +++++++++++++++++- 4 files changed, 967 insertions(+), 9 deletions(-) diff --git a/src/chocolatey.tests.integration/App.config b/src/chocolatey.tests.integration/App.config index 99445ab633..396cb5fae5 100644 --- a/src/chocolatey.tests.integration/App.config +++ b/src/chocolatey.tests.integration/App.config @@ -1,6 +1,60 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj b/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj index f352dc8d53..d5f8a0615f 100644 --- a/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj +++ b/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj @@ -1,5 +1,6 @@  + @@ -79,6 +80,9 @@ MinimumRecommendedRules.ruleset + + ..\packages\AnyOf.0.3.0\lib\net45\AnyOf.dll + ..\packages\Chocolatey.NuGet.Common.3.4.2\lib\net472\Chocolatey.NuGet.Common.dll @@ -97,45 +101,343 @@ ..\packages\Chocolatey.NuGet.Versioning.3.4.2\lib\net472\Chocolatey.NuGet.Versioning.dll + + ..\packages\Fare.2.2.1\lib\net35\Fare.dll + ..\packages\FluentAssertions.6.11.0\lib\net47\FluentAssertions.dll + + ..\packages\Handlebars.Net.2.1.6\lib\net451\Handlebars.dll + + + ..\packages\Handlebars.Net.Helpers.2.4.4\lib\net46\Handlebars.Net.Helpers.dll + + + ..\packages\Handlebars.Net.Helpers.Core.2.4.4\lib\net46\HandlebarsDotNet.Helpers.Core.dll + + + ..\packages\Handlebars.Net.Helpers.DynamicLinq.2.4.4\lib\net46\HandlebarsDotNet.Helpers.DynamicLinq.dll + + + ..\packages\Handlebars.Net.Helpers.Humanizer.2.4.4\lib\net46\HandlebarsDotNet.Helpers.Humanizer.dll + + + ..\packages\Handlebars.Net.Helpers.Json.2.4.4\lib\net46\HandlebarsDotNet.Helpers.Json.dll + + + ..\packages\Handlebars.Net.Helpers.Random.2.4.4\lib\net46\HandlebarsDotNet.Helpers.Random.dll + + + ..\packages\Handlebars.Net.Helpers.Xeger.2.4.4\lib\net46\HandlebarsDotNet.Helpers.Xeger.dll + + + ..\packages\Handlebars.Net.Helpers.XPath.2.4.4\lib\net46\HandlebarsDotNet.Helpers.XPath.dll + + + ..\packages\Handlebars.Net.Helpers.Xslt.2.4.4\lib\net46\HandlebarsDotNet.Helpers.Xslt.dll + + + ..\packages\Humanizer.Core.2.14.1\lib\netstandard2.0\Humanizer.dll + + + ..\packages\JmesPath.Net.1.0.125\lib\net45\JmesPath.Net.dll + + + ..\packages\JsonConverter.Abstractions.0.5.0\lib\net461\JsonConverter.Abstractions.dll + ..\packages\log4net.2.0.12\lib\net45\log4net.dll + + ..\packages\Microsoft.AspNetCore.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.dll + + + ..\packages\Microsoft.AspNetCore.Authentication.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Authentication.Abstractions.dll + + + ..\packages\Microsoft.AspNetCore.Authentication.Core.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Authentication.Core.dll + + + ..\packages\Microsoft.AspNetCore.Connections.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Connections.Abstractions.dll + + + ..\packages\Microsoft.AspNetCore.Diagnostics.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Diagnostics.dll + + + ..\packages\Microsoft.AspNetCore.Diagnostics.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Diagnostics.Abstractions.dll + + + ..\packages\Microsoft.AspNetCore.HostFiltering.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.HostFiltering.dll + + + ..\packages\Microsoft.AspNetCore.Hosting.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.dll + + + ..\packages\Microsoft.AspNetCore.Hosting.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.Abstractions.dll + + + ..\packages\Microsoft.AspNetCore.Hosting.Server.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.Server.Abstractions.dll + + + ..\packages\Microsoft.AspNetCore.Http.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.dll + + + ..\packages\Microsoft.AspNetCore.Http.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.Abstractions.dll + + + ..\packages\Microsoft.AspNetCore.Http.Extensions.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.Extensions.dll + + + ..\packages\Microsoft.AspNetCore.Http.Features.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.Features.dll + + + ..\packages\Microsoft.AspNetCore.HttpOverrides.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.HttpOverrides.dll + + + ..\packages\Microsoft.AspNetCore.Routing.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Routing.dll + + + ..\packages\Microsoft.AspNetCore.Routing.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Routing.Abstractions.dll + + + ..\packages\Microsoft.AspNetCore.Server.IIS.2.2.6\lib\netstandard2.0\Microsoft.AspNetCore.Server.IIS.dll + + + ..\packages\Microsoft.AspNetCore.Server.IISIntegration.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Server.IISIntegration.dll + + + ..\packages\Microsoft.AspNetCore.Server.Kestrel.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.dll + + + ..\packages\Microsoft.AspNetCore.Server.Kestrel.Core.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.Core.dll + + + ..\packages\Microsoft.AspNetCore.Server.Kestrel.Https.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.Https.dll + + + ..\packages\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.dll + + + ..\packages\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll + + + ..\packages\Microsoft.AspNetCore.WebUtilities.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.WebUtilities.dll + + + ..\packages\Microsoft.Bcl.AsyncInterfaces.1.1.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll + + + ..\packages\Microsoft.Extensions.Configuration.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll + + + ..\packages\Microsoft.Extensions.Configuration.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll + + + ..\packages\Microsoft.Extensions.Configuration.Binder.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.Binder.dll + + + ..\packages\Microsoft.Extensions.Configuration.CommandLine.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.CommandLine.dll + + + ..\packages\Microsoft.Extensions.Configuration.EnvironmentVariables.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.EnvironmentVariables.dll + + + ..\packages\Microsoft.Extensions.Configuration.FileExtensions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.FileExtensions.dll + + + ..\packages\Microsoft.Extensions.Configuration.Json.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.Json.dll + + + ..\packages\Microsoft.Extensions.Configuration.UserSecrets.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.UserSecrets.dll + + + ..\packages\Microsoft.Extensions.DependencyInjection.2.2.0\lib\net461\Microsoft.Extensions.DependencyInjection.dll + + + ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + + ..\packages\Microsoft.Extensions.FileProviders.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.FileProviders.Abstractions.dll + + + ..\packages\Microsoft.Extensions.FileProviders.Physical.2.2.0\lib\netstandard2.0\Microsoft.Extensions.FileProviders.Physical.dll + + + ..\packages\Microsoft.Extensions.FileSystemGlobbing.2.2.0\lib\netstandard2.0\Microsoft.Extensions.FileSystemGlobbing.dll + + + ..\packages\Microsoft.Extensions.Hosting.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Hosting.Abstractions.dll + + + ..\packages\Microsoft.Extensions.Logging.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Logging.dll + + + ..\packages\Microsoft.Extensions.Logging.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll + + + ..\packages\Microsoft.Extensions.Logging.Configuration.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Logging.Configuration.dll + + + ..\packages\Microsoft.Extensions.Logging.Console.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Logging.Console.dll + + + ..\packages\Microsoft.Extensions.Logging.Debug.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Logging.Debug.dll + + + ..\packages\Microsoft.Extensions.Logging.EventSource.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Logging.EventSource.dll + + + ..\packages\Microsoft.Extensions.ObjectPool.2.2.0\lib\netstandard2.0\Microsoft.Extensions.ObjectPool.dll + + + ..\packages\Microsoft.Extensions.Options.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Options.dll + + + ..\packages\Microsoft.Extensions.Options.ConfigurationExtensions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Options.ConfigurationExtensions.dll + + + ..\packages\Microsoft.Extensions.Primitives.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll + + + ..\packages\Microsoft.IdentityModel.Abstractions.6.34.0\lib\net472\Microsoft.IdentityModel.Abstractions.dll + + + ..\packages\Microsoft.IdentityModel.JsonWebTokens.6.34.0\lib\net472\Microsoft.IdentityModel.JsonWebTokens.dll + + + ..\packages\Microsoft.IdentityModel.Logging.6.34.0\lib\net472\Microsoft.IdentityModel.Logging.dll + + + ..\packages\Microsoft.IdentityModel.Protocols.6.34.0\lib\net472\Microsoft.IdentityModel.Protocols.dll + + + ..\packages\Microsoft.IdentityModel.Protocols.OpenIdConnect.6.34.0\lib\net472\Microsoft.IdentityModel.Protocols.OpenIdConnect.dll + + + ..\packages\Microsoft.IdentityModel.Tokens.6.34.0\lib\net472\Microsoft.IdentityModel.Tokens.dll + + + ..\packages\Microsoft.Net.Http.Headers.2.2.0\lib\netstandard2.0\Microsoft.Net.Http.Headers.dll + + + ..\packages\Microsoft.OpenApi.1.2.3\lib\net46\Microsoft.OpenApi.dll + + + ..\packages\Microsoft.OpenApi.Readers.1.2.3\lib\net46\Microsoft.OpenApi.Readers.dll + ..\packages\Microsoft.Web.Xdt.3.1.0\lib\net40\Microsoft.Web.XmlTransform.dll ..\packages\Moq.4.2.1402.2112\lib\net40\Moq.dll + + ..\packages\Namotion.Reflection.2.0.10\lib\net45\Namotion.Reflection.dll + - ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll + + + ..\packages\NJsonSchema.10.7.2\lib\net45\NJsonSchema.dll + + + ..\packages\NJsonSchema.Extensions.0.1.0\lib\net45\NJsonSchema.Extensions.dll + + + ..\packages\NSwag.Core.13.16.1\lib\net45\NSwag.Core.dll ..\packages\NUnit.3.13.3\lib\net40\nunit.framework.dll + + ..\packages\RamlToOpenApiConverter.0.6.1\lib\net46\RamlToOpenApiConverter.dll + + + ..\packages\RandomDataGenerator.Net.1.0.17\lib\net45\RandomDataGenerator.dll + + + ..\packages\Scriban.Signed.2.1.4\lib\net45\Scriban.Signed.dll + + + ..\packages\SharpYaml.1.6.5\lib\net45\SharpYaml.dll + + + ..\packages\SimMetrics.Net.1.0.5\lib\net45\SimMetrics.Net.dll + ..\packages\SimpleInjector.2.8.3\lib\net45\SimpleInjector.dll + + ..\packages\Stef.Validation.0.1.1\lib\net40\Stef.Validation.dll + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + ..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll + + + ..\packages\System.ComponentModel.Annotations.4.5.0\lib\net461\System.ComponentModel.Annotations.dll + + + + ..\packages\System.Diagnostics.DiagnosticSource.4.5.0\lib\net46\System.Diagnostics.DiagnosticSource.dll + + + ..\packages\System.IdentityModel.Tokens.Jwt.6.34.0\lib\net472\System.IdentityModel.Tokens.Jwt.dll + + + ..\packages\System.IO.Pipelines.4.5.3\lib\netstandard2.0\System.IO.Pipelines.dll + + + ..\packages\System.Linq.Dynamic.Core.1.3.12\lib\net46\System.Linq.Dynamic.Core.dll + + + ..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll + + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + ..\packages\System.Reactive.5.0.0\lib\net472\System.Reactive.dll - - ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + ..\packages\System.Reflection.Metadata.1.6.0\lib\netstandard2.0\System.Reflection.Metadata.dll + + ..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + + ..\packages\System.Security.Cryptography.Cng.4.5.0\lib\net47\System.Security.Cryptography.Cng.dll + + + ..\packages\System.Security.Principal.Windows.4.5.0\lib\net461\System.Security.Principal.Windows.dll + + + ..\packages\System.Text.Encodings.Web.4.7.2\lib\net461\System.Text.Encodings.Web.dll + + + ..\packages\System.Text.Json.4.7.2\lib\net461\System.Text.Json.dll + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + @@ -144,7 +446,42 @@ + + ..\packages\System.Xml.XmlDocument.4.3.0\lib\net46\System.Xml.XmlDocument.dll + True + True + + + ..\packages\TinyMapper.3.0.3\lib\net40\TinyMapper.dll + + + ..\packages\WireMock.Net.1.5.62\lib\net461\WireMock.Net.dll + + + ..\packages\WireMock.Net.Abstractions.1.5.62\lib\net461\WireMock.Net.Abstractions.dll + + + ..\packages\WireMock.Net.FluentAssertions.1.5.62\lib\net47\WireMock.Net.FluentAssertions.dll + + + ..\packages\WireMock.Net.OpenApiParser.1.5.62\lib\net46\WireMock.Net.OpenApiParser.dll + + + ..\packages\WireMock.Org.Abstractions.1.5.62\lib\net45\WireMock.Org.Abstractions.dll + + + ..\packages\XPath2.1.1.5\lib\net452\XPath2.dll + + + ..\packages\XPath2.Extensions.1.1.5\lib\net452\XPath2.Extensions.dll + + + ..\packages\YamlDotNet.8.1.0\lib\net45\YamlDotNet.dll + + + + @@ -218,7 +555,14 @@ + + + + + + +