diff --git a/src/chocolatey.tests/infrastructure.app/nuget/NugetCommonSpecs.cs b/src/chocolatey.tests/infrastructure.app/nuget/NugetCommonSpecs.cs index 0ec5be524..6821e0479 100644 --- a/src/chocolatey.tests/infrastructure.app/nuget/NugetCommonSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/nuget/NugetCommonSpecs.cs @@ -127,7 +127,7 @@ public void Should_parse_relative_path_source() { Context(); var source = "choco"; - var fullsource = "C:\\packages\\choco"; + var fullsource = "C:\\packages\\choco\\"; _configuration.Sources = source; _because(); diff --git a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs index 3b76c8832..07ddfa20d 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs @@ -18,6 +18,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.ComponentModel; +using System.IO; using System.Linq; using System.Net; using System.Security.Cryptography.X509Certificates; @@ -253,6 +254,13 @@ public static IEnumerable GetRemoteRepositories(ChocolateyConf // If an invalid source was passed in, we don't care here, pass it along fullsource = source; } + + // filesystem.GetFullPath sometimes resolves to `C:` instead of `C:\` which PackageSource can't handle. This corrects for that edge case. + if ( !fullsource.EndsWith(Path.DirectorySeparatorChar.ToString()) && !fullsource.EndsWith(Path.AltDirectorySeparatorChar.ToString()) ) + { + fullsource += Path.DirectorySeparatorChar; + } + nugetSource = new PackageSource(fullsource); if (!nugetSource.IsLocal) diff --git a/tests/pester-tests/scenarios/localpathsource.Tests.ps1 b/tests/pester-tests/scenarios/localpathsource.Tests.ps1 new file mode 100644 index 000000000..3105d847a --- /dev/null +++ b/tests/pester-tests/scenarios/localpathsource.Tests.ps1 @@ -0,0 +1,61 @@ +Describe "Actions from the root of a drive" -Tag Scenario { + BeforeAll { + Initialize-ChocolateyTestInstall + Push-Location '\' + Invoke-Choco new roottest --version 1.0.0 + Remove-Item roottest/tools/*.ps1 -ErrorAction SilentlyContinue + Invoke-Choco pack roottest/roottest.nuspec + } + + AfterAll { + Remove-ChocolateyTestInstall + Remove-Item roottest, roottest.1.0.0.nupkg -Force -Recurse -ErrorAction SilentlyContinue + Pop-Location + } + + Context "Searching with <_> '.' source at the root of a drive" -ForEach @('find', 'search') { + BeforeAll { + $Output = Invoke-Choco $_ --source="'.'" + } + + It 'Exits with Success (0)' { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It 'Does not output message about being unable to parse a source' { + $Output.Lines | Should -Not -Contain "Source '.' is unable to be parsed" -Because $Output.String + } + + It "Finds the package expected" { + $Output.Lines | Should -Contain "roottest 1.0.0" -Because $Output.String + } + } + + Context "Installing from '.' source using <_> at the root of a drive" -ForEach @( 'install', 'upgrade' ) { + BeforeAll { + Restore-ChocolateyInstallSnapshot + $Output = Invoke-Choco $_ roottest --source="'.'" + } + + AfterAll { + Remove-ChocolateyInstallSnapshot + } + + It 'Exits with Success (0)' { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It 'Does not output message about being unable to parse a source' { + $Output.Lines | Should -Not -Contain "Source '.' is unable to be parsed" -Because $Output.String + } + + It "Finds the package expected" { + $Output.Lines | Should -Contain "roottest v1.0.0" -Because $Output.String + } + + It "Successfully updates the package" { + $Action = $_.TrimEnd('e') + 'ed' + $Output.Lines | Should -Contain "Chocolatey $Action 1/1 packages." -Because $Output.String + } + } +}