diff --git a/test/FindPSResource.Tests.ps1 b/test/FindPSResource.Tests.ps1 index c0a70f063..9d946b33b 100644 --- a/test/FindPSResource.Tests.ps1 +++ b/test/FindPSResource.Tests.ps1 @@ -6,7 +6,6 @@ Import-Module "$psscriptroot\PSGetTestUtils.psm1" -Force Describe 'Test Find-PSResource for Module' { BeforeAll{ - $TestGalleryName = Get-PoshTestGalleryName $PSGalleryName = Get-PSGalleryName $NuGetGalleryName = Get-NuGetGalleryName $testModuleName = "test_module" @@ -54,23 +53,36 @@ Describe 'Test Find-PSResource for Module' { $foundScript | Should -BeTrue } - It "should find all resources given Name that equals wildcard, '*'" { - $foundResources = Find-PSResource -Name "*" -Repository "PoshTestGallery" - - # Should find Module and Script resources but no prerelease resources - $foundResources | where-object Name -eq "test_module" | Should -Not -BeNullOrEmpty -Because "test_module should exist in PoshTestGallery" - $foundResources | where-object Name -eq "test_script" | Should -Not -BeNullOrEmpty -Because "test_script should exist in PoshTestGallery" - $foundResources | where-object IsPrerelease -eq $true | Should -BeNullOrEmpty -Because "No prerelease resources should be returned" - } - - It "should find all resources (including prerelease) given Name that equals wildcard, '*' and Prerelease parameter" { - $foundResources = Find-PSResource -Name "*" -Prerelease -Repository "PoshTestGallery" - - # Should find Module and Script resources inlcuding prerelease resources - $foundResources | where-object Name -eq "test_module" | Should -Not -BeNullOrEmpty -Because "test_module should exist in PoshTestGallery" - $foundResources | where-object Name -eq "test_script" | Should -Not -BeNullOrEmpty -Because "test_script should exist in PoshTestGallery" - $foundResources | where-object IsPrerelease -eq $true | Should -Not -BeNullOrEmpty -Because "Prerelease resources should be returned" - } + # TODO: get working with local repo + # It "should find all resources given Name that equals wildcard, '*'" { + # $repoName = "psgettestlocal" + # Get-ModuleResourcePublishedToLocalRepoTestDrive "TestLocalModule1" $repoName + # Get-ModuleResourcePublishedToLocalRepoTestDrive "TestLocalModule2" $repoName + # Get-ModuleResourcePublishedToLocalRepoTestDrive "TestLocalModule3" $repoName + + # $foundResources = Find-PSResource -Name "TestLocalModule1","TestLocalModule2","TestLocalModule3" -Repository $repoName + # # TODO: wildcard search is not supported with local repositories, from NuGet protocol API side- ask about this. + # # $foundResources = Find-PSResource -Name "*" -Repository $repoName + # $foundResources.Count | Should -Not -Be 0 + + # # Should find Module and Script resources but no prerelease resources + # $foundResources | where-object Name -eq "TestLocalModule1" | Should -Not -BeNullOrEmpty -Because "TestLocalModule1 should exist in local repo" + # $foundResources | where-object Name -eq "test_script" | Should -Not -BeNullOrEmpty -Because "TestLocalScript1 should exist in local repo" + # $foundResources | where-object IsPrerelease -eq $true | Should -BeNullOrEmpty -Because "No prerelease resources should be returned" + # } + + # # TODO: get working with local repo + # It "should find all resources (including prerelease) given Name that equals wildcard, '*' and Prerelease parameter" { + # Get-ModuleResourcePublishedToLocalRepoTestDrive "TestLocalModule1" $repoName + # Get-ModuleResourcePublishedToLocalRepoTestDrive "TestLocalModule2" $repoName + # Get-ModuleResourcePublishedToLocalRepoTestDrive "TestLocalModule3" $repoName + # $foundResources = Find-PSResource -Name "*" -Prerelease -Repository $repoName + + # # Should find Module and Script resources inlcuding prerelease resources + # $foundResources | where-object Name -eq "test_module" | Should -Not -BeNullOrEmpty -Because "test_module should exist in local repo" + # $foundResources | where-object Name -eq "test_script" | Should -Not -BeNullOrEmpty -Because "test_script should exist in local repo" + # $foundResources | where-object IsPrerelease -eq $true | Should -Not -BeNullOrEmpty -Because "Prerelease resources should be returned" + # } It "find resource given Name from V3 endpoint repository (NuGetGallery)" { $res = Find-PSResource -Name "Serilog" -Repository $NuGetGalleryName @@ -86,18 +98,18 @@ Describe 'Test Find-PSResource for Module' { $testCases2 = @{Version="[5.0.0.0]"; ExpectedVersions=@("5.0.0.0"); Reason="validate version, exact match"}, @{Version="5.0.0.0"; ExpectedVersions=@("5.0.0.0"); Reason="validate version, exact match without bracket syntax"}, - @{Version="[2.5.0.0, 5.0.0.0]"; ExpectedVersions=@("2.5.0.0", "3.0.0.0", "4.0.0.0", "5.0.0.0"); Reason="validate version, exact range inclusive"}, - @{Version="(2.5.0.0, 5.0.0.0)"; ExpectedVersions=@("3.0.0.0", "4.0.0.0"); Reason="validate version, exact range exclusive"}, - @{Version="(2.5.0.0,)"; ExpectedVersions=@("3.0.0.0", "4.0.0.0", "5.0.0.0"); Reason="validate version, minimum version exclusive"}, - @{Version="[2.5.0.0,)"; ExpectedVersions=@("2.5.0.0", "3.0.0.0", "4.0.0.0", "5.0.0.0"); Reason="validate version, minimum version inclusive"}, - @{Version="(,2.5.0.0)"; ExpectedVersions=@("1.2.0.0", "1.5.0.0", "2.0.0.0"); Reason="validate version, maximum version exclusive"}, - @{Version="(,2.0.0.0]"; ExpectedVersions=@("1.2.0.0", "1.5.0.0", "2.0.0.0", "2.5.0.0"); Reason="validate version, maximum version inclusive"}, - @{Version="[2.5.0.0, 5.0.0.0)"; ExpectedVersions=@("2.5.0.0", "3.0.0.0", "4.0.0.0"); Reason="validate version, mixed inclusive minimum and exclusive maximum version"} - @{Version="(2.5.0.0, 5.0.0.0]"; ExpectedVersions=@("3.0.0.0", "4.0.0.0", "5.0.0.0"); Reason="validate version, mixed exclusive minimum and inclusive maximum version"} + @{Version="[1.0.0.0, 5.0.0.0]"; ExpectedVersions=@("1.0.0.0", "3.0.0.0", "5.0.0.0"); Reason="validate version, exact range inclusive"}, + @{Version="(1.0.0.0, 5.0.0.0)"; ExpectedVersions=@("3.0.0.0"); Reason="validate version, exact range exclusive"}, + @{Version="(1.0.0.0,)"; ExpectedVersions=@("3.0.0.0", "5.0.0.0"); Reason="validate version, minimum version exclusive"}, + @{Version="[1.0.0.0,)"; ExpectedVersions=@("1.0.0.0", "3.0.0.0", "5.0.0.0"); Reason="validate version, minimum version inclusive"}, + @{Version="(,3.0.0.0)"; ExpectedVersions=@("1.0.0.0"); Reason="validate version, maximum version exclusive"}, + @{Version="(,3.0.0.0]"; ExpectedVersions=@("1.0.0.0", "3.0.0.0"); Reason="validate version, maximum version inclusive"}, + @{Version="[1.0.0.0, 5.0.0.0)"; ExpectedVersions=@("1.0.0.0", "3.0.0.0"); Reason="validate version, mixed inclusive minimum and exclusive maximum version"} + @{Version="(1.0.0.0, 5.0.0.0]"; ExpectedVersions=@("3.0.0.0", "5.0.0.0"); Reason="validate version, mixed exclusive minimum and inclusive maximum version"} It "find resource when given Name to " -TestCases $testCases2{ param($Version, $ExpectedVersions) - $res = Find-PSResource -Name $testModuleName -Version $Version -Repository $TestGalleryName + $res = Find-PSResource -Name $testModuleName -Version $Version -Repository $PSGalleryName foreach ($item in $res) { $item.Name | Should -Be $testModuleName $ExpectedVersions | Should -Contain $item.Version @@ -105,8 +117,8 @@ Describe 'Test Find-PSResource for Module' { } It "not find resource with incorrectly formatted version such as " -TestCases @( - @{Version='(2.5.0.0)'; Description="exclusive version (2.5.0.0)"}, - @{Version='[2-5-0-0]'; Description="version formatted with invalid delimiter"} + @{Version='(1.0.0.0)'; Description="exclusive version (2.5.0.0)"}, + @{Version='[1-0-0-0]'; Description="version formatted with invalid delimiter"} ) { param($Version, $Description) @@ -114,24 +126,24 @@ Describe 'Test Find-PSResource for Module' { $res | Should -BeNullOrEmpty } - $testCases = @{Version='[2.*.0.0]'; Description="version with wilcard in middle"}, - @{Version='[*.5.0.0]'; Description="version with wilcard at start"}, - @{Version='[2.5.*.0]'; Description="version with wildcard at third digit"} - @{Version='[2.5.0.*'; Description="version with wildcard at end"}, - @{Version='[2..0.0]'; Description="version with missing digit in middle"}, - @{Version='[2.5.0.]'; Description="version with missing digit at end"}, - @{Version='[2.5.0.0.0]'; Description="version with more than 4 digits"} + $testCases = @{Version='[1.*.0.0]'; Description="version with wilcard in middle"}, + @{Version='[*.0.0.0]'; Description="version with wilcard at start"}, + @{Version='[1.0.*.0]'; Description="version with wildcard at third digit"} + @{Version='[1.0.0.*'; Description="version with wildcard at end"}, + @{Version='[1..0.0]'; Description="version with missing digit in middle"}, + @{Version='[1.0.0.]'; Description="version with missing digit at end"}, + @{Version='[1.0.0.0.0]'; Description="version with more than 4 digits"} It "not find resource and throw exception with incorrectly formatted version such as " -TestCases $testCases { param($Version, $Description) - Find-PSResource -Name $testModuleName -Version $Version -Repository $TestGalleryName -ErrorVariable err -ErrorAction SilentlyContinue + Find-PSResource -Name $testModuleName -Version $Version -Repository $PSGalleryName -ErrorVariable err -ErrorAction SilentlyContinue $err.Count | Should -Not -Be 0 $err[0].FullyQualifiedErrorId | Should -BeExactly "IncorrectVersionFormat,Microsoft.PowerShell.PowerShellGet.Cmdlets.FindPSResource" } - It "find resources when given Name, Version not null --> '*'" { - $res = Find-PSResource -Name $testModuleName -Version "*" -Repository $TestGalleryName + It "find all versions of resource when given Name, Version not null --> '*'" { + $res = Find-PSResource -Name $testModuleName -Version "*" -Repository $PSGalleryName $res | ForEach-Object { $_.Name | Should -Be $testModuleName } @@ -139,7 +151,7 @@ Describe 'Test Find-PSResource for Module' { } It "find resources when given Name with wildcard, Version not null --> '*'" { - $res = Find-PSResource -Name "TestModuleWithDependency*" -Version "*" -Repository $TestGalleryName + $res = Find-PSResource -Name "TestModuleWithDependency*" -Version "*" -Repository $PSGalleryName $moduleA = $res | Where-Object {$_.Name -eq "TestModuleWithDependencyA"} $moduleA.Count | Should -BeGreaterOrEqual 3 $moduleB = $res | Where-Object {$_.Name -eq "TestModuleWithDependencyB"} @@ -155,51 +167,105 @@ Describe 'Test Find-PSResource for Module' { } It "find resources when given Name with wildcard, Version range" { - $res = Find-PSResource -Name "TestModuleWithDependency*" -Version "[1.0.0.0, 2.0.0.0]" -Repository $TestGalleryName + $res = Find-PSResource -Name "TestModuleWithDependency*" -Version "[1.0.0.0, 5.0.0.0]" -Repository $PSGalleryName foreach ($pkg in $res) { $pkg.Name | Should -Match "TestModuleWithDependency*" - [System.Version]$pkg.Version -ge [System.Version]"1.0.0.0" -or [System.Version]$pkg.Version -le [System.Version]"2.0.0.0" | Should -Be $true + [System.Version]$pkg.Version -ge [System.Version]"1.0.0.0" -or [System.Version]$pkg.Version -le [System.Version]"5.0.0.0" | Should -Be $true } } It "find resource when given Name, Version param null" { - $res = Find-PSResource -Name $testModuleName -Repository $TestGalleryName + $res = Find-PSResource -Name $testModuleName -Repository $PSGalleryName $res.Name | Should -Be $testModuleName $res.Version | Should -Be "5.0.0.0" } It "find resource with latest (including prerelease) version given Prerelease parameter" { # test_module resource's latest version is a prerelease version, before that it has a non-prerelease version - $res = Find-PSResource -Name $testModuleName -Repository $TestGalleryName + $res = Find-PSResource -Name $testModuleName -Repository $PSGalleryName $res.Version | Should -Be "5.0.0.0" - $resPrerelease = Find-PSResource -Name $testModuleName -Prerelease -Repository $TestGalleryName + $resPrerelease = Find-PSResource -Name $testModuleName -Prerelease -Repository $PSGalleryName $resPrerelease.Version | Should -Be "5.2.5.0" $resPrerelease.Prerelease | Should -Be "alpha001" } It "find resources, including Prerelease version resources, when given Prerelease parameter" { - $resWithoutPrerelease = Find-PSResource -Name $testModuleName -Version "*" -Repository $TestGalleryName - $resWithPrerelease = Find-PSResource -Name $testModuleName -Version "*" -Repository $TestGalleryName + $resWithoutPrerelease = Find-PSResource -Name $testModuleName -Version "*" -Repository $PSGalleryName + $resWithPrerelease = Find-PSResource -Name $testModuleName -Version "*" -Repository $PSGalleryName $resWithPrerelease.Count | Should -BeGreaterOrEqual $resWithoutPrerelease.Count } - It "find resource of Type script or module from PSGallery/PoshTestGallery, when no Type parameter provided" { - $resScript = Find-PSResource -Name "AzureSqlScale" -Repository $PSGalleryName - $resScript.Name | Should -Be "AzureSqlScale" - $resScript.Type | Should -Be "Script" + It "find resource and its dependency resources with IncludeDependencies parameter" { + $resWithoutDependencies = Find-PSResource -Name "TestModuleWithDependencyE" -Repository $PSGalleryName + $resWithoutDependencies.Count | Should -Be 1 + $resWithoutDependencies.Name | Should -Be "TestModuleWithDependencyE" + + # TestModuleWithDependencyE has the following dependencies: + # TestModuleWithDependencyC <= 1.0.0.0 + # TestModuleWithDependencyB >= 1.0.0.0 + # TestModuleWithDependencyD <= 1.0.0.0 - $resModule = Find-PSResource -Name $testModuleName -Repository $TestGalleryName + $resWithDependencies = Find-PSResource -Name "TestModuleWithDependencyE" -IncludeDependencies -Repository $PSGalleryName + $resWithDependencies.Count | Should -BeGreaterThan $resWithoutDependencies.Count + + $foundParentPkgE = $false + $foundDepB = $false + $foundDepBCorrectVersion = $false + $foundDepC = $false + $foundDepCCorrectVersion = $false + $foundDepD = $false + $foundDepDCorrectVersion = $false + foreach ($pkg in $resWithDependencies) + { + if ($pkg.Name -eq "TestModuleWithDependencyE") + { + $foundParentPkgE = $true + } + elseif ($pkg.Name -eq "TestModuleWithDependencyC") + { + $foundDepC = $true + $foundDepCCorrectVersion = [System.Version]$pkg.Version -le [System.Version]"1.0.0.0" + } + elseif ($pkg.Name -eq "TestModuleWithDependencyB") + { + $foundDepB = $true + $foundDepBCorrectVersion = [System.Version]$pkg.Version -ge [System.Version]"3.0.0.0" + } + elseif ($pkg.Name -eq "TestModuleWithDependencyD") + { + $foundDepD = $true + $foundDepDCorrectVersion = [System.Version]$pkg.Version -le [System.Version]"1.0.0.0" + } + } + + $foundParentPkgE | Should -Be $true + $foundDepC | Should -Be $true + $foundDepCCorrectVersion | Should -Be $true + $foundDepB | Should -Be $true + $foundDepBCorrectVersion | Should -Be $true + $foundDepD | Should -Be $true + $foundDepDCorrectVersion | Should -Be $true + } + + It "find resource of Type script or module from PSGallery, when no Type parameter provided" { + $resScript = Find-PSResource -Name $testScriptName -Repository $PSGalleryName + $resScript.Name | Should -Be $testScriptName + $resScriptType = Out-String -InputObject $resScript.Type + $resScriptType.Replace(",", " ").Split() | Should -Contain "Script" + + $resModule = Find-PSResource -Name $testModuleName -Repository $PSGalleryName $resModule.Name | Should -Be $testModuleName $resModuleType = Out-String -InputObject $resModule.Type $resModuleType.Replace(",", " ").Split() | Should -Contain "Module" } It "find resource of Type Script from PSGallery, when Type Script specified" { - $resScript = Find-PSResource -Name "AzureSqlScale" -Repository $PSGalleryName -Type "Script" - $resScript.Name | Should -Be "AzureSqlScale" + $resScript = Find-PSResource -Name $testScriptName -Repository $PSGalleryName -Type "Script" + $resScript.Name | Should -Be $testScriptName $resScript.Repository | Should -Be "PSGalleryScripts" - $resScript.Type | Should -Be "Script" + $resScriptType = Out-String -InputObject $resScript.Type + $resScriptType.Replace(",", " ").Split() | Should -Contain "Script" } It "find resource of Type Command from PSGallery, when Type Command specified" { @@ -210,10 +276,9 @@ Describe 'Test Find-PSResource for Module' { } } - # Skip test for now because it takes too long to run (> 60 sec) It "find all resources of Type Module when Type parameter set is used" -Skip { $foundScript = $False - $res = Find-PSResource -Type Module -Repository $PSGalleryName + $res = Find-PSResource -Name "test*" -Type Module -Repository $PSGalleryName $res.Count | Should -BeGreaterThan 1 foreach ($item in $res) { if ($item.Type -eq "Script") @@ -237,7 +302,7 @@ Describe 'Test Find-PSResource for Module' { $foundTestModule = $False $foundTestScript = $False $tagToFind = "Tag2" - $res = Find-PSResource -Tag $tagToFind -Repository $TestGalleryName + $res = Find-PSResource -Tag $tagToFind -Repository $PSGalleryName foreach ($item in $res) { $item.Tags -contains $tagToFind | Should -Be $True @@ -256,21 +321,6 @@ Describe 'Test Find-PSResource for Module' { $foundTestScript | Should -Be $True } - It "find resource with IncludeDependencies parameter" { - $res = Find-PSResource -Name "Az.Compute" -IncludeDependencies -Repository $PSGalleryName - $isDependencyNamePresent = $False - $isDependencyVersionCorrect = $False - foreach ($item in $res) { - if ($item.Name -eq "Az.Accounts") - { - $isDependencyNamePresent = $True - $isDependencyVersionCorrect = [System.Version]$item.Version -ge [System.Version]"2.2.8.0" - } - } - $isDependencyNamePresent | Should -BeTrue - $isDependencyVersionCorrect | Should -BeTrue - } - It "find resource in local repository given Repository parameter" { $publishModuleName = "TestFindModule" $repoName = "psgettestlocal" @@ -297,14 +347,14 @@ Describe 'Test Find-PSResource for Module' { $resNonDefault.Repository | Should -Be $repoLowerPriorityRanking } - # Skip test for now because it takes too run (132.24 sec) - It "find resource given CommandName (CommandNameParameterSet)" -Skip { - $res = Find-PSResource -CommandName $commandName -Repository $PSGalleryName - foreach ($item in $res) { - $item.Name | Should -Be $commandName - $item.ParentResource.Includes.Command | Should -Contain $commandName - } - } + # # Skip test for now because it takes too run (132.24 sec) + # It "find resource given CommandName (CommandNameParameterSet)" -Skip { + # $res = Find-PSResource -CommandName $commandName -Repository $PSGalleryName + # foreach ($item in $res) { + # $item.Name | Should -Be $commandName + # $item.ParentResource.Includes.Command | Should -Contain $commandName + # } + # } It "find resource given CommandName and ModuleName (CommandNameParameterSet)" { $res = Find-PSResource -CommandName $commandName -ModuleName $parentModuleName -Repository $PSGalleryName @@ -314,13 +364,13 @@ Describe 'Test Find-PSResource for Module' { } # Skip test for now because it takes too long to run (> 60 sec) - It "find resource given DSCResourceName (DSCResourceNameParameterSet)" -Skip { - $res = Find-PSResource -DscResourceName $dscResourceName -Repository $PSGalleryName - foreach ($item in $res) { - $item.Name | Should -Be $dscResourceName - $item.ParentResource.Includes.DscResource | Should -Contain $dscResourceName - } - } + # It "find resource given DSCResourceName (DSCResourceNameParameterSet)" -Skip { + # $res = Find-PSResource -DscResourceName $dscResourceName -Repository $PSGalleryName + # foreach ($item in $res) { + # $item.Name | Should -Be $dscResourceName + # $item.ParentResource.Includes.DscResource | Should -Contain $dscResourceName + # } + # } It "find resource given DscResourceName and ModuleName (DSCResourceNameParameterSet)" { $res = Find-PSResource -DscResourceName $dscResourceName -ModuleName $parentModuleName -Repository $PSGalleryName diff --git a/test/GetInstalledPSResource.Tests.ps1 b/test/GetInstalledPSResource.Tests.ps1 index 986f25c59..1f3492921 100644 --- a/test/GetInstalledPSResource.Tests.ps1 +++ b/test/GetInstalledPSResource.Tests.ps1 @@ -7,19 +7,21 @@ Import-Module "$psscriptroot\PSGetTestUtils.psm1" -Force Describe 'Test Get-PSResource for Module' { BeforeAll{ - $TestGalleryName = Get-PoshTestGalleryName + $PSGalleryName = Get-PSGalleryName $testModuleName = "test_module" $testScriptName = "test_script" Get-NewPSResourceRepositoryFile - Install-PSResource -Name ContosoServer -Repository $TestGalleryName -Verbose - Install-PSResource ContosoServer -Repository $TestGalleryName -TrustRepository -Version "2.0" - Install-PSResource ContosoServer -Repository $TestGalleryName -TrustRepository -Version "1.5" - Install-PSResource ContosoServer -Repository $TestGalleryName -TrustRepository -Version "1.0" - Install-PSResource TestTestScript -Repository $TestGalleryName -TrustRepository + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository -Verbose + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository -Version "1.0" + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository -Version "3.0" + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository -Version "5.0" + Install-PSResource -Name $testScriptName -Repository $PSGalleryName -TrustRepository } AfterAll { + Uninstall-PSResource -Name $testModuleName -Version "*" + Uninstall-PSResource -Name $testScriptName -Version "*" Get-RevertPSResourceRepositoryFile } @@ -29,59 +31,59 @@ Describe 'Test Get-PSResource for Module' { } It "Get specific module resource by name" { - $pkg = Get-PSResource -Name ContosoServer - $pkg.Name | Should -Contain "ContosoServer" + $pkg = Get-PSResource -Name $testModuleName + $pkg.Name | Should -Contain $testModuleName } It "Get specific script resource by name" { - $pkg = Get-PSResource -Name TestTestScript - $pkg.Name | Should -Be "TestTestScript" + $pkg = Get-PSResource -Name $testScriptName + $pkg.Name | Should -Be $testScriptName } It "Get resource when given Name to " -TestCases @( - @{Name="*tosoSer*"; ExpectedName="ContosoServer"; Reason="validate name, with wildcard at beginning and end of name: *tosoSer*"}, - @{Name="ContosoSer*"; ExpectedName="ContosoServer"; Reason="validate name, with wildcard at end of name: ContosoSer*"}, - @{Name="*tosoServer"; ExpectedName="ContosoServer"; Reason="validate name, with wildcard at beginning of name: *tosoServer"}, - @{Name="Cont*erver"; ExpectedName="ContosoServer"; Reason="validate name, with wildcard in middle of name: Cont*erver"} + @{Name="*est_modul*"; ExpectedName=$testModuleName; Reason="validate name, with wildcard at beginning and end of name: *est_modul*"}, + @{Name="test_mod*"; ExpectedName=$testModuleName; Reason="validate name, with wildcard at end of name: test_mod*"}, + @{Name="*est_module"; ExpectedName=$testModuleName; Reason="validate name, with wildcard at beginning of name: *est_module"}, + @{Name="tes*ule"; ExpectedName=$testModuleName; Reason="validate name, with wildcard in middle of name: tes*ule"} ) { param($Version, $ExpectedVersion) $pkgs = Get-PSResource -Name $Name - $pkgs.Name | Should -Contain "ContosoServer" + $pkgs.Name | Should -Contain $testModuleName } $testCases = - @{Version="[2.0.0.0]"; ExpectedVersion="2.0.0.0"; Reason="validate version, exact match"}, - @{Version="2.0.0.0"; ExpectedVersion="2.0.0.0"; Reason="validate version, exact match without bracket syntax"}, - @{Version="[1.0.0.0, 2.5.0.0]"; ExpectedVersion=@("2.5.0.0", "2.0.0.0", "1.5.0.0", "1.0.0.0"); Reason="validate version, exact range inclusive"}, - @{Version="(1.0.0.0, 2.5.0.0)"; ExpectedVersion=@("2.0.0.0", "1.5.0.0"); Reason="validate version, exact range exclusive"}, - @{Version="(1.0.0.0,)"; ExpectedVersion=@("2.5.0.0", "2.0.0.0", "1.5.0.0"); Reason="validate version, minimum version exclusive"}, - @{Version="[1.0.0.0,)"; ExpectedVersion=@("2.5.0.0", "2.0.0.0", "1.5.0.0", "1.0.0.0"); Reason="validate version, minimum version inclusive"}, - @{Version="(,1.5.0.0)"; ExpectedVersion="1.0.0.0"; Reason="validate version, maximum version exclusive"}, - @{Version="(,1.5.0.0]"; ExpectedVersion=@("1.5.0.0", "1.0.0.0"); Reason="validate version, maximum version inclusive"}, - @{Version="[1.0.0.0, 2.5.0.0)"; ExpectedVersion=@("2.0.0.0", "1.5.0.0", "1.0.0.0"); Reason="validate version, mixed inclusive minimum and exclusive maximum version"} + @{Version="[1.0.0.0]"; ExpectedVersion="1.0.0.0"; Reason="validate version, exact match"}, + @{Version="1.0.0.0"; ExpectedVersion="1.0.0.0"; Reason="validate version, exact match without bracket syntax"}, + @{Version="[1.0.0.0, 5.0.0.0]"; ExpectedVersion=@("5.0.0.0", "3.0.0.0", "1.0.0.0"); Reason="validate version, exact range inclusive"}, + @{Version="(1.0.0.0, 5.0.0.0)"; ExpectedVersion=@("3.0.0.0"); Reason="validate version, exact range exclusive"}, + @{Version="(1.0.0.0,)"; ExpectedVersion=@("5.0.0.0", "3.0.0.0"); Reason="validate version, minimum version exclusive"}, + @{Version="[1.0.0.0,)"; ExpectedVersion=@("5.0.0.0", "3.0.0.0", "1.0.0.0"); Reason="validate version, minimum version inclusive"}, + @{Version="(,5.0.0.0)"; ExpectedVersion=@("3.0.0.0", "1.0.0.0"); Reason="validate version, maximum version exclusive"}, + @{Version="(,5.0.0.0]"; ExpectedVersion=@("5.0.0.0", "3.0.0.0", "1.0.0.0"); Reason="validate version, maximum version inclusive"}, + @{Version="[1.0.0.0, 5.0.0.0)"; ExpectedVersion=@("3.0.0.0", "1.0.0.0"); Reason="validate version, mixed inclusive minimum and exclusive maximum version"} It "Get resource when given Name to " -TestCases $testCases { param($Version, $ExpectedVersion) - $pkgs = Get-PSResource -Name "ContosoServer" -Version $Version - $pkgs.Name | Should -Contain "ContosoServer" + $pkgs = Get-PSResource -Name $testModuleName -Version $Version + $pkgs.Name | Should -Contain $testModuleName $pkgs.Version | Should -Be $ExpectedVersion } It "Throw invalid version error when passing incorrectly formatted version such as " -TestCases @( @{Version='[1.*.0]'; Description="version with wilcard in middle"}, - @{Version='[*.5.0.0]'; Description="version with wilcard at start"}, + @{Version='[*.0.0.0]'; Description="version with wilcard at start"}, @{Version='[1.*.0.0]'; Description="version with wildcard at second digit"}, - @{Version='[1.5.*.0]'; Description="version with wildcard at third digit"} - @{Version='[1.5.0.*'; Description="version with wildcard at end"}, + @{Version='[1.0.*.0]'; Description="version with wildcard at third digit"} + @{Version='[1.0.0.*'; Description="version with wildcard at end"}, @{Version='[1..0.0]'; Description="version with missing digit in middle"}, - @{Version='[1.5.0.]'; Description="version with missing digit at end"}, - @{Version='[1.5.0.0.0]'; Description="version with more than 4 digits"} + @{Version='[1.0.0.]'; Description="version with missing digit at end"}, + @{Version='[1.0.0.0.0]'; Description="version with more than 4 digits"} ) { param($Version, $Description) $res = $null try { - $res = Find-PSResource -Name "ContosoServer" -Version $Version -Repository $TestGalleryName -ErrorAction Ignore + $res = Find-PSResource -Name $testModuleName -Version $Version -Repository $PSGalleryName -ErrorAction Ignore } catch {} @@ -90,15 +92,15 @@ $testCases = # These versions technically parse into proper NuGet versions, but will not return the version expected It "Does not return resource when passing incorrectly formatted version such as , does not throw error" -TestCases @( - @{Version='(1.5.0.0)'; Description="exlcusive version (8.1.0.0)"}, - @{Version='[1-5-0-0]'; Description="version formatted with invalid delimiter"} + @{Version='(1.0.0.0)'; Description="exlcusive version (8.1.0.0)"}, + @{Version='[1-0-0-0]'; Description="version formatted with invalid delimiter"} ) { param($Version, $Description) $res = $null try { - $res = Find-PSResource -Name "ContosoServer" -Version $Version -Repository $TestGalleryName -ErrorAction Ignore + $res = Find-PSResource -Name $testModuleName -Version $Version -Repository $PSGalleryName -ErrorAction Ignore } catch {} @@ -106,12 +108,12 @@ $testCases = } It "Get resources when given Name, and Version is '*'" { - $pkgs = Get-PSResource -Name ContosoServer -Version "*" + $pkgs = Get-PSResource -Name $testModuleName -Version "*" $pkgs.Count | Should -BeGreaterOrEqual 2 } It "Get prerelease version module when version with correct prerelease label is specified" { - Install-PSResource -Name $testModuleName -Version "5.2.5-alpha001" -Repository $TestGalleryName + Install-PSResource -Name $testModuleName -Version "5.2.5-alpha001" -Repository $PSGalleryName -TrustRepository $res = Get-PSResource -Name $testModuleName -Version "5.2.5" $res | Should -BeNullOrEmpty $res = Get-PSResource -Name $testModuleName -Version "5.2.5-alpha001" @@ -121,12 +123,12 @@ $testCases = } It "Get prerelease version script when version with correct prerelease label is specified" { - Install-PSResource -Name $testScriptName -Version "3.0.0-alpha001" -Repository $TestGalleryName + Install-PSResource -Name $testScriptName -Version "3.0.0-alpha" -Repository $PSGalleryName -TrustRepository $res = Get-PSResource -Name $testScriptName -Version "3.0.0" $res | Should -BeNullOrEmpty - $res = Get-PSResource -Name $testScriptName -Version "3.0.0-alpha001" + $res = Get-PSResource -Name $testScriptName -Version "3.0.0-alpha" $res.Name | Should -Be $testScriptName $res.Version | Should -Be "3.0.0" - $res.Prerelease | Should -Be "alpha001" + $res.Prerelease | Should -Be "alpha" } } diff --git a/test/InstallPSResource.Tests.ps1 b/test/InstallPSResource.Tests.ps1 index fae7b83bf..c6f173483 100644 --- a/test/InstallPSResource.Tests.ps1 +++ b/test/InstallPSResource.Tests.ps1 @@ -7,10 +7,11 @@ Import-Module "$psscriptroot\PSGetTestUtils.psm1" -Force Describe 'Test Install-PSResource for Module' { BeforeAll { - $TestGalleryName = Get-PoshTestGalleryName $PSGalleryName = Get-PSGalleryName $NuGetGalleryName = Get-NuGetGalleryName - $testModuleName = "TestModule" + $testModuleName = "test_module" + $testModuleName2 = "TestModule99" + $testScriptName = "test_script" $RequiredResourceJSONFileName = "TestRequiredResourceFile.json" $RequiredResourcePSD1FileName = "TestRequiredResourceFile.psd1" Get-NewPSResourceRepositoryFile @@ -18,9 +19,7 @@ Describe 'Test Install-PSResource for Module' { } AfterEach { - Uninstall-PSResource "TestModule", "TestModule99", "myTestModule", "myTestModule2", "testModulePrerelease", - "testModuleWithlicense","PSGetTestModule", "PSGetTestDependency1", "TestFindModule","ClobberTestModule1", - "ClobberTestModule2" -SkipDependencyCheck -ErrorAction SilentlyContinue + Uninstall-PSResource "test_module", "test_module2", "test_script", "TestModule99", "testModuleWithlicense", "TestFindModule","ClobberTestModule1", "ClobberTestModule2" -SkipDependencyCheck -ErrorAction SilentlyContinue } AfterAll { @@ -28,7 +27,7 @@ Describe 'Test Install-PSResource for Module' { } $testCases = @{Name="*"; ErrorId="NameContainsWildcard"}, - @{Name="TestModule*"; ErrorId="NameContainsWildcard"}, + @{Name="Test_Module*"; ErrorId="NameContainsWildcard"}, @{Name="Test?Module","Test[Module"; ErrorId="ErrorFilteringNamesForUnsupportedWildcards"} It "Should not install resource with wildcard in name" -TestCases $testCases { @@ -39,29 +38,29 @@ Describe 'Test Install-PSResource for Module' { } It "Install specific module resource by name" { - Install-PSResource -Name "TestModule" -Repository $TestGalleryName - $pkg = Get-Module "TestModule" -ListAvailable - $pkg.Name | Should -Be "TestModule" - $pkg.Version | Should -Be "1.3.0" + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository + $pkg = Get-PSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0.0" } It "Install specific script resource by name" { - Install-PSResource -Name "TestTestScript" -Repository $TestGalleryName - $pkg = Get-PSResource "TestTestScript" - $pkg.Name | Should -Be "TestTestScript" - $pkg.Version | Should -Be "1.3.1.0" + Install-PSResource -Name $testScriptName -Repository $PSGalleryName -TrustRepository + $pkg = Get-PSResource $testScriptName + $pkg.Name | Should -Be $testScriptName + $pkg.Version | Should -Be "3.5.0.0" } It "Install multiple resources by name" { - $pkgNames = @("TestModule","TestModule99") - Install-PSResource -Name $pkgNames -Repository $TestGalleryName - $pkg = Get-Module $pkgNames -ListAvailable + $pkgNames = @($testModuleName,$testModuleName2) + Install-PSResource -Name $pkgNames -Repository $PSGalleryName -TrustRepository + $pkg = Get-PSResource $pkgNames $pkg.Name | Should -Be $pkgNames } It "Should not install resource given nonexistant name" { - Install-PSResource -Name "NonExistantModule" -Repository $TestGalleryName -ErrorVariable err -ErrorAction SilentlyContinue - $pkg = Get-Module "NonExistantModule" -ListAvailable + Install-PSResource -Name "NonExistantModule" -Repository $PSGalleryName -TrustRepository -ErrorVariable err -ErrorAction SilentlyContinue + $pkg = Get-PSResource "NonExistantModule" $pkg.Name | Should -BeNullOrEmpty $err.Count | Should -Not -Be 0 $err[0].FullyQualifiedErrorId | Should -BeExactly "ResourceNotFoundError,Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallPSResource" @@ -69,157 +68,162 @@ Describe 'Test Install-PSResource for Module' { # Do some version testing, but Find-PSResource should be doing thorough testing It "Should install resource given name and exact version" { - Install-PSResource -Name "TestModule" -Version "1.2.0" -Repository $TestGalleryName - $pkg = Get-Module "TestModule" -ListAvailable - $pkg.Name | Should -Be "TestModule" - $pkg.Version | Should -Be "1.2.0" + Install-PSResource -Name $testModuleName -Version "1.0.0" -Repository $PSGalleryName -TrustRepository + $pkg = Get-PSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "1.0.0.0" } It "Should install resource given name and exact version with bracket syntax" { - Install-PSResource -Name "TestModule" -Version "[1.2.0]" -Repository $TestGalleryName - $pkg = Get-Module "TestModule" -ListAvailable - $pkg.Name | Should -Be "TestModule" - $pkg.Version | Should -Be "1.2.0" + Install-PSResource -Name $testModuleName -Version "[1.0.0]" -Repository $PSGalleryName -TrustRepository + $pkg = Get-PSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "1.0.0.0" } - It "Should install resource given name and exact range inclusive [1.0.0, 1.1.1]" { - Install-PSResource -Name "TestModule" -Version "[1.0.0, 1.1.1]" -Repository $TestGalleryName - $pkg = Get-Module "TestModule" -ListAvailable - $pkg.Name | Should -Be "TestModule" - $pkg.Version | Should -Be "1.1.1" + It "Should install resource given name and exact range inclusive [1.0.0, 5.0.0]" { + Install-PSResource -Name $testModuleName -Version "[1.0.0, 5.0.0]" -Repository $PSGalleryName -TrustRepository + $pkg = Get-PSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0.0" } - It "Should install resource given name and exact range exclusive (1.0.0, 1.1.1)" { - Install-PSResource -Name "TestModule" -Version "(1.0.0, 1.1.1)" -Repository $TestGalleryName - $pkg = Get-Module "TestModule" -ListAvailable - $pkg.Name | Should -Be "TestModule" - $pkg.Version | Should -Be "1.1" + It "Should install resource given name and exact range exclusive (1.0.0, 5.0.0)" { + Install-PSResource -Name $testModuleName -Version "(1.0.0, 5.0.0)" -Repository $PSGalleryName -TrustRepository + $pkg = Get-PSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "3.0.0.0" } It "Should not install resource with incorrectly formatted version such as " -TestCases @( - @{Version='(1.2.0.0)'; Description="exclusive version (2.10.0.0)"}, - @{Version='[1-2-0-0]'; Description="version formatted with invalid delimiter [1-2-0-0]"} + @{Version='(1.0.0.0)'; Description="exclusive version (1.0.0.0)"}, + @{Version='[1-0-0-0]'; Description="version formatted with invalid delimiter [1-0-0-0]"} ) { param($Version, $Description) - Install-PSResource -Name "TestModule" -Version $Version -Repository $TestGalleryName -ErrorAction SilentlyContinue + Install-PSResource -Name $testModuleName -Version $Version -Repository $PSGalleryName -TrustRepository -ErrorAction SilentlyContinue $Error[0].FullyQualifiedErrorId | Should -be "ResourceNotFoundError,Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallPSResource" - $res = Get-Module "TestModule" -ListAvailable + $res = Get-PSResource $testModuleName $res | Should -BeNullOrEmpty } It "Install resource when given Name, Version '*', should install the latest version" { - Install-PSResource -Name "TestModule" -Version "*" -Repository $TestGalleryName - $pkg = Get-Module "TestModule" -ListAvailable - $pkg.Name | Should -Be "TestModule" - $pkg.Version | Should -Be "1.3.0" + Install-PSResource -Name $testModuleName -Version "*" -Repository $PSGalleryName -TrustRepository + $pkg = Get-PSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0.0" } It "Install resource with latest (including prerelease) version given Prerelease parameter" { - Install-PSResource -Name "TestModulePrerelease" -Prerelease -Repository $TestGalleryName - $pkg = Get-Module "TestModulePrerelease" -ListAvailable - $pkg.Name | Should -Be "TestModulePrerelease" - $pkg.Version | Should -Be "0.0.1" - $pkg.PrivateData.PSData.Prerelease | Should -Be "preview" + Install-PSResource -Name $testModuleName -Prerelease -Repository $PSGalleryName -TrustRepository + $pkg = Get-PSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.2.5" + $pkg.Prerelease | Should -Be "alpha001" } It "Install a module with a dependency" { - Install-PSResource -Name "PSGetTestModule" -Prerelease -Repository $TestGalleryName - $pkg = Get-Module "PSGetTestModule" -ListAvailable - $pkg.Name | Should -Be "PSGetTestModule" - $pkg.Version | Should -Be "2.0.2" - $pkg.PrivateData.PSData.Prerelease | Should -Be "-alpha1" + Uninstall-PSResource -Name "TestModuleWithDependency*" -Version "*" -SkipDependencyCheck + Install-PSResource -Name "TestModuleWithDependencyC" -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository - $pkg = Get-Module "PSGetTestDependency1" -ListAvailable - $pkg.Name | Should -Be "PSGetTestDependency1" - $pkg.Version | Should -Be "1.0.0" + $pkg = Get-PSResource "TestModuleWithDependencyC" + $pkg.Name | Should -Be "TestModuleWithDependencyC" + $pkg.Version | Should -Be "1.0.0.0" + + $pkg = Get-PSResource "TestModuleWithDependencyB" + $pkg.Name | Should -Be "TestModuleWithDependencyB" + $pkg.Version | Should -Be "3.0.0.0" + + $pkg = Get-PSResource "TestModuleWithDependencyD" + $pkg.Name | Should -Be "TestModuleWithDependencyD" + $pkg.Version | Should -Be "1.0.0.0" } It "Install a module with a dependency and skip installing the dependency" { - Install-PSResource -Name "PSGetTestModule" -Prerelease -Repository $TestGalleryName -SkipDependencyCheck - $pkg = Get-Module "PSGetTestModule" -ListAvailable - $pkg.Name | Should -Be "PSGetTestModule" - $pkg.Version | Should -Be "2.0.2" - $pkg.PrivateData.PSData.Prerelease | Should -Be "-alpha1" + Uninstall-PSResource -Name "TestModuleWithDependency*" -Version "*" -SkipDependencyCheck + Install-PSResource -Name "TestModuleWithDependencyC" -Version "1.0.0.0" -SkipDependencyCheck -Repository $PSGalleryName -TrustRepository + $pkg = Get-PSResource "TestModuleWithDependencyC" + $pkg.Name | Should -Be "TestModuleWithDependencyC" + $pkg.Version | Should -Be "1.0.0.0" - $pkg = Get-Module "PSGetTestDependency1" -ListAvailable + $pkg = Get-PSResource "TestModuleWithDependencyB", "TestModuleWithDependencyD" $pkg | Should -BeNullOrEmpty } It "Install resource via InputObject by piping from Find-PSresource" { - Find-PSResource -Name "TestModule" -Repository $TestGalleryName | Install-PSResource - $pkg = Get-Module "TestModule" -ListAvailable - $pkg.Name | Should -Be "TestModule" - $pkg.Version | Should -Be "1.3.0" + Find-PSResource -Name $testModuleName -Repository $PSGalleryName | Install-PSResource -TrustRepository + $pkg = Get-PSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0.0" } # Windows only It "Install resource under CurrentUser scope - Windows only" -Skip:(!(Get-IsWindows)) { - Install-PSResource -Name "TestModule" -Repository $TestGalleryName -Scope CurrentUser - $pkg = Get-Module "TestModule" -ListAvailable - $pkg.Name | Should -Be "TestModule" - $pkg.Path.Contains("Documents") | Should -Be $true + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository -Scope CurrentUser + $pkg = Get-PSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.InstalledLocation.ToString().Contains("Documents") | Should -Be $true } # Windows only It "Install resource under AllUsers scope - Windows only" -Skip:(!((Get-IsWindows) -and (Test-IsAdmin))) { - Install-PSResource -Name "TestModule" -Repository $TestGalleryName -Scope AllUsers - $pkg = Get-Module "TestModule" -ListAvailable - $pkg.Name | Should -Be "TestModule" - $pkg.Path.Contains("Program Files") | Should -Be $true + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository -Scope AllUsers + $pkg = Get-PSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.InstalledLocation.ToString().Contains("Program Files") | Should -Be $true } # Windows only It "Install resource under no specified scope - Windows only" -Skip:(!(Get-IsWindows)) { - Install-PSResource -Name "TestModule" -Repository $TestGalleryName - $pkg = Get-Module "TestModule" -ListAvailable - $pkg.Name | Should -Be "TestModule" - $pkg.Path.Contains("Documents") | Should -Be $true + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository + $pkg = Get-PSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.InstalledLocation.ToString().Contains("Documents") | Should -Be $true } # Unix only # Expected path should be similar to: '/home/janelane/.local/share/powershell/Modules' It "Install resource under CurrentUser scope - Unix only" -Skip:(Get-IsWindows) { - Install-PSResource -Name "TestModule" -Repository $TestGalleryName -Scope CurrentUser - $pkg = Get-Module "TestModule" -ListAvailable - $pkg.Name | Should -Be "TestModule" - $pkg.Path.Contains("$env:HOME/.local") | Should -Be $true + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository -Scope CurrentUser + $pkg = Get-PSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.InstalledLocation.ToString().Contains("$env:HOME/.local") | Should -Be $true } # Unix only # Expected path should be similar to: '/home/janelane/.local/share/powershell/Modules' It "Install resource under no specified scope - Unix only" -Skip:(Get-IsWindows) { - Install-PSResource -Name "TestModule" -Repository $TestGalleryName - $pkg = Get-Module "TestModule" -ListAvailable - $pkg.Name | Should -Be "TestModule" - $pkg.Path.Contains("$env:HOME/.local") | Should -Be $true + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository + $pkg = Get-PSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.InstalledLocation.ToString().Contains("$env:HOME/.local") | Should -Be $true } It "Should not install resource that is already installed" { - Install-PSResource -Name "TestModule" -Repository $TestGalleryName - $pkg = Get-Module "TestModule" -ListAvailable - $pkg.Name | Should -Be "TestModule" - Install-PSResource -Name "TestModule" -Repository $TestGalleryName -WarningVariable WarningVar -warningaction SilentlyContinue + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository + $pkg = Get-PSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository -WarningVariable WarningVar -warningaction SilentlyContinue $WarningVar | Should -Not -BeNullOrEmpty } It "Reinstall resource that is already installed with -Reinstall parameter" { - Install-PSResource -Name "TestModule" -Repository $TestGalleryName - $pkg = Get-Module "TestModule" -ListAvailable - $pkg.Name | Should -Be "TestModule" - $pkg.Version | Should -Be "1.3.0" - Install-PSResource -Name "TestModule" -Repository $TestGalleryName -Reinstall - $pkg = Get-Module "TestModule" -ListAvailable - $pkg.Name | Should -Be "TestModule" - $pkg.Version | Should -Be "1.3.0" + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository + $pkg = Get-PSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0.0" + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -Reinstall -TrustRepository + $pkg = Get-PSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0.0" } It "Restore resource after reinstall fails" { - Install-PSResource -Name "TestModule" -Repository $TestGalleryName - $pkg = Get-Module "TestModule" -ListAvailable - $pkg.Name | Should -Be "TestModule" - $pkg.Version | Should -Be "1.3.0" + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository + $pkg = Get-Module $testModuleName -ListAvailable + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0.0" $resourcePath = Split-Path -Path $pkg.Path -Parent $resourceFiles = Get-ChildItem -Path $resourcePath -Recurse @@ -229,7 +233,7 @@ Describe 'Test Install-PSResource for Module' { try { # Reinstall of resource should fail with one of its files locked. - Install-PSResource -Name "TestModule" -Repository $TestGalleryName -Reinstall -ErrorVariable ev -ErrorAction Silent + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository -Reinstall -ErrorVariable ev -ErrorAction Silent $ev.FullyQualifiedErrorId | Should -BeExactly 'InstallPackageFailed,Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallPSResource' } finally @@ -241,33 +245,23 @@ Describe 'Test Install-PSResource for Module' { (Get-ChildItem -Path $resourcePath -Recurse).Count | Should -BeExactly $resourceFiles.Count } - It "Install resource that requires accept license with -AcceptLicense flag" { - Install-PSResource -Name "testModuleWithlicense" -Repository $TestGalleryName -AcceptLicense - $pkg = Get-PSResource "testModuleWithlicense" - $pkg.Name | Should -Be "testModuleWithlicense" - $pkg.Version | Should -Be "0.0.3.0" - } - - It "Install resource should not prompt 'trust repository' if repository is not trusted but -TrustRepository is used" { - Set-PSResourceRepository PoshTestGallery -Trusted:$false - - Install-PSResource -Name "TestModule" -Repository $TestGalleryName -TrustRepository - - $pkg = Get-Module "TestModule" -ListAvailable - $pkg.Name | Should -Be "TestModule" + # It "Install resource that requires accept license with -AcceptLicense flag" { + # Install-PSResource -Name "testModuleWithlicense" -Repository $TestGalleryName -AcceptLicense + # $pkg = Get-PSResource "testModuleWithlicense" + # $pkg.Name | Should -Be "testModuleWithlicense" + # $pkg.Version | Should -Be "0.0.3.0" + # } - Set-PSResourceRepository PoshTestGallery -Trusted - } It "Install resource with cmdlet names from a module already installed (should clobber)" { - Install-PSResource -Name "myTestModule" -Repository $TestGalleryName - $pkg = Get-PSResource "myTestModule" - $pkg.Name | Should -Be "myTestModule" - $pkg.Version | Should -Be "0.0.3.0" - - Install-PSResource -Name "myTestModule2" -Repository $TestGalleryName - $pkg = Get-PSResource "myTestModule2" - $pkg.Name | Should -Be "myTestModule2" + Install-PSResource -Name "CLobberTestModule1" -Repository $PSGalleryName -TrustRepository + $pkg = Get-PSResource "ClobberTestModule1" + $pkg.Name | Should -Be "ClobberTestModule1" + $pkg.Version | Should -Be "0.0.1.0" + + Install-PSResource -Name "ClobberTestModule2" -Repository $PSGalleryName -TrustRepository + $pkg = Get-PSResource "ClobberTestModule2" + $pkg.Name | Should -Be "ClobberTestModule2" $pkg.Version | Should -Be "0.0.1.0" } @@ -278,144 +272,148 @@ Describe 'Test Install-PSResource for Module' { Set-PSResourceRepository "psgettestlocal" -Trusted:$true Install-PSResource -Name $publishModuleName -Repository $repoName - $pkg = Get-Module $publishModuleName -ListAvailable + $pkg = Get-PSResource $publishModuleName $pkg | Should -Not -BeNullOrEmpty $pkg.Name | Should -Be $publishModuleName } It "Install module using -WhatIf, should not install the module" { - Install-PSResource -Name "TestModule" -WhatIf + Install-PSResource -Name $testModuleName -WhatIf - $res = Get-Module "TestModule" -ListAvailable + $res = Get-PSResource $testModuleName $res | Should -BeNullOrEmpty } It "Validates that a module with module-name script files (like Pester) installs under Modules path" { - Install-PSResource -Name "testModuleWithScript" -Repository $TestGalleryName + Install-PSResource -Name "testModuleWithScript" -Repository $PSGalleryName -TrustRepository - $res = Get-Module "testModuleWithScript" -ListAvailable - $res.Path.Contains("Modules") | Should -Be $true + $res = Get-PSResource "testModuleWithScript" + $res.InstalledLocation.ToString().Contains("Modules") | Should -Be $true } It "Install module using -NoClobber, should throw clobber error and not install the module" { - Install-PSResource -Name "ClobberTestModule1" -Repository $TestGalleryName + Install-PSResource -Name "ClobberTestModule1" -Repository $PSGalleryName -TrustRepository - $res = Get-Module "ClobberTestModule1" -ListAvailable + $res = Get-PSResource "ClobberTestModule1" $res.Name | Should -Be "ClobberTestModule1" - Install-PSResource -Name "ClobberTestModule2" -Repository $TestGalleryName -NoClobber -ErrorAction SilentlyContinue + Install-PSResource -Name "ClobberTestModule2" -Repository $PSGalleryName -TrustRepository -NoClobber -ErrorAction SilentlyContinue $Error[0].FullyQualifiedErrorId | Should -be "CommandAlreadyExists,Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallPSResource" } - It "Install PSResourceInfo object piped in" { - Find-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName | Install-PSResource + + It "Install PSResourceInfo object piped in" { + Find-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName | Install-PSResource -TrustRepository $res = Get-PSResource -Name $testModuleName $res.Name | Should -Be $testModuleName - $res.Version | Should -Be "1.1.0.0" + $res.Version | Should -Be "1.0.0.0" } It "Install module using -PassThru" { - $res = Install-PSResource -Name "TestModule" -Version "1.3.0" -Repository $TestGalleryName -PassThru - $res.Name | Should -Be "TestModule" - $res.Version | Should -Be "1.3.0.0" + $res = Install-PSResource -Name $testModuleName -Repository $PSGalleryName -PassThru -TrustRepository + $res.Name | Should -Contain $testModuleName } It "Install modules using -RequiredResource with hashtable" { $rrHash = @{ - TestModule = @{ - version = "[0.0.1,1.3.0]" - repository = $TestGalleryName + test_module = @{ + version = "[1.0.0,5.0.0)" + repository = $PSGalleryName } - TestModulePrerelease = @{ - version = "[0.0.0,0.0.5]" - repository = $TestGalleryName + test_module2 = @{ + version = "[1.0.0,3.0.0)" + repository = $PSGalleryName prerelease = "true" } - TestModule99 = @{ - } + TestModule99 = @{} } - Install-PSResource -RequiredResource $rrHash + Install-PSResource -RequiredResource $rrHash -TrustRepository - $res1 = Get-Module "TestModule" -ListAvailable - $res1.Name | Should -Be "TestModule" - $res1.Version | Should -Be "1.3.0" + $res1 = Get-PSResource $testModuleName + $res1.Name | Should -Be $testModuleName + $res1.Version | Should -Be "3.0.0.0" - $res2 = Get-Module "TestModulePrerelease" -ListAvailable - $res2.Name | Should -Be "TestModulePrerelease" - $res2.Version | Should -Be "0.0.1" + $res2 = Get-PSResource "test_module2" -Version "2.5.0-beta" + $res2.Name | Should -Be "test_module2" + $res2.Version | Should -Be "2.5.0" + $res2.Prerelease | Should -Be "beta" - $res3 = Get-Module "TestModule99" -ListAvailable - $res3.Name | Should -Be "TestModule99" - $res3.Version | Should -Be "0.0.5" + $res3 = Get-PSResource $testModuleName2 + $res3.Name | Should -Be $testModuleName2 + $res3.Version | Should -Be "0.0.93.0" } It "Install modules using -RequiredResource with JSON string" { $rrJSON = "{ - 'TestModule': { - 'version': '[0.0.1,1.3.0]', - 'repository': 'PoshTestGallery' + 'test_module': { + 'version': '[1.0.0,5.0.0)', + 'repository': 'PSGallery' }, - 'TestModulePrerelease': { - 'version': '[0.0.0,0.0.5]', - 'repository': 'PoshTestGallery', + 'test_module2': { + 'version': '[1.0.0,3.0.0)', + 'repository': 'PSGallery', 'prerelease': 'true' }, 'TestModule99': { + 'repository': 'PSGallery' } }" - Install-PSResource -RequiredResource $rrJSON + Install-PSResource -RequiredResource $rrJSON -TrustRepository - $res1 = Get-Module "TestModule" -ListAvailable - $res1.Name | Should -Be "TestModule" - $res1.Version | Should -Be "1.3.0" + $res1 = Get-PSResource $testModuleName + $res1.Name | Should -Be $testModuleName + $res1.Version | Should -Be "3.0.0.0" - $res2 = Get-Module "TestModulePrerelease" -ListAvailable - $res2.Name | Should -Be "TestModulePrerelease" - $res2.Version | Should -Be "0.0.1" + $res2 = Get-PSResource "test_module2" -Version "2.5.0-beta" + $res2.Name | Should -Be "test_module2" + $res2.Version | Should -Be "2.5.0" + $res2.Prerelease | Should -Be "beta" - $res3 = Get-Module "TestModule99" -ListAvailable - $res3.Name | Should -Be "TestModule99" - $res3.Version | Should -Be "0.0.5" + $res3 = Get-PSResource $testModuleName2 + $res3.Name | Should -Be $testModuleName2 + $res3.Version | Should -Be "0.0.93.0" } It "Install modules using -RequiredResourceFile with PSD1 file" { $rrFilePSD1 = Join-Path -Path $psscriptroot -ChildPath $RequiredResourcePSD1FileName - Install-PSResource -RequiredResourceFile $rrFilePSD1 + Install-PSResource -RequiredResourceFile $rrFilePSD1 -TrustRepository - $res1 = Get-Module "TestModule" -ListAvailable - $res1.Name | Should -Be "TestModule" - $res1.Version | Should -Be "1.3.0" + $res1 = Get-PSResource $testModuleName + $res1.Name | Should -Be $testModuleName + $res1.Version | Should -Be "3.0.0.0" - $res2 = Get-Module "TestModulePrerelease" -ListAvailable - $res2.Name | Should -Be "TestModulePrerelease" - $res2.Version | Should -Be "0.0.1" + $res2 = Get-PSResource "test_module2" -Version "2.5.0-beta" + $res2.Name | Should -Be "test_module2" + $res2.Version | Should -Be "2.5.0" + $res2.Prerelease | Should -Be "beta" - $res3 = Get-Module "TestModule99" -ListAvailable - $res3.Name | Should -Be "TestModule99" - $res3.Version | Should -Be "0.0.5" + $res3 = Get-PSResource $testModuleName2 + $res3.Name | Should -Be $testModuleName2 + $res3.Version | Should -Be "0.0.93.0" } It "Install modules using -RequiredResourceFile with JSON file" { $rrFileJSON = Join-Path -Path $psscriptroot -ChildPath $RequiredResourceJSONFileName - Install-PSResource -RequiredResourceFile $rrFileJSON + Install-PSResource -RequiredResourceFile $rrFileJSON -TrustRepository - $res1 = Get-Module "TestModule" -ListAvailable - $res1.Name | Should -Be "TestModule" - $res1.Version | Should -Be "1.2.0" + $res1 = Get-PSResource $testModuleName + $res1.Name | Should -Be $testModuleName + $res1.Version | Should -Be "3.0.0.0" - $res2 = Get-Module "TestModulePrerelease" -ListAvailable - $res2.Name | Should -Be "TestModulePrerelease" - $res2.Version | Should -Be "0.0.1" + $res2 = Get-PSResource "test_module2" -Version "2.5.0-beta" + $res2.Name | Should -Be "test_module2" + $res2.Version | Should -Be "2.5.0" + $res2.Prerelease | Should -Be "beta" - $res3 = Get-Module "TestModule99" -ListAvailable - $res3.Name | Should -Be "TestModule99" - $res3.Version | Should -Be "0.0.5" + $res3 = Get-PSResource $testModuleName2 + $res3.Name | Should -Be $testModuleName2 + $res3.Version | Should -Be "0.0.93.0" } } diff --git a/test/SavePSResource.Tests.ps1 b/test/SavePSResource.Tests.ps1 index 6704ee72b..8160144bc 100644 --- a/test/SavePSResource.Tests.ps1 +++ b/test/SavePSResource.Tests.ps1 @@ -7,12 +7,11 @@ Import-Module "$psscriptroot\PSGetTestUtils.psm1" -Force Describe 'Test Save-PSResource for PSResources' { BeforeAll { - $TestGalleryName = Get-PoshTestGalleryName $PSGalleryName = Get-PSGalleryName $NuGetGalleryName = Get-NuGetGalleryName $testModuleName = "test_module" - $testModuleName2 = "TestModule" - $testScriptName = "TestTestScript" + $testScriptName = "test_script" + $testModuleName2 = "testmodule99" Get-NewPSResourceRepositoryFile Register-LocalRepos @@ -30,30 +29,30 @@ Describe 'Test Save-PSResource for PSResources' { } It "Save specific module resource by name" { - Save-PSResource -Name $testModuleName2 -Repository $TestGalleryName -Path $SaveDir - $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName2 + Save-PSResource -Name $testModuleName -Repository $PSGalleryName -Path $SaveDir -TrustRepository + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName $pkgDir | Should -Not -BeNullOrEmpty (Get-ChildItem $pkgDir.FullName).Count | Should -Be 1 } It "Save specific script resource by name" { - Save-PSResource -Name $testScriptName -Repository $TestGalleryName -Path $SaveDir - $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq "TestTestScript.ps1" + Save-PSResource -Name $testScriptName -Repository $PSGalleryName -Path $SaveDir -TrustRepository + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq "test_script.ps1" $pkgDir | Should -Not -BeNullOrEmpty (Get-ChildItem $pkgDir.FullName).Count | Should -Be 1 } It "Save multiple resources by name" { - $pkgNames = @("TestModule","TestModule99") - Save-PSResource -Name $pkgNames -Repository $TestGalleryName -Path $SaveDir - $pkgDirs = Get-ChildItem -Path $SaveDir | Where-Object { $_.Name -eq "TestModule" -or $_.Name -eq "TestModule99" } + $pkgNames = @($testModuleName, $testModuleName2) + Save-PSResource -Name $pkgNames -Repository $PSGalleryName -Path $SaveDir -TrustRepository + $pkgDirs = Get-ChildItem -Path $SaveDir | Where-Object { $_.Name -eq $testModuleName -or $_.Name -eq $testModuleName2 } $pkgDirs.Count | Should -Be 2 (Get-ChildItem $pkgDirs[0].FullName).Count | Should -Be 1 (Get-ChildItem $pkgDirs[1].FullName).Count | Should -Be 1 } It "Should not save resource given nonexistant name" { - Save-PSResource -Name NonExistentModule -Repository $TestGalleryName -Path $SaveDir -ErrorVariable err -ErrorAction SilentlyContinue + Save-PSResource -Name NonExistentModule -Repository $PSGalleryName -Path $SaveDir -ErrorVariable err -ErrorAction SilentlyContinue -TrustRepository $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq "NonExistentModule" $pkgDir.Name | Should -BeNullOrEmpty $err.Count | Should -Not -Be 0 @@ -61,108 +60,96 @@ Describe 'Test Save-PSResource for PSResources' { } It "Not Save module with Name containing wildcard" { - Save-PSResource -Name "TestModule*" -Repository $TestGalleryName -Path $SaveDir -ErrorVariable err -ErrorAction SilentlyContinue + Save-PSResource -Name "TestModule*" -Repository $PSGalleryName -Path $SaveDir -ErrorVariable err -ErrorAction SilentlyContinue -TrustRepository $err.Count | Should -Not -Be 0 $err[0].FullyQualifiedErrorId | Should -BeExactly "NameContainsWildcard,Microsoft.PowerShell.PowerShellGet.Cmdlets.SavePSResource" } # Do some version testing, but Find-PSResource should be doing thorough testing It "Should save resource given name and exact version" { - Save-PSResource -Name $testModuleName2 -Version "1.2.0" -Repository $TestGalleryName -Path $SaveDir - $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName2 + Save-PSResource -Name $testModuleName -Version "1.0.0" -Repository $PSGalleryName -Path $SaveDir -TrustRepository + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName $pkgDir | Should -Not -BeNullOrEmpty $pkgDirVersion = Get-ChildItem $pkgDir.FullName - $pkgDirVersion.Name | Should -Be "1.2.0" + $pkgDirVersion.Name | Should -Be "1.0.0.0" } It "Should save resource given name and exact version with bracket syntax" { - Save-PSResource -Name $testModuleName2 -Version "[1.2.0]" -Repository $TestGalleryName -Path $SaveDir - $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName2 + Save-PSResource -Name $testModuleName -Version "[1.0.0]" -Repository $PSGalleryName -Path $SaveDir -TrustRepository + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName $pkgDir | Should -Not -BeNullOrEmpty $pkgDirVersion = Get-ChildItem -Path $pkgDir.FullName - $pkgDirVersion.Name | Should -Be "1.2.0" + $pkgDirVersion.Name | Should -Be "1.0.0.0" } - It "Should save resource given name and exact range inclusive [1.0.0, 1.1.1]" { - Save-PSResource -Name $testModuleName2 -Version "[1.0.0, 1.1.1]" -Repository $TestGalleryName -Path $SaveDir - $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName2 + It "Should save resource given name and exact range inclusive [1.0.0, 3.0.0]" { + Save-PSResource -Name $testModuleName -Version "[1.0.0, 3.0.0]" -Repository $PSGalleryName -Path $SaveDir -TrustRepository + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName $pkgDir | Should -Not -BeNullOrEmpty $pkgDirVersion = Get-ChildItem -Path $pkgDir.FullName - $pkgDirVersion.Name | Should -Be "1.1.1" + $pkgDirVersion.Name | Should -Be "3.0.0.0" } - It "Should save resource given name and exact range exclusive (1.0.0, 1.1.1)" { - Save-PSResource -Name $testModuleName2 -Version "(1.0.0, 1.1.1)" -Repository $TestGalleryName -Path $SaveDir - $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName2 + It "Should save resource given name and exact range exclusive (1.0.0, 5.0.0)" { + Save-PSResource -Name $testModuleName -Version "(1.0.0, 5.0.0)" -Repository $PSGalleryName -Path $SaveDir -TrustRepository + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName $pkgDir | Should -Not -BeNullOrEmpty $pkgDirVersion = Get-ChildItem -Path $pkgDir.FullName - $pkgDirVersion.Name | Should -Be "1.1" + $pkgDirVersion.Name | Should -Be "3.0.0.0" } It "Should not save resource with incorrectly formatted version such as " -TestCases @( - @{Version='(1.2.0.0)'; Description="exclusive version (2.10.0.0)"}, - @{Version='[1-2-0-0]'; Description="version formatted with invalid delimiter [1-2-0-0]"} + @{Version='(1.0.0.0)'; Description="exclusive version (1.0.0.0)"}, + @{Version='[1-0-0-0]'; Description="version formatted with invalid delimiter [1-0-0-0]"} ) { param($Version, $Description) - Save-PSResource -Name $testModuleName2 -Version $Version -Repository $TestGalleryName -Path $SaveDir -ErrorVariable err -ErrorAction SilentlyContinue - $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName2 + Save-PSResource -Name $testModuleName -Version $Version -Repository $PSGalleryName -Path $SaveDir -ErrorVariable err -ErrorAction SilentlyContinue -TrustRepository + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName $pkgDir | Should -BeNullOrEmpty $err.Count | Should -Not -Be 0 $err[0].FullyQualifiedErrorId | Should -BeExactly "ResourceNotFoundError,Microsoft.PowerShell.PowerShellGet.Cmdlets.SavePSResource" } It "Save resource when given Name, Version '*', should install the latest version" { - Save-PSResource -Name $testModuleName2 -Version "*" -Repository $TestGalleryName -Path $SaveDir -ErrorAction SilentlyContinue - $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName2 + Save-PSResource -Name $testModuleName -Version "*" -Repository $PSGalleryName -Path $SaveDir -ErrorAction SilentlyContinue -TrustRepository + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName $pkgDir | Should -Not -BeNullOrEmpty $pkgDirVersion = Get-ChildItem -Path $pkgDir.FullName - $pkgDirVersion.Name | Should -Be "1.3.0" + $pkgDirVersion.Name | Should -Be "5.0.0.0" } It "Save resource with latest (including prerelease) version given Prerelease parameter" { - Save-PSResource -Name "TestModulePrerelease" -Prerelease -Repository $TestGalleryName -Path $SaveDir - $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq "TestModulePrerelease" + Save-PSResource -Name $testModuleName -Prerelease -Repository $PSGalleryName -Path $SaveDir -TrustRepository + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName $pkgDir | Should -Not -BeNullOrEmpty $pkgDirVersion = Get-ChildItem -Path $pkgDir.FullName - $pkgDirVersion.Name | Should -Be "0.0.1" + $pkgDirVersion.Name | Should -Be "5.2.5" } It "Save a module with a dependency" { - Save-PSResource -Name "PSGetTestModule" -Prerelease -Repository $TestGalleryName -Path $SaveDir - $pkgDirs = Get-ChildItem -Path $SaveDir | Where-Object { $_.Name -eq "PSGetTestModule" -or $_.Name -eq "PSGetTestDependency1" } - $pkgDirs.Count | Should -Be 2 + Save-PSResource -Name "TestModuleWithDependencyE" -Version "1.0.0.0" -Repository $PSGalleryName -Path $SaveDir -TrustRepository + $pkgDirs = Get-ChildItem -Path $SaveDir | Where-Object { $_.Name -eq "TestModuleWithDependencyE" -or $_.Name -eq "TestModuleWithDependencyC" -or $_.Name -eq "TestModuleWithDependencyB" -or $_.Name -eq "TestModuleWithDependencyD"} + $pkgDirs.Count | Should -Be 4 (Get-ChildItem $pkgDirs[0].FullName).Count | Should -Be 1 (Get-ChildItem $pkgDirs[1].FullName).Count | Should -Be 1 + (Get-ChildItem $pkgDirs[2].FullName).Count | Should -Be 1 + (Get-ChildItem $pkgDirs[3].FullName).Count | Should -Be 1 } It "Save a module with a dependency and skip saving the dependency" { - Save-PSResource -Name "PSGetTestModule" -Prerelease -Repository $TestGalleryName -Path $SaveDir -SkipDependencyCheck - $pkgDirs = Get-ChildItem -Path $SaveDir | Where-Object { $_.Name -eq "PSGetTestModule" -or $_.Name -eq "PSGetTestDependency1" } + Save-PSResource -Name "TestModuleWithDependencyE" -Version "1.0.0.0" -SkipDependencyCheck -Repository $PSGalleryName -Path $SaveDir -TrustRepository + $pkgDirs = Get-ChildItem -Path $SaveDir | Where-Object { $_.Name -eq "TestModuleWithDependencyE"} $pkgDirs.Count | Should -Be 1 (Get-ChildItem $pkgDirs[0].FullName).Count | Should -Be 1 } It "Save resource via InputObject by piping from Find-PSresource" { - Find-PSResource -Name $testModuleName2 -Repository $TestGalleryName | Save-PSResource -Path $SaveDir - $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName2 + Find-PSResource -Name $testModuleName -Repository $PSGalleryName | Save-PSResource -Path $SaveDir -TrustRepository + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName $pkgDir | Should -Not -BeNullOrEmpty $pkgDirVersion = Get-ChildItem -Path $pkgDir.FullName - $pkgDirVersion.Name | Should -Be "1.3.0" - } - - It "Save resource should not prompt 'trust repository' if repository is not trusted but -TrustRepository is used" { - try { - Set-PSResourceRepository PoshTestGallery -Trusted:$false - Save-PSResource -Name $testModuleName2 -Repository $TestGalleryName -TrustRepository -Path $SaveDir - $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName2 - $pkgDir | Should -Not -BeNullOrEmpty - $pkgDirVersion = Get-ChildItem -Path $pkgDir.FullName - $pkgDirVersion.Name | Should -Be "1.3.0" - } - finally { - Set-PSResourceRepository PoshTestGallery -Trusted - } + $pkgDirVersion.Name | Should -Be "5.0.0.0" } It "Save resource from local repository given Repository parameter" { @@ -178,58 +165,57 @@ Describe 'Test Save-PSResource for PSResources' { } It "Save specific module resource by name when no repository is specified" { - Set-PSResourceRepository "PoshTestGallery" -Trusted:$True Set-PSResourceRepository "PSGallery" -Trusted:$True Set-PSResourceRepository "psgettestlocal2" -Trusted:$True - Save-PSResource -Name "TestModule" -Path $SaveDir - $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName2 + Save-PSResource -Name $testModuleName -Path $SaveDir + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName $pkgDir | Should -Not -BeNullOrEmpty (Get-ChildItem -Path $pkgDir.FullName).Count | Should -Be 1 } It "Save PSResourceInfo object piped in" { - Find-PSResource -Name $testModuleName2 -Version "1.1.0.0" -Repository $TestGalleryName | Save-PSResource -Path $SaveDir - $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName2 + Find-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName | Save-PSResource -Path $SaveDir -TrustRepository + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName $pkgDir | Should -Not -BeNullOrEmpty (Get-ChildItem -Path $pkgDir.FullName).Count | Should -Be 1 } It "Save PSResourceInfo object piped in for prerelease version object" { - Find-PSResource -Name $testModuleName -Version "4.5.2-alpha001" -Repository $TestGalleryName | Save-PSResource -Path $SaveDir + Find-PSResource -Name $testModuleName -Version "5.2.5-alpha001" -Repository $PSGalleryName | Save-PSResource -Path $SaveDir $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName $pkgDir | Should -Not -BeNullOrEmpty (Get-ChildItem -Path $pkgDir.FullName).Count | Should -Be 1 } It "Save module as a nupkg" { - Save-PSResource -Name $testModuleName2 -Version "1.3.0" -Repository $TestGalleryName -Path $SaveDir -AsNupkg + Save-PSResource -Name $testModuleName -Version "1.0.0" -Repository $PSGalleryName -Path $SaveDir -AsNupkg -TrustRepository write-host $SaveDir write-host - $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq "testmodule.1.3.0.nupkg" + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq "test_module.1.0.0.nupkg" $pkgDir | Should -Not -BeNullOrEmpty } It "Save script as a nupkg" { - Save-PSResource -Name $testScriptName -Version "1.3.1" -Repository $TestGalleryName -Path $SaveDir -AsNupkg - $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq "testtestscript.1.3.1.nupkg" + Save-PSResource -Name $testScriptName -Version "2.5.0" -Repository $PSGalleryName -Path $SaveDir -AsNupkg -TrustRepository + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq "test_script.2.5.0.nupkg" $pkgDir | Should -Not -BeNullOrEmpty } It "Save module and include XML metadata file" { - Save-PSResource -Name $testModuleName2 -Version "1.3.0" -Repository $TestGalleryName -Path $SaveDir -IncludeXML - $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName2 + Save-PSResource -Name $testModuleName -Version "1.0.0" -Repository $PSGalleryName -Path $SaveDir -IncludeXML -TrustRepository + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName $pkgDir | Should -Not -BeNullOrEmpty $pkgDirVersion = Get-ChildItem -Path $pkgDir.FullName - $pkgDirVersion.Name | Should -Be "1.3.0" + $pkgDirVersion.Name | Should -Be "1.0.0.0" $xmlFile = Get-ChildItem -Path $pkgDirVersion.FullName | Where-Object Name -eq "PSGetModuleInfo.xml" $xmlFile | Should -Not -BeNullOrEmpty } It "Save module using -PassThru" { - $res = Save-PSResource -Name $testModuleName2 -Version "1.3.0" -Repository $TestGalleryName -Path $SaveDir -PassThru - $res.Name | Should -Be $testModuleName2 - $res.Version | Should -Be "1.3.0.0" + $res = Save-PSResource -Name $testModuleName -Version "1.0.0" -Repository $PSGalleryName -Path $SaveDir -PassThru -TrustRepository + $res.Name | Should -Be $testModuleName + $res.Version | Should -Be "1.0.0.0" } <# # Tests should not write to module directory diff --git a/test/TestRequiredResourceFile.json b/test/TestRequiredResourceFile.json index 6d6c04e9f..5c193eac4 100644 --- a/test/TestRequiredResourceFile.json +++ b/test/TestRequiredResourceFile.json @@ -1,12 +1,14 @@ { - "TestModule": { - "version": "[0.0.1,1.3.0)", - "repository": "PoshTestGallery" + "test_module": { + "version": "[1.0.0,5.0.0)", + "repository": "PSGallery" }, - "TestModulePrerelease": { - "version": "[0.0.0,0.0.5]", - "repository": "PoshTestGallery", + "test_module2": { + "version": "[1.0.0,3.0.0)", + "repository": "PSGallery", "prerelease": "true" }, - "TestModule99": {} + "TestModule99": { + "repository": "PSGallery" + } } diff --git a/test/TestRequiredResourceFile.psd1 b/test/TestRequiredResourceFile.psd1 index 767e404bf..71eba50fa 100644 --- a/test/TestRequiredResourceFile.psd1 +++ b/test/TestRequiredResourceFile.psd1 @@ -1,14 +1,16 @@ @{ - TestModule = @{ - version = "[0.0.1,1.3.0]" - repository = "PoshTestGallery" + test_module = @{ + version = "[1.0.0,5.0.0)" + repository = "PSGallery" } - TestModulePrerelease = @{ - version = "[0.0.0,0.0.5]" - repository = "PoshTestGallery" - prerelease = "true" - } + test_module2 = @{ + version = "[1.0.0,3.0.0)" + repository = "PSGallery" + prerelease = "true" + } - TestModule99 = @{} + TestModule99 = @{ + repository = "PSGallery" + } } diff --git a/test/UninstallPSResource.Tests.ps1 b/test/UninstallPSResource.Tests.ps1 index b42ecaf19..54cfeb062 100644 --- a/test/UninstallPSResource.Tests.ps1 +++ b/test/UninstallPSResource.Tests.ps1 @@ -7,17 +7,20 @@ Import-Module "$psscriptroot\PSGetTestUtils.psm1" -Force Describe 'Test Uninstall-PSResource for Modules' { BeforeAll{ - $TestGalleryName = Get-PoshTestGalleryName $PSGalleryName = Get-PSGalleryName - $testModuleName = "test_module" + $testModuleName = "test_module2" $testScriptName = "test_script" Get-NewPSResourceRepositoryFile - Uninstall-PSResource -name ContosoServer -Version "*" Uninstall-PSResource -Name $testModuleName -Version "*" + Uninstall-PSResource -Name $testScriptName -Version "*" } BeforeEach { - $null = Install-PSResource ContosoServer -Repository $TestGalleryName -TrustRepository -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName -Repository $PSGalleryName -TrustRepository -WarningAction SilentlyContinue + } + + AfterEach { + Uninstall-PSResource -Name $testModuleName -Version "*" } AfterAll { @@ -25,8 +28,8 @@ Describe 'Test Uninstall-PSResource for Modules' { } It "Uninstall a specific module by name" { - Uninstall-PSResource -name ContosoServer - Get-Module ContosoServer -ListAvailable | Should -Be $null + Uninstall-PSResource -name $testModuleName + Get-PSResource $testModuleName | Should -BeNullOrEmpty } $testCases = @{Name="Test?Module"; ErrorId="ErrorFilteringNamesForUnsupportedWildcards"}, @@ -40,129 +43,131 @@ Describe 'Test Uninstall-PSResource for Modules' { } It "Uninstall a list of modules by name" { - $null = Install-PSResource BaseTestPackage -Repository $TestGalleryName -TrustRepository -WarningAction SilentlyContinue -SkipDependencyCheck + $null = Install-PSResource "RequiredModule1" -Repository $PSGalleryName -TrustRepository -WarningAction SilentlyContinue -SkipDependencyCheck - Uninstall-PSResource -Name BaseTestPackage, ContosoServer - Get-Module ContosoServer, BaseTestPackage -ListAvailable | Should -be $null + Uninstall-PSResource -Name $testModuleName, "RequiredModule1" + Get-PSResource $testModuleName, "RequiredModule1" | Should -BeNullOrEmpty } It "Uninstall a specific script by name" { - $null = Install-PSResource "test_script" -Repository $TestGalleryName -TrustRepository - $res = Get-PSResource -Name "test_script" - $res.Name | Should -Be "test_script" + $null = Install-PSResource $testScriptName -Repository $PSGalleryName -TrustRepository + $res = Get-PSResource -Name $testScriptName + $res.Name | Should -Be $testScriptName - Uninstall-PSResource -name "test_script" - $res = Get-PSResource -Name "test_script" + Uninstall-PSResource -Name $testScriptName + $res = Get-PSResource -Name $testScriptName $res | Should -BeNullOrEmpty } It "Uninstall a list of scripts by name" { - $null = Install-PSResource "test_script", "TestTestScript" -Repository $TestGalleryName -TrustRepository - $res = Get-PSResource -Name "test_script" - $res2 = Get-PSResource -Name "TestTestScript" - $res.Name | Should -Be "test_script" - $res2.Name | Should -Be "TestTestScript" - - Uninstall-PSResource -Name "test_script", "TestTestScript" - $res = Get-PSResource -Name "test_script" - $res2 = Get-PSResource -Name "TestTestScript" + $null = Install-PSResource $testScriptName, "Required-Script1" -Repository $PSGalleryName -TrustRepository + $res = Get-PSResource -Name $testScriptName + $res.Name | Should -Be $testScriptName + $res2 = Get-PSResource -Name "Required-Script1" + $res2.Name | Should -Be "Required-Script1" + + Uninstall-PSResource -Name $testScriptName, "Required-Script1" + $res = Get-PSResource -Name $testScriptName $res | Should -BeNullOrEmpty + $res2 = Get-PSResource -Name "Required-Script1" $res2 | Should -BeNullOrEmpty } It "Uninstall a module when given name and specifying all versions" { - $null = Install-PSResource ContosoServer -Repository $TestGalleryName -Version "1.0.0" -TrustRepository -WarningAction SilentlyContinue - $null = Install-PSResource ContosoServer -Repository $TestGalleryName -Version "1.5.0" -TrustRepository -WarningAction SilentlyContinue - $null = Install-PSResource ContosoServer -Repository $TestGalleryName -Version "2.0.0" -TrustRepository -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName -Repository $PSGalleryName -Version "1.0.0" -TrustRepository -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName -Repository $PSGalleryName -Version "3.0.0" -TrustRepository -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName -Repository $PSGalleryName -Version "5.0.0" -TrustRepository -WarningAction SilentlyContinue - Uninstall-PSResource -Name ContosoServer -version "*" - $pkgs = Get-Module ContosoServer -ListAvailable + Uninstall-PSResource -Name $testModuleName -version "*" + $pkgs = Get-PSResource $testModuleName $pkgs.Version | Should -Not -Contain "1.0.0" - $pkgs.Version | Should -Not -Contain "1.5.0" - $pkgs.Version | Should -Not -Contain "2.0.0" - $pkgs.Version | Should -Not -Contain "2.5.0" + $pkgs.Version | Should -Not -Contain "3.0.0" + $pkgs.Version | Should -Not -Contain "5.0.0" } It "Uninstall a module when given name and using the default version (ie all versions, not explicitly specified)" { - $null = Install-PSResource ContosoServer -Repository $TestGalleryName -Version "1.0.0" -TrustRepository -WarningAction SilentlyContinue - $null = Install-PSResource ContosoServer -Repository $TestGalleryName -Version "1.5.0" -TrustRepository -WarningAction SilentlyContinue - $null = Install-PSResource ContosoServer -Repository $TestGalleryName -Version "2.0.0" -TrustRepository -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName -Repository $PSGalleryName -Version "1.0.0" -TrustRepository -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName -Repository $PSGalleryName -Version "3.0.0" -TrustRepository -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName -Repository $PSGalleryName -Version "5.0.0" -TrustRepository -WarningAction SilentlyContinue - Uninstall-PSResource -Name ContosoServer - $pkgs = Get-Module ContosoServer -ListAvailable + Uninstall-PSResource -Name $testModuleName + $pkgs = Get-PSResource $testModuleName $pkgs.Version | Should -Not -Contain "1.0.0" - $pkgs.Version | Should -Not -Contain "1.5.0" - $pkgs.Version | Should -Not -Contain "2.0.0" - $pkgs.Version | Should -Not -Contain "2.5.0" + $pkgs.Version | Should -Not -Contain "3.0.0" + $pkgs.Version | Should -Not -Contain "5.0.0" } It "Uninstall module when given Name and specifying exact version" { - $null = Install-PSResource ContosoServer -Repository $TestGalleryName -Version "1.0.0" -TrustRepository -WarningAction SilentlyContinue - $null = Install-PSResource ContosoServer -Repository $TestGalleryName -Version "1.5.0" -TrustRepository -WarningAction SilentlyContinue - $null = Install-PSResource ContosoServer -Repository $TestGalleryName -Version "2.0.0" -TrustRepository -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName -Repository $PSGalleryName -Version "1.0.0" -TrustRepository -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName -Repository $PSGalleryName -Version "3.0.0" -TrustRepository -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName -Repository $PSGalleryName -Version "5.0.0" -TrustRepository -WarningAction SilentlyContinue - Uninstall-PSResource -Name "ContosoServer" -Version "1.0.0" - $pkgs = Get-Module ContosoServer -ListAvailable + Uninstall-PSResource -Name $testModuleName -Version "3.0.0" + $pkgs = Get-PSResource -Name $testModuleName $pkgs.Version | Should -Not -Contain "1.0.0" } - $testCases = @{Version="[2.0.0.0]"; ExpectedVersion="2.0.0.0"; Reason="validate version, exact match"}, - @{Version="2.0.0.0"; ExpectedVersion="2.0.0.0"; Reason="validate version, exact match without bracket syntax"}, - @{Version="[1.0.0.0, 2.5.0.0]"; ExpectedVersion="2.5.0.0"; Reason="validate version, exact range inclusive"}, - @{Version="(1.0.0.0, 2.5.0.0)"; ExpectedVersion="2.0.0.0"; Reason="validate version, exact range exclusive"}, - @{Version="(1.0.0.0,)"; ExpectedVersion="2.5.0.0"; Reason="validate version, minimum version exclusive"}, - @{Version="[1.0.0.0,)"; ExpectedVersion="2.5.0.0"; Reason="validate version, minimum version inclusive"}, - @{Version="(,1.5.0.0)"; ExpectedVersion="1.0.0.0"; Reason="validate version, maximum version exclusive"}, - @{Version="(,1.5.0.0]"; ExpectedVersion="1.5.0.0"; Reason="validate version, maximum version inclusive"}, - @{Version="[1.0.0.0, 2.5.0.0)"; ExpectedVersion="2.0.0.0"; Reason="validate version, mixed inclusive minimum and exclusive maximum version"} + $testCases = @{Version="[1.0.0.0]"; ExpectedVersion="1.0.0.0"; Reason="validate version, exact match"}, + @{Version="1.0.0.0"; ExpectedVersion="1.0.0.0"; Reason="validate version, exact match without bracket syntax"}, + @{Version="[1.0.0.0, 5.0.0.0]"; ExpectedVersion="5.0.0.0"; Reason="validate version, exact range inclusive"}, + @{Version="(1.0.0.0, 5.0.0.0)"; ExpectedVersion="3.0.0.0"; Reason="validate version, exact range exclusive"}, + @{Version="(1.0.0.0,)"; ExpectedVersion="5.0.0.0"; Reason="validate version, minimum version exclusive"}, + @{Version="[1.0.0.0,)"; ExpectedVersion="5.0.0.0"; Reason="validate version, minimum version inclusive"}, + @{Version="(,3.0.0.0)"; ExpectedVersion="1.0.0.0"; Reason="validate version, maximum version exclusive"}, + @{Version="(,3.0.0.0]"; ExpectedVersion="1.0.0.0"; Reason="validate version, maximum version inclusive"}, + @{Version="[1.0.0.0, 5.0.0.0)"; ExpectedVersion="3.0.0.0"; Reason="validate version, mixed inclusive minimum and exclusive maximum version"} It "Uninstall module when given Name to " -TestCases $testCases { param($Version, $ExpectedVersion) - $null = Install-PSResource ContosoServer -Repository $TestGalleryName -Version "1.0.0" -TrustRepository -WarningAction SilentlyContinue - $null = Install-PSResource ContosoServer -Repository $TestGalleryName -Version "1.5.0" -TrustRepository -WarningAction SilentlyContinue - $null = Install-PSResource ContosoServer -Repository $TestGalleryName -Version "2.0.0" -TrustRepository -WarningAction SilentlyContinue + Uninstall-PSResource -Name $testModuleName -Version "*" + $null = Install-PSResource $testModuleName -Repository $PSGalleryName -Version "1.0.0" -TrustRepository -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName -Repository $PSGalleryName -Version "3.0.0" -TrustRepository -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName -Repository $PSGalleryName -Version "5.0.0" -TrustRepository -WarningAction SilentlyContinue - Uninstall-PSResource -Name ContosoServer -Version $Version - $pkgs = Get-Module ContosoServer -ListAvailable + Uninstall-PSResource -Name $testModuleName -Version $Version + $pkgs = Get-PSResource $testModuleName $pkgs.Version | Should -Not -Contain $Version } $testCases2 = @{Version='[1.*.0]'; Description="version with wilcard in middle"}, - @{Version='[*.5.0.0]'; Description="version with wilcard at start"}, + @{Version='[*.0.0.0]'; Description="version with wilcard at start"}, @{Version='[1.*.0.0]'; Description="version with wildcard at second digit"}, - @{Version='[1.5.*.0]'; Description="version with wildcard at third digit"} - @{Version='[1.5.0.*]'; Description="version with wildcard at end"}, + @{Version='[1.0.*.0]'; Description="version with wildcard at third digit"} + @{Version='[1.0.0.*]'; Description="version with wildcard at end"}, @{Version='[1..0.0]'; Description="version with missing digit in middle"}, - @{Version='[1.5.0.]'; Description="version with missing digit at end"}, - @{Version='[1.5.0.0.0]'; Description="version with more than 4 digits"} + @{Version='[1.0.0.]'; Description="version with missing digit at end"}, + @{Version='[1.0.0.0.0]'; Description="version with more than 4 digits"} It "Do not uninstall module with incorrectly formatted version such as " -TestCases $testCases2 { param($Version, $Description) - {Uninstall-PSResource -Name "ContosoServer" -Version $Version} | Should -Throw "Argument for -Version parameter is not in the proper format." + {Uninstall-PSResource -Name $testModuleName -Version $Version} | Should -Throw "Argument for -Version parameter is not in the proper format." } - $testCases3 = @{Version='(2.5.0.0)'; Description="exclusive version (8.1.0.0)"}, - @{Version='[2-5-0-0]'; Description="version formatted with invalid delimiter"} + $testCases3 = @{Version='(1.0.0.0)'; Description="exclusive version (1.0.0.0)"}, + @{Version='[1-0-0-0]'; Description="version formatted with invalid delimiter"} It "Do not uninstall module with incorrectly formatted version such as " -TestCases $testCases3 { param($Version, $Description) - Uninstall-PSResource -Name "ContosoServer" -Version $Version + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository - $pkg = Get-Module ContosoServer -ListAvailable - $pkg.Version | Should -Be "2.5" + Uninstall-PSResource -Name $testModuleName -Version $Version + $pkg = Get-PSResource $testModuleName -Version "1.0.0.0" + $pkg.Version | Should -Be "1.0.0.0" } It "Uninstall prerelease version module when prerelease version specified" { - Install-PSResource -Name $testModuleName -Version "5.2.5-alpha001" -Repository $TestGalleryName + Install-PSResource -Name $testModuleName -Version "5.2.5-alpha001" -Repository $PSGalleryName -TrustRepository Uninstall-PSResource -Name $testModuleName -Version "5.2.5-alpha001" $res = Get-PSResource $testModuleName -Version "5.2.5-alpha001" $res | Should -BeNullOrEmpty } It "Not uninstall non-prerelease version module when similar prerelease version is specified" { - Install-PSResource -Name $testModuleName -Version "5.0.0.0" -Repository $TestGalleryName + # test_module has a version 5.0.0.0, but no version 5.0.0-preview. + # despite the core version part being the same this uninstall on a nonexistant prerelease version should not be successful + Install-PSResource -Name $testModuleName -Version "5.0.0.0" -Repository $PSGalleryName -TrustRepository Uninstall-PSResource -Name $testModuleName -Version "5.0.0-preview" $res = Get-PSResource -Name $testModuleName -Version "5.0.0.0" $res.Name | Should -Be $testModuleName @@ -170,14 +175,14 @@ Describe 'Test Uninstall-PSResource for Modules' { } It "Uninstall prerelease version script when prerelease version specified" { - Install-PSResource -Name $testScriptName -Version "3.0.0-alpha001" -Repository $TestGalleryName - Uninstall-PSResource -Name $testScriptName -Version "3.0.0-alpha001" + Install-PSResource -Name $testScriptName -Version "3.0.0-alpha" -Repository $PSGalleryName -TrustRepository + Uninstall-PSResource -Name $testScriptName -Version "3.0.0-alpha" $res = Get-PSResource -Name $testScriptName $res | Should -BeNullOrEmpty } It "Not uninstall non-prerelease version module when prerelease version specified" { - Install-PSResource -Name $testScriptName -Version "2.5.0.0" -Repository $TestGalleryName + Install-PSResource -Name $testScriptName -Version "2.5.0.0" -Repository $PSGalleryName -TrustRepository Uninstall-PSResource -Name $testScriptName -Version "2.5.0-alpha001" $res = Get-PSResource -Name $testScriptName -Version "2.5.0.0" $res.Name | Should -Be $testScriptName @@ -185,11 +190,11 @@ Describe 'Test Uninstall-PSResource for Modules' { } It "uninstall all prerelease versions (which satisfy the range) when -Version '*' and -Prerelease parameter is specified" { - Install-PSResource -Name $testModuleName -Version "3.0.0" -Repository $TestGalleryName - Install-PSResource -Name $testModuleName -Version "3.5.2-beta001" -Repository $TestGalleryName - Install-PSResource -Name $testModuleName -Version "4.0.0" -Repository $TestGalleryName - Install-PSResource -Name $testModuleName -Version "4.5.2-alpha001" -Repository $TestGalleryName - Install-PSResource -Name $testModuleName -Version "5.0.0" -Repository $TestGalleryName + Uninstall-PSResource -Name $testModuleName -Version "*" + Install-PSResource -Name $testModuleName -Version "2.5.0-beta" -Repository $PSGalleryName -TrustRepository + Install-PSResource -Name $testModuleName -Version "3.0.0" -Repository $PSGalleryName -TrustRepository + Install-PSResource -Name $testModuleName -Version "5.0.0" -Repository $PSGalleryName -TrustRepository + Install-PSResource -Name $testModuleName -Version "5.2.5-alpha001" -Repository $PSGalleryName -TrustRepository $res = Get-PSResource -Name $testModuleName $prereleaseVersionPkgs = $res | Where-Object {$_.IsPrerelease -eq $true} $prereleaseVersionPkgs.Count | Should -Be 2 @@ -199,66 +204,67 @@ Describe 'Test Uninstall-PSResource for Modules' { $prereleaseVersionPkgs = $res | Where-Object {$_.IsPrerelease -eq $true} $prereleaseVersionPkgs.Count | Should -Be 0 $stableVersionPkgs = $res | Where-Object {$_.IsPrerelease -ne $true} - $stableVersionPkgs.Count | Should -Be 3 + $stableVersionPkgs.Count | Should -Be 2 } It "uninstall all prerelease versions (which satisfy the range) when -Version range and -Prerelease parameter is specified" { - Install-PSResource -Name $testModuleName -Version "3.0.0" -Repository $TestGalleryName - Install-PSResource -Name $testModuleName -Version "3.5.2-beta001" -Repository $TestGalleryName - Install-PSResource -Name $testModuleName -Version "4.0.0" -Repository $TestGalleryName - Install-PSResource -Name $testModuleName -Version "4.5.2-alpha001" -Repository $TestGalleryName - Install-PSResource -Name $testModuleName -Version "5.0.0" -Repository $TestGalleryName + Uninstall-PSResource -Name $testModuleName -Version "*" + Install-PSResource -Name $testModuleName -Version "2.5.0-beta" -Repository $PSGalleryName -TrustRepository + Install-PSResource -Name $testModuleName -Version "3.0.0" -Repository $PSGalleryName -TrustRepository + Install-PSResource -Name $testModuleName -Version "5.0.0" -Repository $PSGalleryName -TrustRepository + Install-PSResource -Name $testModuleName -Version "5.2.5-alpha001" -Repository $PSGalleryName -TrustRepository + $res = Get-PSResource -Name $testModuleName $prereleaseVersionPkgs = $res | Where-Object {$_.IsPrerelease -eq $true} $prereleaseVersionPkgs.Count | Should -Be 2 - Uninstall-PSResource -Name $testModuleName -Version "[3.0.0, 4.0.0]" -Prerelease + Uninstall-PSResource -Name $testModuleName -Version "[2.0.0, 5.0.0]" -Prerelease $res = Get-PSResource -Name $testModuleName - # should only uninstall 3.5.2-beta001, 4.5.2-alpha001 is out of range and should remain installed + # should only uninstall 2.5.0-beta, 5.2.5-alpha001 is out of range and should remain installed $prereleaseVersionPkgs = $res | Where-Object {$_.IsPrerelease -eq $true} $prereleaseVersionPkgs.Count | Should -Be 1 $stableVersionPkgs = $res | Where-Object {$_.IsPrerelease -ne $true} - # versions 3.0.0 and 4.0.0 fall in range but should not be uninstalled as Prerelease parameter only selects prerelease versions for uninstallation - $stableVersionPkgs.Count | Should -Be 3 + # versions 3.0.0 falls in range but should not be uninstalled as Prerelease parameter only selects prerelease versions to uninstall + $stableVersionPkgs.Count | Should -Be 2 } It "Uninstall module using -WhatIf, should not uninstall the module" { - Uninstall-PSResource -Name "ContosoServer" -WhatIf - $pkg = Get-Module ContosoServer -ListAvailable - $pkg.Version | Should -Be "2.5" + Uninstall-PSResource -Name $testModuleName -WhatIf + $pkg = Get-PSResource $testModuleName -Version "5.0.0.0" + $pkg.Version | Should -Be "5.0.0.0" } It "Do not Uninstall module that is a dependency for another module" { - $null = Install-PSResource $testModuleName -Repository $TestGalleryName -TrustRepository -WarningAction SilentlyContinue + $null = Install-PSResource "test_module" -Repository $PSGalleryName -TrustRepository -WarningAction SilentlyContinue Uninstall-PSResource -Name "RequiredModule1" -ErrorVariable ev -ErrorAction SilentlyContinue - $pkg = Get-Module "RequiredModule1" -ListAvailable + $pkg = Get-PSResource "RequiredModule1" $pkg | Should -Not -Be $null $ev.FullyQualifiedErrorId | Should -BeExactly 'UninstallPSResourcePackageIsaDependency,Microsoft.PowerShell.PowerShellGet.Cmdlets.UninstallPSResource' } It "Uninstall module that is a dependency for another module using -SkipDependencyCheck" { - $null = Install-PSResource $testModuleName -Repository $TestGalleryName -TrustRepository -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName -Repository $PSGalleryName -TrustRepository -WarningAction SilentlyContinue Uninstall-PSResource -Name "RequiredModule1" -SkipDependencyCheck - $pkg = Get-Module "RequiredModule1" -ListAvailable + $pkg = Get-PSResource "RequiredModule1" $pkg | Should -BeNullOrEmpty } It "Uninstall PSResourceInfo object piped in" { - Install-PSResource -Name "ContosoServer" -Version "1.5.0.0" -Repository $TestGalleryName - Get-PSResource -Name "ContosoServer" -Version "1.5.0.0" | Uninstall-PSResource - $res = Get-PSResource -Name "ContosoServer" -Version "1.5.0.0" + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository + Get-PSResource -Name $testModuleName -Version "1.0.0.0" | Uninstall-PSResource + $res = Get-PSResource -Name "ContosoServer" -Version "1.0.0.0" $res | Should -BeNullOrEmpty } It "Uninstall PSResourceInfo object piped in for prerelease version object" { - Install-PSResource -Name $testModuleName -Version "4.5.2-alpha001" -Repository $TestGalleryName - Get-PSResource -Name $testModuleName -Version "4.5.2-alpha001" | Uninstall-PSResource - $res = Get-PSResource -Name $testModuleName -Version "4.5.2-alpha001" + Install-PSResource -Name $testModuleName -Version "2.5.0-beta" -Repository $PSGalleryName -TrustRepository + Get-PSResource -Name $testModuleName -Version "2.5.0-beta" | Uninstall-PSResource + $res = Get-PSResource -Name $testModuleName -Version "2.5.0-beta" $res | Should -BeNullOrEmpty } } diff --git a/test/UnregisterPSResourceRepository.Tests.ps1 b/test/UnregisterPSResourceRepository.Tests.ps1 index f3e6e206e..97b9e3a1f 100644 --- a/test/UnregisterPSResourceRepository.Tests.ps1 +++ b/test/UnregisterPSResourceRepository.Tests.ps1 @@ -5,8 +5,8 @@ Import-Module "$psscriptroot\PSGetTestUtils.psm1" -Force Describe "Test Unregister-PSResourceRepository" { BeforeEach { - $TestGalleryName = Get-PoshTestGalleryName - $TestGalleryUri = Get-PoshTestGalleryLocation + $PSGalleryName = Get-PSGalleryName + $PSGalleryUri = Get-PSGalleryLocation Get-NewPSResourceRepositoryFile $tmpDir1Path = Join-Path -Path $TestDrive -ChildPath "tmpDir1" $tmpDir2Path = Join-Path -Path $TestDrive -ChildPath "tmpDir2" @@ -71,10 +71,10 @@ Describe "Test Unregister-PSResourceRepository" { } It "unregister repository using -PassThru" { - $res = Unregister-PSResourceRepository -Name $TestGalleryName -PassThru - $res.Name | Should -Be $TestGalleryName - $Res.Uri | Should -Be $TestGalleryUri - $res = Get-PSResourceRepository -Name $TestGalleryName -ErrorVariable err -ErrorAction SilentlyContinue + $res = Unregister-PSResourceRepository -Name $PSGalleryName -PassThru + $res.Name | Should -Be $PSGalleryName + $Res.Uri | Should -Be $PSGalleryUri + $res = Get-PSResourceRepository -Name $PSGalleryName -ErrorVariable err -ErrorAction SilentlyContinue $res | Should -BeNullOrEmpty $err.Count | Should -Not -Be 0 $err[0].FullyQualifiedErrorId | Should -BeExactly "ErrorGettingSpecifiedRepo,Microsoft.PowerShell.PowerShellGet.Cmdlets.GetPSResourceRepository" diff --git a/test/UpdatePSResource.Tests.ps1 b/test/UpdatePSResource.Tests.ps1 index bd081d970..05b2bbf7b 100644 --- a/test/UpdatePSResource.Tests.ps1 +++ b/test/UpdatePSResource.Tests.ps1 @@ -8,15 +8,17 @@ Describe 'Test Update-PSResource' { BeforeAll { - $TestGalleryName = Get-PoshTestGalleryName + $PSGalleryName = Get-PSGalleryName $NuGetGalleryName = Get-NuGetGalleryName - $testModuleName = "TestModule" + $testModuleName = "test_module" + $testModuleName2 = "test_module2" + $testModuleName3 = "TestModule99" Get-NewPSResourceRepositoryFile Get-PSResourceRepository } AfterEach { - Uninstall-PSResource "TestModule", "TestModule99", "TestModuleWithLicense", "PSGetTestModule" + Uninstall-PSResource "test_module", "TestModule99", "TestModuleWithLicense", "test_module2", "test_script" } AfterAll { @@ -24,15 +26,15 @@ Describe 'Test Update-PSResource' { } It "update resource installed given Name parameter" { - Install-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository - Update-PSResource -Name $testModuleName -Repository $TestGalleryName + Update-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository $res = Get-PSResource -Name $testModuleName $isPkgUpdated = $false foreach ($pkg in $res) { - if ([System.Version]$pkg.Version -gt [System.Version]"1.1.0.0") + if ([System.Version]$pkg.Version -gt [System.Version]"1.0.0.0") { $isPkgUpdated = $true } @@ -42,43 +44,43 @@ Describe 'Test Update-PSResource' { } It "update resources installed given Name (with wildcard) parameter" { - Install-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName - Install-PSResource -Name "TestModule99" -Version "0.0.4.0" -Repository $TestGalleryName + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository + Install-PSResource -Name $testModuleName2 -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository - Update-PSResource -Name "TestModule*" -Repository $TestGalleryName - $res = Get-PSResource -Name "TestModule*" + Update-PSResource -Name "test_mod*" -Repository $PSGalleryName -TrustRepository + $res = Get-PSResource -Name "test_mod*" -Version "5.0.0.0" - $inputHashtable = @{TestModule = "1.1.0.0"; TestModule99 = "0.0.4.0"} - $isTestModuleUpdated = $false - $isTestModule99Updated = $false + $inputHashtable = @{test_module = "1.0.0.0"; test_module2 = "1.0.0.0"} + $isTest_ModuleUpdated = $false + $isTest_Module2Updated = $false foreach ($item in $res) { if ([System.Version]$item.Version -gt [System.Version]$inputHashtable[$item.Name]) { if ($item.Name -like $testModuleName) { - $isTestModuleUpdated = $true + $isTest_ModuleUpdated = $true } - elseif ($item.Name -like "TestModule99") + elseif ($item.Name -like $testModuleName2) { - $isTestModule99Updated = $true + $isTest_Module2Updated = $true } } } - $isTestModuleUpdated | Should -BeTrue - $isTestModule99Updated | Should -BeTrue + $isTest_ModuleUpdated | Should -BeTrue + $isTest_Module2Updated | Should -BeTrue } It "update resource installed given Name and Version (specific) parameters" { - Install-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository - Update-PSResource -Name $testModuleName -Version "1.2.0.0" -Repository $TestGalleryName + Update-PSResource -Name $testModuleName -Version "5.0.0.0" -Repository $PSGalleryName -TrustRepository $res = Get-PSResource -Name $testModuleName $isPkgUpdated = $false foreach ($pkg in $res) { - if ([System.Version]$pkg.Version -eq [System.Version]"1.2.0.0") + if ([System.Version]$pkg.Version -eq [System.Version]"5.0.0.0") { $isPkgUpdated = $true } @@ -87,22 +89,22 @@ Describe 'Test Update-PSResource' { $isPkgUpdated | Should -BeTrue } - $testCases2 = @{Version="[1.3.0.0]"; ExpectedVersions=@("1.1.0.0", "1.3.0.0"); Reason="validate version, exact match"}, - @{Version="1.3.0.0"; ExpectedVersions=@("1.1.0.0", "1.3.0.0"); Reason="validate version, exact match without bracket syntax"}, - @{Version="[1.1.1.0, 1.3.0.0]"; ExpectedVersions=@("1.1.0.0", "1.3.0.0"); Reason="validate version, exact range inclusive"}, - @{Version="(1.1.1.0, 1.3.0.0)"; ExpectedVersions=@("1.1.0.0", "1.2.0.0"); Reason="validate version, exact range exclusive"}, - @{Version="(1.1.1.0,)"; ExpectedVersions=@("1.1.0.0", "1.3.0.0"); Reason="validate version, minimum version exclusive"}, - @{Version="[1.1.1.0,)"; ExpectedVersions=@("1.1.0.0", "1.3.0.0"); Reason="validate version, minimum version inclusive"}, - @{Version="(,1.3.0.0)"; ExpectedVersions=@("1.1.0.0", "1.2.0.0"); Reason="validate version, maximum version exclusive"}, - @{Version="(,1.3.0.0]"; ExpectedVersions=@("1.1.0.0", "1.3.0.0"); Reason="validate version, maximum version inclusive"}, - @{Version="[1.1.1.0, 1.3.0.0)"; ExpectedVersions=@("1.1.0.0", "1.2.0.0"); Reason="validate version, mixed inclusive minimum and exclusive maximum version"} - @{Version="(1.1.1.0, 1.3.0.0]"; ExpectedVersions=@("1.1.0.0", "1.2.0.0"); Reason="validate version, mixed exclusive minimum and inclusive maximum version"} + $testCases2 = @{Version="[3.0.0.0]"; ExpectedVersions=@("1.0.0.0", "3.0.0.0"); Reason="validate version, exact match"}, + @{Version="3.0.0.0"; ExpectedVersions=@("1.0.0.0", "3.0.0.0"); Reason="validate version, exact match without bracket syntax"}, + @{Version="[3.0.0.0, 5.0.0.0]"; ExpectedVersions=@("1.0.0.0", "3.0.0.0", "5.0.0.0"); Reason="validate version, exact range inclusive"}, + @{Version="(3.0.0.0, 6.0.0.0)"; ExpectedVersions=@("1.0.0.0", "3.0.0.0", "5.0.0.0"); Reason="validate version, exact range exclusive"}, + @{Version="(3.0.0.0,)"; ExpectedVersions=@("1.0.0.0", "5.0.0.0"); Reason="validate version, minimum version exclusive"}, + @{Version="[3.0.0.0,)"; ExpectedVersions=@("1.0.0.0", "3.0.0.0", "5.0.0.0"); Reason="validate version, minimum version inclusive"}, + @{Version="(,5.0.0.0)"; ExpectedVersions=@("1.0.0.0", "3.0.0.0"); Reason="validate version, maximum version exclusive"}, + @{Version="(,5.0.0.0]"; ExpectedVersions=@("1.0.0.0", "3.0.0.0", "5.0.0.0"); Reason="validate version, maximum version inclusive"}, + @{Version="[1.0.0.0, 5.0.0.0)"; ExpectedVersions=@("1.0.0.0", "3.0.0.0"); Reason="validate version, mixed inclusive minimum and exclusive maximum version"} + @{Version="(1.0.0.0, 3.0.0.0]"; ExpectedVersions=@("1.0.0.0", "3.0.0.0"); Reason="validate version, mixed exclusive minimum and inclusive maximum version"} It "update resource when given Name to " -TestCases $testCases2{ param($Version, $ExpectedVersions) - Install-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName - Update-PSResource -Name $testModuleName -Version $Version -Repository $TestGalleryName + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository + Update-PSResource -Name $testModuleName -Version $Version -Repository $PSGalleryName -TrustRepository $res = Get-PSResource -Name $testModuleName @@ -113,20 +115,20 @@ Describe 'Test Update-PSResource' { } $testCases = @( - @{Version='(1.2.0.0)'; Description="exclusive version (2.10.0.0)"}, - @{Version='[1-2-0-0]'; Description="version formatted with invalid delimiter [1-2-0-0]"} + @{Version='(3.0.0.0)'; Description="exclusive version (3.0.0.0)"}, + @{Version='[3-0-0-0]'; Description="version formatted with invalid delimiter [3-0-0-0]"} ) It "Should not update resource with incorrectly formatted version such as " -TestCases $testCases{ param($Version, $Description) - Install-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName - Update-PSResource -Name $testModuleName -Version $Version -Repository $TestGalleryName + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository + Update-PSResource -Name $testModuleName -Version $Version -Repository $PSGalleryName -TrustRepository $res = Get-PSResource -Name $testModuleName $isPkgUpdated = $false foreach ($pkg in $res) { - if ([System.Version]$pkg.Version -gt [System.Version]"1.1.0.0") + if ([System.Version]$pkg.Version -gt [System.Version]"1.0.0.0") { $isPkgUpdated = $true } @@ -136,18 +138,16 @@ Describe 'Test Update-PSResource' { } It "update resource with latest (including prerelease) version given Prerelease parameter" { - # PSGetTestModule resource's latest version is a prerelease version, before that it has a non-prerelease version - - Install-PSResource -Name "PSGetTestModule" -Version "1.0.2.0" -Repository $TestGalleryName - Update-PSResource -Name "PSGetTestModule" -Prerelease -Repository $TestGalleryName - $res = Get-PSResource -Name "PSGetTestModule" + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository + Update-PSResource -Name $testModuleName -Prerelease -Repository $PSGalleryName -TrustRepository + $res = Get-PSResource -Name $testModuleName $isPkgUpdated = $false foreach ($pkg in $res) { - if ([System.Version]$pkg.Version -gt [System.Version]"1.0.2.0") + if ([System.Version]$pkg.Version -ge [System.Version]"5.2.5") { - $pkg.Prerelease | Should -Be "alpha1" + $pkg.Prerelease | Should -Be "alpha001" $isPkgUpdated = $true } } @@ -158,17 +158,17 @@ Describe 'Test Update-PSResource' { # Windows only It "update resource under CurrentUser scope" -skip:(!$IsWindows) { # TODO: perhaps also install TestModule with the highest version (the one above 1.2.0.0) to the AllUsers path too - Install-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName -Scope AllUsers - Install-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName -Scope CurrentUser + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository -Scope AllUsers + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository -Scope CurrentUser - Update-PSResource -Name $testModuleName -Version "1.2.0.0" -Repository $TestGalleryName -Scope CurrentUser + Update-PSResource -Name $testModuleName -Version "3.0.0.0" -Repository $PSGalleryName -TrustRepository -Scope CurrentUser $res = Get-PSResource -Name $testModuleName $isPkgUpdated = $false foreach ($pkg in $res) { - if ([System.Version]$pkg.Version -gt [System.Version]"1.1.0.0") + if ([System.Version]$pkg.Version -gt [System.Version]"1.0.0.0") { $pkg.InstalledLocation.Contains("Documents") | Should -Be $true $isPkgUpdated = $true @@ -180,16 +180,16 @@ Describe 'Test Update-PSResource' { # Windows only It "update resource under AllUsers scope" -skip:(!($IsWindows -and (Test-IsAdmin))) { - Install-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName -Scope AllUsers - Install-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName -Scope CurrentUser + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository -Scope AllUsers + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository -Scope CurrentUser - Update-PSResource -Name $testModuleName -Version "1.2.0.0" -Repository $TestGalleryName -Scope AllUsers + Update-PSResource -Name $testModuleName -Version "3.0.0.0" -Repository $PSGalleryName -TrustRepository -Scope AllUsers $res = Get-PSResource -Name $testModuleName $isPkgUpdated = $false foreach ($pkg in $res) { - if ([System.Version]$pkg.Version -gt [System.Version]"1.1.0.0") + if ([System.Version]$pkg.Version -gt [System.Version]"1.0.0.0") { $pkg.InstalledLocation.Contains("Program Files") | Should -Be $true $isPkgUpdated = $true @@ -201,15 +201,15 @@ Describe 'Test Update-PSResource' { # Windows only It "update resource under no specified scope" -skip:(!$IsWindows) { - Install-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName - Update-PSResource -Name $testModuleName -Version "1.2.0.0" -Repository $TestGalleryName + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository + Update-PSResource -Name $testModuleName -Version "3.0.0.0" -Repository $PSGalleryName -TrustRepository $res = Get-PSResource -Name $testModuleName $isPkgUpdated = $false foreach ($pkg in $res) { - if ([System.Version]$pkg.Version -gt [System.Version]"1.1.0.0") + if ([System.Version]$pkg.Version -gt [System.Version]"1.0.0.0") { $pkg.InstalledLocation.Contains("Documents") | Should -Be $true $isPkgUpdated = $true @@ -224,16 +224,16 @@ Describe 'Test Update-PSResource' { It "Update resource under CurrentUser scope - Unix only" -Skip:(Get-IsWindows) { # this line is commented out because AllUsers scope requires sudo and that isn't supported in CI yet # Install-PSResource -Name "TestModule" -Version "1.1.0.0" -Repository $TestGalleryName -Scope AllUsers - Install-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName -Scope CurrentUser + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository -Scope CurrentUser - Update-PSResource -Name $testModuleName -Repository $TestGalleryName -Scope CurrentUser + Update-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository -Scope CurrentUser $res = Get-PSResource -Name $testModuleName $isPkgUpdated = $false foreach ($pkg in $res) { - if ([System.Version]$pkg.Version -gt [System.Version]"1.1.0.0") + if ([System.Version]$pkg.Version -gt [System.Version]"1.0.0.0") { $pkg.InstalledLocation.Contains("$env:HOME/.local") | Should -Be $true $isPkgUpdated = $true @@ -247,17 +247,17 @@ Describe 'Test Update-PSResource' { # Expected path should be similar to: '/usr/local/share/powershell/Modules' # this test is skipped because it requires sudo to run and has yet to be resolved in CI It "Update resource under AllUsers scope - Unix only" -Skip:($true) { - Install-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName -Scope AllUsers - Install-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName -Scope CurrentUser + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository -Scope AllUsers + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository -Scope CurrentUser - Update-PSResource -Name $testModuleName -Repository $TestGalleryName -Scope AllUsers + Update-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository -Scope AllUsers $res = Get-PSResource -Name $testModuleName $isPkgUpdated = $false foreach ($pkg in $res) { - if ([System.Version]$pkg.Version -gt [System.Version]"1.1.0.0") + if ([System.Version]$pkg.Version -gt [System.Version]"1.0.0.0") { $pkg.InstalledLocation.Contains("usr") | Should -Be $true $isPkgUpdated = $true @@ -272,16 +272,16 @@ Describe 'Test Update-PSResource' { It "Update resource under no specified scope - Unix only" -Skip:(Get-IsWindows) { # this is commented out because it requires sudo to run with AllUsers scope and this hasn't been resolved in CI yet # Install-PSResource -Name "TestModule" -Version "1.1.0.0" -Repository $TestGalleryName -Scope AllUsers - Install-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName -Scope CurrentUser + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository -Scope CurrentUser - Update-PSResource -Name $testModuleName -Repository $TestGalleryName + Update-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository $res = Get-PSResource -Name $testModuleName $isPkgUpdated = $false foreach ($pkg in $res) { - if ([System.Version]$pkg.Version -gt [System.Version]"1.1.0.0") + if ([System.Version]$pkg.Version -gt [System.Version]"1.0.0.0") { $pkg.InstalledLocation.Contains("$env:HOME/.local") | Should -Be $true $isPkgUpdated = $true @@ -291,54 +291,33 @@ Describe 'Test Update-PSResource' { $isPkgUpdated | Should -Be $true } - It "update resource that requires accept license with -AcceptLicense flag" { - Install-PSResource -Name "TestModuleWithLicense" -Version "0.0.1.0" -Repository $TestGalleryName -AcceptLicense - Update-PSResource -Name "TestModuleWithLicense" -Repository $TestGalleryName -AcceptLicense - $res = Get-PSResource "TestModuleWithLicense" - - $isPkgUpdated = $false - foreach ($pkg in $res) - { - if ([System.Version]$pkg.Version -gt [System.Version]"0.0.1.0") - { - $isPkgUpdated = $true - } - } - - $isPkgUpdated | Should -Be $true - } - - It "update resource should not prompt 'trust repository' if repository is not trusted but -TrustRepository is used" { - Install-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName - - Set-PSResourceRepository PoshTestGallery -Trusted:$false + # It "update resource that requires accept license with -AcceptLicense flag" { + # Install-PSResource -Name "TestModuleWithLicense" -Version "0.0.1.0" -Repository $TestGalleryName -AcceptLicense + # Update-PSResource -Name "TestModuleWithLicense" -Repository $TestGalleryName -AcceptLicense + # $res = Get-PSResource "TestModuleWithLicense" - Update-PSResource -Name $testModuleName -Version "1.2.0.0" -Repository $TestGalleryName -TrustRepository - $res = Get-PSResource -Name $testModuleName + # $isPkgUpdated = $false + # foreach ($pkg in $res) + # { + # if ([System.Version]$pkg.Version -gt [System.Version]"0.0.1.0") + # { + # $isPkgUpdated = $true + # } + # } - $isPkgUpdated = $false - foreach ($pkg in $res) - { - if ([System.Version]$pkg.Version -gt [System.Version]"1.1.0.0") - { - $isPkgUpdated = $true - } - } - - $isPkgUpdated | Should -BeTrue - Set-PSResourceRepository PoshTestGallery -Trusted - } + # $isPkgUpdated | Should -Be $true + # } It "Update module using -WhatIf, should not update the module" { - Install-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName - Update-PSResource -Name $testModuleName -WhatIf + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository + Update-PSResource -Name $testModuleName -WhatIf -Repository $PSGalleryName -TrustRepository $res = Get-PSResource -Name $testModuleName $isPkgUpdated = $false foreach ($pkg in $res) { - if ([System.Version]$pkg.Version -gt [System.Version]"1.1.0.0") + if ([System.Version]$pkg.Version -gt [System.Version]"1.0.0.0") { $isPkgUpdated = $true } @@ -348,10 +327,10 @@ Describe 'Test Update-PSResource' { } It "update resource installed given -Name and -PassThru parameters" { - Install-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository - $res = Update-PSResource -Name $testModuleName -Version "1.3.0.0" -Repository $TestGalleryName -PassThru - $res.Name | Should -Be $testModuleName - $res.Version | Should -Be "1.3.0.0" + $res = Update-PSResource -Name $testModuleName -Version "3.0.0.0" -Repository $PSGalleryName -TrustRepository -PassThru + $res.Name | Should -Contain $testModuleName + $res.Version | Should -Contain "3.0.0.0" } } diff --git a/test/testRepositories.xml b/test/testRepositories.xml index 6426f2c53..a0da40886 100644 --- a/test/testRepositories.xml +++ b/test/testRepositories.xml @@ -1,6 +1,5 @@ -