Skip to content

Commit

Permalink
Merge pull request #2999 from TheCakeIsNaOH/nuget-version-tests
Browse files Browse the repository at this point in the history
(#1935) Add tests to ensure upstream NuGet version is used.
  • Loading branch information
gep13 authored Apr 17, 2023
2 parents fa95e6b + 61cb649 commit ced3b70
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<metadata minClientVersion="100.0.0">
<id>unsupportedelements</id>
<version>1.0.0</version>
<title>unsupportedelements</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<metadata minClientVersion="100.0.0">
<id>unsupportedelements</id>
<version>1.1.0</version>
<title>unsupportedelements</title>
Expand Down
44 changes: 44 additions & 0 deletions src/chocolatey.tests.integration/scenarios/PackScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,27 @@ public void Should_throw_exception_on_icon_element()
}
}

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";

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

protected override string GetNuspecContent()
{
return NuspecContentWithFormatableMinClientVersion.FormatWith(_minClientVersion);
}
}

private const string NuspecContent = @"<?xml version=""1.0"" encoding=""utf-8""?>
<package xmlns=""http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"">
<metadata>
Expand Down Expand Up @@ -916,5 +937,28 @@ public void Should_throw_exception_on_icon_element()
<files>
</files>
</package>";

private const string NuspecContentWithFormatableMinClientVersion = @"<?xml version=""1.0"" encoding=""utf-8""?>
<package xmlns=""http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"">
<metadata minClientVersion=""{0}"">
<id>test-package</id>
<title>Test Package</title>
<version>0.1.0</version>
<authors>package author</authors>
<owners>package owner</owners>
<summary>A brief summary</summary>
<description>A big description</description>
<tags>test admin</tags>
<copyright></copyright>
<licenseUrl>http://apache.org/2</licenseUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<releaseNotes></releaseNotes>
<dependencies>
<dependency id=""chocolatey-core.extension"" />
</dependencies>
</metadata>
<files>
</files>
</package>";
}
}
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 ced3b70

Please sign in to comment.