Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Edyoung/issue 349 catastrophic #407

Merged
merged 3 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
82 changes: 76 additions & 6 deletions Tests/PSGetUpdateModule.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,76 @@ function SuiteCleanup {
}
}

Describe UpdateModuleFromAlternateRepo -Tags 'BVT' {
BeforeAll {
SuiteSetup
}

AfterAll {
SuiteCleanup
}

AfterEach {
PSGetTestUtils\Uninstall-Module ContosoServer
PSGetTestUtils\Uninstall-Module ContosoClient
}

It "Check that removing a slash from a repo doesn't break update" {
$withSlash = "https://www.poshtestgallery.com/api/v2/"
$noSlash = "https://www.poshtestgallery.com/api/v2"
#Write-Host (Get-PSRepository | Out-String)
(Get-PSRepository PSGallery).SourceLocation | Should Be $withSlash

Install-Module ContosoServer -RequiredVersion 1.0
(Get-InstalledModule ContosoServer).RepositorySourceLocation | Should Be $withSlash
#Write-Host (Get-InstalledModule ContosoServer -AllVersions | Format-List | Out-String)

# now update where PSGallery Source Location is
Set-PSGallerySourceLocation -Location $noSlash
#Write-Host (Get-PSRepository | Out-String)
(Get-PSRepository PSGallery).SourceLocation | Should Be $noSlash

# reload powershellget to force-update cached repository info
Import-Module PowerShellGet -Force

# now try and update module isntalled using other SourceLocation
Update-Module ContosoServer -RequiredVersion 2.0 -ErrorAction Stop
#Write-Host (Get-InstalledModule ContosoServer -AllVersions | Format-List | Out-String)
(Get-InstalledModule ContosoServer).RepositorySourceLocation | Should Be $noSlash

(Get-InstalledModule ContosoServer).Version | Should Be 2.0
}

It "Check that adding a slash to a repo doesn't break update" {
$withSlash = "https://www.poshtestgallery.com/api/v2/"
$noSlash = "https://www.poshtestgallery.com/api/v2"
#Write-Host (Get-PSRepository | Out-String)

Set-PSGallerySourceLocation -Location $noSlash

(Get-PSRepository PSGallery).SourceLocation | Should Be $noSlash

Install-Module ContosoServer -RequiredVersion 1.0
(Get-InstalledModule ContosoServer).RepositorySourceLocation | Should Be $noSlash
#Write-Host (Get-InstalledModule ContosoServer -AllVersions | Format-List | Out-String)

# now update where PSGallery Source Location is
Set-PSGallerySourceLocation -Location $withSlash
#Write-Host (Get-PSRepository | Out-String)
(Get-PSRepository PSGallery).SourceLocation | Should Be $withSlash

# reload powershellget to force-update cached repository info
Import-Module PowerShellGet -Force

# now try and update module isntalled using other SourceLocation
Update-Module ContosoServer -RequiredVersion 2.0 -ErrorAction Stop
#Write-Host (Get-InstalledModule ContosoServer -AllVersions | Format-List | Out-String)
(Get-InstalledModule ContosoServer).RepositorySourceLocation | Should Be $withSlash

(Get-InstalledModule ContosoServer).Version | Should Be 2.0
}
}

Describe PowerShell.PSGet.UpdateModuleTests -Tags 'BVT','InnerLoop' {

BeforeAll {
Expand Down Expand Up @@ -350,7 +420,7 @@ Describe PowerShell.PSGet.UpdateModuleTests -Tags 'BVT','InnerLoop' {
}

Describe PowerShell.PSGet.UpdateModuleTests.P1 -Tags 'P1','OuterLoop' {
# Not executing these tests on MacOS as
# Not executing these tests on MacOS as
# the total execution time is exceeding allowed 50 min in TravisCI daily builds.
if($IsMacOS) {
return
Expand All @@ -376,13 +446,13 @@ Describe PowerShell.PSGet.UpdateModuleTests.P1 -Tags 'P1','OuterLoop' {
# Expected Result: both modules should be refreshed
#
It "UpdateMultipleModulesWithWildcard" {

Install-Module ContosoClient -RequiredVersion 1.0

$contosoClientDetails = Get-InstalledModule -Name ContosoClient

Install-Module ContosoServer -RequiredVersion 1.0

$MyError = $null
$DateTimeBeforeUpdate = Get-Date

Expand All @@ -391,7 +461,7 @@ Describe PowerShell.PSGet.UpdateModuleTests.P1 -Tags 'P1','OuterLoop' {
Assert ($MyError.Count -eq 0) "There should not be any error when updating multiple modules with wildcard in name, $MyError"
$res = Get-InstalledModule -Name ContosoServer -MinimumVersion "1.1"
Assert ($res -and ($res.Name -eq "ContosoServer") -and ($res.Version -gt [Version]"1.0")) "Update-Module should update when wildcard specified in name"

$res = Get-InstalledModule -Name ContosoClient -MinimumVersion "1.1"
Assert ($res -and ($res.Name -eq "ContosoClient") -and ($res.Version -gt [Version]"1.0")) "Update-Module should update when wildcard specified in name"

Expand Down Expand Up @@ -457,7 +527,7 @@ Describe PowerShell.PSGet.UpdateModuleTests.P1 -Tags 'P1','OuterLoop' {

Describe PowerShell.PSGet.UpdateModuleTests.P2 -Tags 'P2','OuterLoop' {

# Not executing these tests on MacOS as
# Not executing these tests on MacOS as
# the total execution time is exceeding allowed 50 min in TravisCI daily builds.
if($IsMacOS) {
return
Expand Down
19 changes: 8 additions & 11 deletions src/PowerShellGet/private/functions/Get-SourceName.ps1
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
function Get-SourceName
{
function Get-SourceName {
[CmdletBinding()]
[OutputType("string")]
Param
(
[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$Location
)

Set-ModuleSourcesVariable

foreach($psModuleSource in $script:PSGetModuleSources.Values)
{
if(($psModuleSource.Name -eq $Location) -or
($psModuleSource.SourceLocation -eq $Location) -or
((Get-Member -InputObject $psModuleSource -Name $script:ScriptSourceLocation) -and
($psModuleSource.ScriptSourceLocation -eq $Location)))
{
foreach ($psModuleSource in $script:PSGetModuleSources.Values) {
if (($psModuleSource.Name -eq $Location) -or
(Test-EquivalentLocation -LocationA $psModuleSource.SourceLocation -LocationB $Location) -or
((Get-Member -InputObject $psModuleSource -Name $script:ScriptSourceLocation) -and
(Test-EquivalentLocation -LocationA $psModuleSource.ScriptSourceLocation -LocationB $Location))) {
return $psModuleSource.Name
}
}
}
}
18 changes: 18 additions & 0 deletions src/PowerShellGet/private/functions/Test-EquivalentLocation.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

# Compare 2 strings, ignoring any trailing slashes or backslashes.
# This is not exactly the same as URL or path equivalence but it should work in practice
function Test-EquivalentLocation {
[CmdletBinding()]
[OutputType("bool")]
param(
[Parameter(Mandatory = $false)]
[string]$LocationA,

[Parameter(Mandatory = $false)]
[string]$LocationB
)

$LocationA = $LocationA.TrimEnd("\/")
$LocationB = $LocationB.TrimEnd("\/")
return $LocationA -eq $LocationB
}