Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/chocolatey/infrastructure.app/nuget/NugetCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -253,6 +254,13 @@ public static IEnumerable<SourceRepository> 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)
Expand Down
61 changes: 61 additions & 0 deletions tests/pester-tests/scenarios/localpathsource.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Loading