diff --git a/src/chocolatey.tests.integration/scenarios/SearchScenarios.cs b/src/chocolatey.tests.integration/scenarios/SearchScenarios.cs index c47a83a270..2fdf5d38f7 100644 --- a/src/chocolatey.tests.integration/scenarios/SearchScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/SearchScenarios.cs @@ -601,7 +601,7 @@ public void ShouldOutputWarningAboutThresholdBeingReached() { MockLogger.Messages.Should() .ContainKey(LogLevel.Warn.ToString()) - .WhoseValue.Should().ContainSingle(m => m == "The threshold of 2 packages per source has been met. Please refine your search, or specify a page to find any more results."); + .WhoseValue.Should().ContainSingle(m => m == "The threshold of 2 packages, or package versions, per source has been met. Please refine your search, or specify a page number to retrieve more results."); } [Fact] diff --git a/src/chocolatey/infrastructure.app/nuget/NugetList.cs b/src/chocolatey/infrastructure.app/nuget/NugetList.cs index 6048a023fa..595c403120 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetList.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetList.cs @@ -148,6 +148,19 @@ private async static Task> SearchPackagesAsyn { var takeNumber = GetTakeAmount(configuration); + if (takeNumber != 30) + { + var warning = "The page size has been specified to be {0:N0} packages. There are known issues with some repositories when you use a page size other than 30.".FormatWith(takeNumber); + if (configuration.RegularOutput) + { + "chocolatey".Log().Warn(warning); + } + else + { + "chocolatey".Log().Debug(warning); + } + } + var partResults = new HashSet(new ComparePackageSearchMetadataIdOnly()); var latestResults = new List(); @@ -305,13 +318,10 @@ private async static Task> SearchPackagesAsyn private static int GetTakeAmount(ChocolateyConfiguration configuration) { - // We calculate the amount of items we take at the same time, while making - // sure to take the minimum value of 30 packages which we know is a safe value - // to take from CCR and other feeds to minimize any issues that can happen. if (configuration.ListCommand.Page.HasValue || configuration.ListCommand.ExplicitPageSize) { - return Math.Min(configuration.ListCommand.PageSize, 30); + return configuration.ListCommand.PageSize; } return 30; diff --git a/tests/pester-tests/features/PageSize.Tests.ps1 b/tests/pester-tests/features/PageSize.Tests.ps1 new file mode 100644 index 0000000000..a0b846522b --- /dev/null +++ b/tests/pester-tests/features/PageSize.Tests.ps1 @@ -0,0 +1,64 @@ +Describe 'Ensuring honours page size settings' -ForEach @( + @{ + Command = 'search' + } +) -Tag PageSize { + BeforeAll { + Initialize-ChocolateyTestInstall + } + + Context 'Page size ' -ForEach @( + @{ + ExpectedExitCode = 1 + ProvidedSize = 0 + } + @{ + ExpectedExitCode = 1 + ProvidedSize = 101 + } + @{ + ExpectedExitCode = 0 + ProvidedSize = 1 + } + @{ + ExpectedExitCode = 0 + ProvidedSize = 30 + } + @{ + ExpectedExitCode = 0 + ProvidedSize = 40 + } + @{ + ExpectedExitCode = 0 + ProvidedSize = 100 + } + ) { + BeforeAll { + $Output = Invoke-Choco $Command --page-size $ProvidedSize + } + + It 'Exits correctly ()' { + $Output.ExitCode | Should -Be $ExpectedExitCode -Because $Output.String + } + + It 'Outputs expected messages' { + $ExpectedMessage = if ($ExpectedExitCode -eq 1) { + "The page size has been specified to be $ProvidedSize packages. The page size cannot be lower than 1 package, and no larger than 100 packages." + } else { + if ($ProvidedSize -ne 30) { + "The page size has been specified to be $ProvidedSize packages. There are known issues with some repositories when you use a page size other than 30." + } + # There are currently 43 test packages in the repository. + # Any number above this amount will not result in the below message. + if ($ProvidedSize -le 40) { + "The threshold of $ProvidedSize packages, or package versions, per source has been met. Please refine your search, or specify a page number to retrieve more results." + } + } + foreach ($message in $ExpectedMessage) { + # The output here may contain duplicated line for the warning about non-30 page size. + # We have been unable to reproduce this output in any scenario other than in these tests. + $Output.Lines | Should -Contain $message -Because $Output.String + } + } + } +}