Skip to content

Commit

Permalink
(chocolatey#1935) Add User Agent test to ensure NuGet version is used
Browse files Browse the repository at this point in the history
This both ensures that the user agent is set, when NuGet sources are configured
and that it uses the upstream version of NuGet that the NuGet assembles are
based on. This same version is used in other areas as well, like minClientVersion,
so it applies to multiple areas.
  • Loading branch information
TheCakeIsNaOH authored and gep13 committed Apr 17, 2023
1 parent 1dcac3e commit 046a5c4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/chocolatey.tests.integration/scenarios/PackScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,24 +499,24 @@ public void Should_throw_exception_on_icon_element()
}
}

public class when_packing_with_min_client_version : ScenariosBase
public class When_packing_with_min_client_version : ScenariosBase
{
protected override string ExpectedNuspecVersion => "0.1.0";
protected override string ExpectedSubDirectory => "PackageOutput";

// This high version is to ensure that pack does not throw, even if the min client version is well
// above both the Chocolatey and NuGet assembly versions.
private string MinClientVersion = "100.0.0";
private string _MinClientVersion = "100.0.0";

public override void Because()
{
MockLogger.reset();
Service.pack_run(Configuration);
MockLogger.Reset();
Service.Pack(Configuration);
}

protected override string GetNuspecContent()
{
return NuspecContentWithFormatableMinClientVersion.format_with(MinClientVersion);
return NuspecContentWithFormatableMinClientVersion.FormatWith(_MinClientVersion);
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/chocolatey.tests/infrastructure.app/nuget/NugetCommonSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace chocolatey.tests.infrastructure.app.nuget
using System;
using System.Collections.Generic;
using System.Linq;
using chocolatey.infrastructure.app;
using chocolatey.infrastructure.app.configuration;
using chocolatey.infrastructure.app.nuget;
using chocolatey.infrastructure.filesystem;
Expand Down Expand Up @@ -161,6 +162,22 @@ public void Should_parse_unc_source()
packageRepositories.First().PackageSource.IsLocal.ShouldBeTrue();
packageRepositories.First().PackageSource.SourceUri.IsUnc.ShouldBeTrue();
}

[Fact]
public void Should_set_user_agent_string()
{
Context();
var source = "https://community.chocolatey.org/api/v2/";
configuration.Sources = source;
configuration.Information.ChocolateyProductVersion = "vNext";

because();

// Change this when the NuGet version is updated.
string nugetClientVersion = "6.4.1";
string expectedUserAgentString = "{0}/{1} via NuGet Client/{2}".FormatWith(ApplicationParameters.UserAgent, configuration.Information.ChocolateyProductVersion, nugetClientVersion);
UserAgent.UserAgentString.ShouldStartWith(expectedUserAgentString);
}
}
}
}

0 comments on commit 046a5c4

Please sign in to comment.