From 965d7334752fe5519e4fe12a5bf29ddaba384ea9 Mon Sep 17 00:00:00 2001 From: Edwin Young Date: Wed, 23 Jan 2019 15:44:43 -0800 Subject: [PATCH 1/3] Added basic test case to demonstrate repository / problem --- Tests/PSGetUpdateModule.Tests.ps1 | 54 +++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/Tests/PSGetUpdateModule.Tests.ps1 b/Tests/PSGetUpdateModule.Tests.ps1 index 899f0bf8..3c961f69 100644 --- a/Tests/PSGetUpdateModule.Tests.ps1 +++ b/Tests/PSGetUpdateModule.Tests.ps1 @@ -77,6 +77,48 @@ function SuiteCleanup { } } +Describe UpdateModuleFromAlternateRepo -Tags 'BVT' { + BeforeAll { + SuiteSetup + } + + AfterAll { + SuiteCleanup + } + + AfterEach { + PSGetTestUtils\Uninstall-Module ContosoServer + PSGetTestUtils\Uninstall-Module ContosoClient + } + + It "Check situation" { + $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 + + } +} + Describe PowerShell.PSGet.UpdateModuleTests -Tags 'BVT','InnerLoop' { BeforeAll { @@ -350,7 +392,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 @@ -376,13 +418,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 @@ -391,7 +433,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" @@ -457,7 +499,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 From 01713cdc1cf9defaf50c9eddec623d99a69b9ccf Mon Sep 17 00:00:00 2001 From: Edwin Young Date: Wed, 23 Jan 2019 16:52:06 -0800 Subject: [PATCH 2/3] Proposed fix for location issues --- Tests/PSGetUpdateModule.Tests.ps1 | 38 ++++++++++++++++--- .../private/functions/Get-SourceName.ps1 | 19 ++++------ .../functions/Test-EquivalentLocation.ps1 | 18 +++++++++ 3 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 src/PowerShellGet/private/functions/Test-EquivalentLocation.ps1 diff --git a/Tests/PSGetUpdateModule.Tests.ps1 b/Tests/PSGetUpdateModule.Tests.ps1 index 3c961f69..c3fb18a5 100644 --- a/Tests/PSGetUpdateModule.Tests.ps1 +++ b/Tests/PSGetUpdateModule.Tests.ps1 @@ -91,19 +91,19 @@ Describe UpdateModuleFromAlternateRepo -Tags 'BVT' { PSGetTestUtils\Uninstall-Module ContosoClient } - It "Check situation" { + 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) + #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) + #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) + #Write-Host (Get-PSRepository | Out-String) (Get-PSRepository PSGallery).SourceLocation | Should Be $noSlash # reload powershellget to force-update cached repository info @@ -111,11 +111,39 @@ Describe UpdateModuleFromAlternateRepo -Tags 'BVT' { # 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) + #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 } } diff --git a/src/PowerShellGet/private/functions/Get-SourceName.ps1 b/src/PowerShellGet/private/functions/Get-SourceName.ps1 index 0cbc0ce3..89130a75 100644 --- a/src/PowerShellGet/private/functions/Get-SourceName.ps1 +++ b/src/PowerShellGet/private/functions/Get-SourceName.ps1 @@ -1,10 +1,9 @@ -function Get-SourceName -{ +function Get-SourceName { [CmdletBinding()] [OutputType("string")] Param ( - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string] $Location @@ -12,14 +11,12 @@ function Get-SourceName 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 } } -} \ No newline at end of file +} diff --git a/src/PowerShellGet/private/functions/Test-EquivalentLocation.ps1 b/src/PowerShellGet/private/functions/Test-EquivalentLocation.ps1 new file mode 100644 index 00000000..14962a8c --- /dev/null +++ b/src/PowerShellGet/private/functions/Test-EquivalentLocation.ps1 @@ -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 +} From 54b6b0ad07798616fdb4a6cb09039123f7e78ad5 Mon Sep 17 00:00:00 2001 From: Edwin Young Date: Thu, 24 Jan 2019 10:56:21 -0800 Subject: [PATCH 3/3] do-nothing update to tickle appveyor --- Tests/PSGetUpdateModule.Tests.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/Tests/PSGetUpdateModule.Tests.ps1 b/Tests/PSGetUpdateModule.Tests.ps1 index c3fb18a5..f6224a72 100644 --- a/Tests/PSGetUpdateModule.Tests.ps1 +++ b/Tests/PSGetUpdateModule.Tests.ps1 @@ -113,7 +113,6 @@ Describe UpdateModuleFromAlternateRepo -Tags 'BVT' { 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 } @@ -142,7 +141,6 @@ Describe UpdateModuleFromAlternateRepo -Tags 'BVT' { 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 } }