Skip to content

Commit

Permalink
(#1485) Display package source during install/upgrade
Browse files Browse the repository at this point in the history
This logs the package source uri to info before downloading nupkgs
during both install and upgrade. Additionally, it debug logs the
download URI that the nupkg available at.

The information outputs for both individual package installs/upgrades,
and for dependencies that get installed/upgraded by their parent
package. This information is especially useful when multiple sources
are in play, so the user can determine where individual packages
are coming from.
  • Loading branch information
TheCakeIsNaOH committed Jan 9, 2024
1 parent a7f72e0 commit 9a36b40
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/chocolatey.tests.integration/scenarios/InstallScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,26 @@ public void Should_have_a_version_of_one_dot_zero_dot_zero()
_packageResult.Version.Should().Be(TestVersion());
}

[Fact]
public void Should_contain_message_with_source()
{
var message = "Downloading package from source '{0}'".FormatWith(Configuration.Sources);

MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToString()).WhoseValue.Should()
.Contain(message);
}

[Fact]
public void Should_contain_message_with_download_uri()
{
var packagePath = "file:///{0}/{1}.{2}{3}".FormatWith(Configuration.Sources.Replace("\\","/"), Configuration.PackageNames,
TestVersion(), NuGetConstants.PackageExtension);
var message = "Package download location '{0}'".FormatWith(packagePath);

MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToString()).WhoseValue.Should()
.Contain(message);
}

[Fact]
[WindowsOnly]
[Platform(Exclude = "Mono")]
Expand Down
20 changes: 20 additions & 0 deletions src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,26 @@ public void Should_match_the_upgrade_version_of_one_dot_one_dot_zero()
_packageResult.Version.Should().Be("1.1.0");
}

[Fact]
public void Should_contain_message_with_source()
{
var message = "Downloading package from source '{0}'".FormatWith(Configuration.Sources);

MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToString()).WhoseValue.Should()
.Contain(message);
}

[Fact]
public void Should_contain_message_with_download_uri()
{
var packagePath = "file:///{0}/{1}.{2}{3}".FormatWith(Configuration.Sources.Replace("\\", "/"), Configuration.PackageNames,
"1.1.0", NuGetConstants.PackageExtension);
var message = "Package download location '{0}'".FormatWith(packagePath);

MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToString()).WhoseValue.Should()
.Contain(message);
}

[Fact]
[WindowsOnly]
[Platform(Exclude = "Mono")]
Expand Down
6 changes: 6 additions & 0 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,9 @@ Version was specified as '{0}'. It is possible that version

_fileSystem.DeleteFile(pathResolver.GetInstalledPackageFilePath(packageDependencyInfo));

this.Log().Info("Downloading package from source '{0}'".FormatWith(packageDependencyInfo.Source));
this.Log().Debug("Package download location '{0}'".FormatWith(packageDependencyInfo.DownloadUri));

ChocolateyProgressInfo.ShouldDisplayDownloadProgress = config.Features.ShowDownloadProgress;

using (var downloadResult = downloadResource.GetDownloadResourceResultAsync(
Expand Down Expand Up @@ -1485,6 +1488,9 @@ public virtual ConcurrentDictionary<string, PackageResult> Upgrade(ChocolateyCon

_fileSystem.DeleteFile(pathResolver.GetInstalledPackageFilePath(packageDependencyInfo));

this.Log().Info("Downloading package from source '{0}'".FormatWith(packageDependencyInfo.Source));
this.Log().Debug("Package download location '{0}'".FormatWith(packageDependencyInfo.DownloadUri));

ChocolateyProgressInfo.ShouldDisplayDownloadProgress = config.Features.ShowDownloadProgress;

using (var downloadResult = downloadResource.GetDownloadResourceResultAsync(
Expand Down

0 comments on commit 9a36b40

Please sign in to comment.