diff --git a/Tests/PSGetFindModule.Tests.ps1 b/Tests/PSGetFindModule.Tests.ps1 index 8be4d7dd..6ec4a46f 100644 --- a/Tests/PSGetFindModule.Tests.ps1 +++ b/Tests/PSGetFindModule.Tests.ps1 @@ -31,10 +31,9 @@ function SuiteSetup { $psgetModuleInfo = Import-Module PowerShellGet -Global -Force -Passthru Import-LocalizedData script:LocalizedData -filename PSGet.Resource.psd1 -BaseDirectory $psgetModuleInfo.ModuleBase - $script:moduleSourcesFilePath= Join-Path $script:PSGetLocalAppDataPath "PSRepositories.xml" + $script:moduleSourcesFilePath = Join-Path $script:PSGetLocalAppDataPath "PSRepositories.xml" $script:moduleSourcesBackupFilePath = Join-Path $script:PSGetLocalAppDataPath "PSRepositories.xml_$(get-random)_backup" - if(Test-Path $script:moduleSourcesFilePath) - { + if (Test-Path $script:moduleSourcesFilePath) { Rename-Item $script:moduleSourcesFilePath $script:moduleSourcesBackupFilePath -Force } @@ -42,12 +41,10 @@ function SuiteSetup { } function SuiteCleanup { - if(Test-Path $script:moduleSourcesBackupFilePath) - { + if (Test-Path $script:moduleSourcesBackupFilePath) { Move-Item $script:moduleSourcesBackupFilePath $script:moduleSourcesFilePath -Force } - else - { + else { RemoveItem $script:moduleSourcesFilePath } @@ -55,7 +52,7 @@ function SuiteCleanup { $null = Import-PackageProvider -Name PowerShellGet -Force } -Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' { +Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' { BeforeAll { SuiteSetup @@ -120,7 +117,29 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' { # It "FindModuleNonExistentModule" { AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module NonExistentModule} ` - -expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" + -expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" + } + + # Purpose: FindScriptNotModule + # + # Action: Find-Module Fabrikam-ServerScript + # + # Expected Result: Should fail + # + It "FindScriptNotModule" { + AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module Fabrikam-ServerScript} ` + -expectedFullyQualifiedErrorId 'MatchInvalidType,Find-Module' + } + + # Purpose: FindScriptNotModuleWildcard + # + # Action: Find-Module Fabrikam-ServerScript + # + # Expected Result: Should not return anything + # + It "FindScriptNotModuleWildcard" { + $res = Find-Module Fabrikam-ServerScript* + Assert (-not $res) "Find-Module returned a script" } # Purpose: FindModuleWithVersionParams @@ -131,7 +150,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' { # It "FindModuleWithVersionParams" { AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer -MinimumVersion 1.0 -RequiredVersion 5.0} ` - -expectedFullyQualifiedErrorId "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Find-Module" + -expectedFullyQualifiedErrorId "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Find-Module" } # Purpose: Find a module using MinimumVersion @@ -153,7 +172,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' { # It "FindModuleWithMinVersionNotAvailable" { AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer -MinimumVersion 10.0} ` - -expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" + -expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" } # Purpose: FindModuleWithReqVersionNotAvailable @@ -164,7 +183,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' { # It "FindModuleWithReqVersionNotAvailable" { AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer -RequiredVersion 10.0} ` - -expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" + -expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" } # Purpose: FindModuleWithRequiredVersion @@ -185,8 +204,8 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' { # Expected Result: Should fail with error id # It "FindModuleWithMultipleModuleNamesAndReqVersion" { - AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer,ContosoClient -RequiredVersion 1.0} ` - -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module" + AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer, ContosoClient -RequiredVersion 1.0} ` + -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module" } # Purpose: FindModuleWithMultipleModuleNamesAndMinVersion @@ -196,8 +215,8 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' { # Expected Result: Should fail with error id # It "FindModuleWithMultipleModuleNamesAndMinVersion" { - AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer,ContosoClient -MinimumVersion 1.0} ` - -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module" + AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer, ContosoClient -MinimumVersion 1.0} ` + -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module" } # Purpose: FindModuleWithWildcardNameAndReqVersion @@ -208,7 +227,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' { # It "FindModuleWithWildcardNameAndReqVersion" { AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module Contoso*er -RequiredVersion 1.0} ` - -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module" + -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module" } # Purpose: FindModuleWithWildcardNameAndMinVersion @@ -219,7 +238,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' { # It "FindModuleWithWildcardNameAndMinVersion" { AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module Contoso*er -MinimumVersion 1.0} ` - -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module" + -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module" } # Purpose: FindModuleWithMultiNames @@ -229,7 +248,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' { # Expected Result: should find ContosoClient and ContosoServer modules # It "FindModuleWithMultiNames" { - $res = Find-Module ContosoClient,ContosoServer -Repository PSGallery + $res = Find-Module ContosoClient, ContosoServer -Repository PSGallery Assert ($res.Count -eq 2) "Find-Module with multiple names should not fail, $res" } @@ -334,7 +353,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' { # Expected Result: Should return two role capabilities # It FindRoleCapabilityWithTwoRoleCapabilityNames { - $psgetRoleCapabilityInfos = Find-RoleCapability -Name Lev1Maintenance,Lev2Maintenance + $psgetRoleCapabilityInfos = Find-RoleCapability -Name Lev1Maintenance, Lev2Maintenance AssertEquals $psgetRoleCapabilityInfos.Count 2 "Find-RoleCapability did not return the expected RoleCapabilities, $psgetRoleCapabilityInfos" @@ -360,7 +379,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' { # Expected Result: Should return two resources # It FindDscResourceWithTwoResourceNames { - $psgetDscResourceInfos = Find-DscResource -Name DscTestResource,NewDscTestResource + $psgetDscResourceInfos = Find-DscResource -Name DscTestResource, NewDscTestResource Assert ($psgetDscResourceInfos.Count -ge 2) "Find-DscResource did not return the expected DscResources, $psgetDscResourceInfos" @@ -387,7 +406,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' { # Expected Result: Should return two command names # It FindCommandWithTwoResourceNames { - $psgetCommandInfos = Find-Command -Name Get-ContosoServer,Get-ContosoClient + $psgetCommandInfos = Find-Command -Name Get-ContosoServer, Get-ContosoClient Assert ($psgetCommandInfos.Count -ge 2) "Find-Command did not return the expected command names, $psgetCommandInfos" @@ -396,7 +415,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' { } } -Describe PowerShell.PSGet.FindModuleTests.P1 -Tags 'P1','OuterLoop' { +Describe PowerShell.PSGet.FindModuleTests.P1 -Tags 'P1', 'OuterLoop' { BeforeAll { SuiteSetup @@ -458,7 +477,7 @@ Describe PowerShell.PSGet.FindModuleTests.P1 -Tags 'P1','OuterLoop' { # It FindModuleWithAllVersionsAndMinimumVersion { AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoClient -MinimumVersion 2.0 -Repository PSGallery -AllVersions} ` - -expectedFullyQualifiedErrorId 'AllVersionsCannotBeUsedWithOtherVersionParameters,Find-Module' + -expectedFullyQualifiedErrorId 'AllVersionsCannotBeUsedWithOtherVersionParameters,Find-Module' } # Purpose: FindModuleWithAllVersionsAndRequiredVersion @@ -469,7 +488,7 @@ Describe PowerShell.PSGet.FindModuleTests.P1 -Tags 'P1','OuterLoop' { # It FindModuleWithAllVersionsAndRequiredVersion { AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoClient -RequiredVersion 2.0 -Repository PSGallery -AllVersions} ` - -expectedFullyQualifiedErrorId 'AllVersionsCannotBeUsedWithOtherVersionParameters,Find-Module' + -expectedFullyQualifiedErrorId 'AllVersionsCannotBeUsedWithOtherVersionParameters,Find-Module' } # Purpose: Validate Find-Module -Filter KeyWordNotExists @@ -498,7 +517,7 @@ Describe PowerShell.PSGet.FindModuleTests.P1 -Tags 'P1','OuterLoop' { $DepencyModuleNames = $res1.Dependencies.Name $res2 = Find-Module -Name $ModuleName -IncludeDependencies -MaximumVersion "1.0" -MinimumVersion "0.1" - Assert ($res2.Count -ge ($DepencyModuleNames.Count+1)) "Find-Module with -IncludeDependencies returned wrong results, $res2" + Assert ($res2.Count -ge ($DepencyModuleNames.Count + 1)) "Find-Module with -IncludeDependencies returned wrong results, $res2" $DepencyModuleNames | ForEach-Object { Assert ($res2.Name -Contains $_) "Find-Module with -IncludeDependencies didn't return the $_ module, $($res2.Name)"} } @@ -507,8 +526,8 @@ Describe PowerShell.PSGet.FindModuleTests.P1 -Tags 'P1','OuterLoop' { Describe PowerShell.PSGet.FindModuleTests.P2 -Tags 'P2', 'OuterLoop' { BeforeAll { - if(($PSEdition -eq 'Core') -or ($env:APPVEYOR_TEST_PASS -eq 'True')) { - return + if (($PSEdition -eq 'Core') -or ($env:APPVEYOR_TEST_PASS -eq 'True')) { + return } SuiteSetup @@ -518,8 +537,8 @@ Describe PowerShell.PSGet.FindModuleTests.P2 -Tags 'P2', 'OuterLoop' { SuiteCleanup } - if(($PSEdition -eq 'Core') -or ($env:APPVEYOR_TEST_PASS -eq 'True')) { - return + if (($PSEdition -eq 'Core') -or ($env:APPVEYOR_TEST_PASS -eq 'True')) { + return } <# @@ -533,11 +552,10 @@ Describe PowerShell.PSGet.FindModuleTests.P2 -Tags 'P2', 'OuterLoop' { $ParameterSetCount = $ParameterSets.Count $i = 1 - foreach ($inputParameters in $ParameterSets) - { + foreach ($inputParameters in $ParameterSets) { Write-Verbose -Message "Combination #$i out of $ParameterSetCount" Write-Verbose -Message "$($inputParameters | Out-String)" - Write-Progress -Activity "Combination $i out of $ParameterSetCount" -PercentComplete $(($i/$ParameterSetCount) * 100) + Write-Progress -Activity "Combination $i out of $ParameterSetCount" -PercentComplete $(($i / $ParameterSetCount) * 100) $params = $inputParameters.FindModuleInputParameters Write-Verbose -Message ($params | Out-String) @@ -546,25 +564,21 @@ Describe PowerShell.PSGet.FindModuleTests.P2 -Tags 'P2', 'OuterLoop' { It "FindModuleParameterCombinationsTests - Combination $i/$ParameterSetCount" { - if($inputParameters.PositiveCase) - { + if ($inputParameters.PositiveCase) { $res = Invoke-Command -ScriptBlock $scriptBlock - if($inputParameters.ExpectedModuleCount -gt 1) - { + if ($inputParameters.ExpectedModuleCount -gt 1) { Assert ($res.Count -ge $inputParameters.ExpectedModuleCount) "Combination #$i : Find-Module did not return expected module count. Actual value $($res.Count) should be greater than or equal to the expected value $($inputParameters.ExpectedModuleCount)." } - else - { + else { AssertEqualsCaseInsensitive $res.Name $inputParameters.ExpectedModuleNames "Combination #$i : Find-Module did not return expected module" } } - else - { + else { AssertFullyQualifiedErrorIdEquals -Scriptblock $scriptBlock -ExpectedFullyQualifiedErrorId $inputParameters.FullyQualifiedErrorId } } - $i = $i+1 - } + $i = $i + 1 + } } diff --git a/Tests/PSGetFindScript.Tests.ps1 b/Tests/PSGetFindScript.Tests.ps1 index cd340523..b1fd471e 100644 --- a/Tests/PSGetFindScript.Tests.ps1 +++ b/Tests/PSGetFindScript.Tests.ps1 @@ -17,7 +17,7 @@ function SuiteSetup { Import-Module "$PSScriptRoot\PSGetTestUtils.psm1" -WarningAction SilentlyContinue Import-Module "$PSScriptRoot\Asserts.psm1" -WarningAction SilentlyContinue - + $script:PSGetLocalAppDataPath = Get-PSGetLocalAppDataPath $script:DscTestScript = "DscTestScript" @@ -27,10 +27,9 @@ function SuiteSetup { $psgetModuleInfo = Import-Module PowerShellGet -Global -Force -Passthru Import-LocalizedData script:LocalizedData -filename PSGet.Resource.psd1 -BaseDirectory $psgetModuleInfo.ModuleBase - $script:moduleSourcesFilePath= Join-Path $script:PSGetLocalAppDataPath "PSRepositories.xml" + $script:moduleSourcesFilePath = Join-Path $script:PSGetLocalAppDataPath "PSRepositories.xml" $script:moduleSourcesBackupFilePath = Join-Path $script:PSGetLocalAppDataPath "PSRepositories.xml_$(get-random)_backup" - if(Test-Path $script:moduleSourcesFilePath) - { + if (Test-Path $script:moduleSourcesFilePath) { Rename-Item $script:moduleSourcesFilePath $script:moduleSourcesBackupFilePath -Force } @@ -38,12 +37,10 @@ function SuiteSetup { } function SuiteCleanup { - if(Test-Path $script:moduleSourcesBackupFilePath) - { + if (Test-Path $script:moduleSourcesBackupFilePath) { Move-Item $script:moduleSourcesBackupFilePath $script:moduleSourcesFilePath -Force } - else - { + else { RemoveItem $script:moduleSourcesFilePath } @@ -51,7 +48,7 @@ function SuiteCleanup { $null = Import-PackageProvider -Name PowerShellGet -Force } -Describe PowerShell.PSGet.FindScriptTests -Tags 'BVT','InnerLoop' { +Describe PowerShell.PSGet.FindScriptTests -Tags 'BVT', 'InnerLoop' { BeforeAll { SuiteSetup @@ -116,7 +113,29 @@ Describe PowerShell.PSGet.FindScriptTests -Tags 'BVT','InnerLoop' { # It "FindScriptNonExistentScript" { AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Script NonExistentScript} ` - -expectedFullyQualifiedErrorId 'NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage' + -expectedFullyQualifiedErrorId 'NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage' + } + + # Purpose: FindModuleNotScript + # + # Action: Find-Script ContosoServer + # + # Expected Result: Should fail + # + It "FindModuleNotScript" { + AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Script ContosoServer} ` + -expectedFullyQualifiedErrorId 'MatchInvalidType,Find-Script' + } + + # Purpose: FindModuleNotScriptWildcard + # + # Action: Find-Script ContosoServer + # + # Expected Result: Should not return anything + # + It "FindModuleNotScriptWildcard" { + $res = Find-Script ContosoServer* + Assert (-not $res) "Find-Script returned a module" } # Purpose: Find a script using MinimumVersion @@ -148,7 +167,7 @@ Describe PowerShell.PSGet.FindScriptTests -Tags 'BVT','InnerLoop' { # Expected Result: should find Fabrikam-ClientScript and Fabrikam-ServerScript scripts # It "FindScriptWithMultiNames" { - $res = Find-Script Fabrikam-ClientScript,Fabrikam-ServerScript -Repository PSGallery + $res = Find-Script Fabrikam-ClientScript, Fabrikam-ServerScript -Repository PSGallery Assert ($res.Count -eq 2) "Find-Script with multiple names should not fail, $res" } @@ -235,7 +254,7 @@ Describe PowerShell.PSGet.FindScriptTests -Tags 'BVT','InnerLoop' { } } -Describe PowerShell.PSGet.FindScriptTests.P1 -Tags 'P1','OuterLoop' { +Describe PowerShell.PSGet.FindScriptTests.P1 -Tags 'P1', 'OuterLoop' { BeforeAll { SuiteSetup @@ -288,7 +307,7 @@ Describe PowerShell.PSGet.FindScriptTests.P1 -Tags 'P1','OuterLoop' { $res = Find-Script *rikam-ServerScr* Assert ($res -and ($res.Name -eq "Fabrikam-ServerScript")) "Find-Script failed to find script using wild cards" } - + # Purpose: FindScriptWithVersionParams # # Action: Find-Script Fabrikam-ServerScript -MinimumVersion 1.0 -RequiredVersion 5.0 @@ -297,7 +316,7 @@ Describe PowerShell.PSGet.FindScriptTests.P1 -Tags 'P1','OuterLoop' { # It "FindScriptWithVersionParams" { AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Script Fabrikam-ServerScript -MinimumVersion 1.0 -RequiredVersion 5.0} ` - -expectedFullyQualifiedErrorId "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Find-Script" + -expectedFullyQualifiedErrorId "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Find-Script" } # Purpose: Find a script with not available MinimumVersion @@ -308,7 +327,7 @@ Describe PowerShell.PSGet.FindScriptTests.P1 -Tags 'P1','OuterLoop' { # It "FindScriptWithMinVersionNotAvailable" { AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Script Fabrikam-ServerScript -MinimumVersion 10.0} ` - -expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" + -expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" } # Purpose: FindScriptWithReqVersionNotAvailable @@ -319,7 +338,7 @@ Describe PowerShell.PSGet.FindScriptTests.P1 -Tags 'P1','OuterLoop' { # It "FindScriptWithReqVersionNotAvailable" { AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Script Fabrikam-ServerScript -RequiredVersion 10.0} ` - -expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" + -expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" } # Purpose: FindScriptWithMultipleScriptNamesAndReqVersion @@ -329,8 +348,8 @@ Describe PowerShell.PSGet.FindScriptTests.P1 -Tags 'P1','OuterLoop' { # Expected Result: Should fail with error id # It "FindScriptWithMultipleScriptNamesAndReqVersion" { - AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Script Fabrikam-ServerScript,Fabrikam-ClientScript -RequiredVersion 1.0} ` - -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Script" + AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Script Fabrikam-ServerScript, Fabrikam-ClientScript -RequiredVersion 1.0} ` + -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Script" } # Purpose: FindScriptWithMultipleScriptNamesAndMinVersion @@ -340,8 +359,8 @@ Describe PowerShell.PSGet.FindScriptTests.P1 -Tags 'P1','OuterLoop' { # Expected Result: Should fail with error id # It "FindScriptWithMultipleScriptNamesAndMinVersion" { - AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Script Fabrikam-ServerScript,Fabrikam-ClientScript -MinimumVersion 1.0} ` - -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Script" + AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Script Fabrikam-ServerScript, Fabrikam-ClientScript -MinimumVersion 1.0} ` + -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Script" } # Purpose: FindScriptWithWildcardNameAndReqVersion @@ -352,7 +371,7 @@ Describe PowerShell.PSGet.FindScriptTests.P1 -Tags 'P1','OuterLoop' { # It "FindScriptWithWildcardNameAndReqVersion" { AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Script Fabrikam-Ser*er -RequiredVersion 1.0} ` - -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Script" + -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Script" } # Purpose: FindScriptWithWildcardNameAndMinVersion @@ -363,7 +382,7 @@ Describe PowerShell.PSGet.FindScriptTests.P1 -Tags 'P1','OuterLoop' { # It "FindScriptWithWildcardNameAndMinVersion" { AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Script Fabrikam-Ser*er -MinimumVersion 1.0} ` - -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Script" + -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Script" } # Purpose: FindScriptWithAllVersionsAndMinimumVersion @@ -374,7 +393,7 @@ Describe PowerShell.PSGet.FindScriptTests.P1 -Tags 'P1','OuterLoop' { # It FindScriptWithAllVersionsAndMinimumVersion { AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Script Fabrikam-ClientScript -MinimumVersion 2.0 -Repository PSGallery -AllVersions} ` - -expectedFullyQualifiedErrorId 'AllVersionsCannotBeUsedWithOtherVersionParameters,Find-Script' + -expectedFullyQualifiedErrorId 'AllVersionsCannotBeUsedWithOtherVersionParameters,Find-Script' } # Purpose: FindScriptWithAllVersionsAndRequiredVersion @@ -385,7 +404,7 @@ Describe PowerShell.PSGet.FindScriptTests.P1 -Tags 'P1','OuterLoop' { # It FindScriptWithAllVersionsAndRequiredVersion { AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Script Fabrikam-ClientScript -RequiredVersion 2.0 -Repository PSGallery -AllVersions} ` - -expectedFullyQualifiedErrorId 'AllVersionsCannotBeUsedWithOtherVersionParameters,Find-Script' + -expectedFullyQualifiedErrorId 'AllVersionsCannotBeUsedWithOtherVersionParameters,Find-Script' } # Purpose: Validate Find-Script -Filter KeyWordNotExists @@ -414,7 +433,7 @@ Describe PowerShell.PSGet.FindScriptTests.P1 -Tags 'P1','OuterLoop' { $DepencyScriptNames = $res1.Dependencies.Name $res2 = Find-Script -Name $ScriptName -IncludeDependencies -MaximumVersion "1.0" -MinimumVersion "0.1" - Assert ($res2.Count -ge ($DepencyScriptNames.Count+1)) "Find-Script with -IncludeDependencies returned wrong results, $res2" + Assert ($res2.Count -ge ($DepencyScriptNames.Count + 1)) "Find-Script with -IncludeDependencies returned wrong results, $res2" $DepencyScriptNames | ForEach-Object { Assert ($res2.Name -Contains $_) "Find-Script with -IncludeDependencies didn't return the $_ script, $($res2.Name)"} } diff --git a/Tests/Pester.PSRepository.Tests.ps1 b/Tests/Pester.PSRepository.Tests.ps1 index 620cccdd..da964562 100644 --- a/Tests/Pester.PSRepository.Tests.ps1 +++ b/Tests/Pester.PSRepository.Tests.ps1 @@ -9,6 +9,7 @@ $SourceLocation = 'https://www.poshtestgallery.com/api/v2/' $PublishLocation = 'https://www.poshtestgallery.com/api/v2/package/' $ScriptSourceLocation = 'https://www.poshtestgallery.com/api/v2/items/psscript/' $ScriptPublishLocation = 'https://www.poshtestgallery.com/api/v2/package/' +$TestRepositoryName = 'PSTestGallery' Describe 'Test Register-PSRepository and Register-PackageSource for PSGallery repository' -tags 'BVT', 'InnerLoop' { @@ -249,3 +250,84 @@ Describe 'Test Set-PSRepository and Set-PackageSource for PSGallery repository' } ` -Skip:$($PSVersionTable.PSVersion -lt '5.0.0') } + +Describe 'Test Register-PSRepository for PSTestGallery repository' -tags 'BVT', 'InnerLoop' { + + BeforeAll { + Install-NuGetBinaries + Get-PSRepository | + Where-Object -Property SourceLocation -eq $SourceLocation | + Unregister-PSRepository + } + + BeforeEach { + Unregister-PSRepository -Name $TestRepositoryName -ErrorAction SilentlyContinue + } + + BeforeAll { + Unregister-PSRepository -Name $TestRepositoryName -ErrorAction SilentlyContinue + } + + It 'Register-PSRepository -Name $TestRepositoryName -SourceLocation $SourceLocation -ScriptSourceLocation $SourceLocation -PublishLocation $SourceLocation -ScriptPublishLocation $SourceLocation : Should work' { + $paramRegisterPSRepository = @{ + Name = $TestRepositoryName + SourceLocation = $SourceLocation + PublishLocation = $SourceLocation + ScriptSourceLocation = $SourceLocation + ScriptPublishLocation = $SourceLocation + } + + { Register-PSRepository @paramRegisterPSRepository } | Should not Throw + $repo = Get-PSRepository -Name $TestRepositoryName + $repo.SourceLocation | Should be $SourceLocation + $repo.ScriptSourceLocation | Should be $SourceLocation + $repo.PublishLocation | Should be $SourceLocation + $repo.ScriptPublishLocation | Should be $SourceLocation + } +} + +Describe 'Test Set-PSRepository for PSTestGallery repository' -tags 'BVT', 'InnerLoop' { + + BeforeAll { + Install-NuGetBinaries + Get-PSRepository | + Where-Object -Property SourceLocation -eq $SourceLocation | + Unregister-PSRepository + } + + BeforeEach { + Unregister-PSRepository -Name $TestRepositoryName -ErrorAction SilentlyContinue + } + + BeforeAll { + Unregister-PSRepository -Name $TestRepositoryName -ErrorAction SilentlyContinue + } + + It 'Set-PSRepository -Name $TestRepositoryName -SourceLocation $SourceLocation -ScriptSourceLocation $SourceLocation -PublishLocation $SourceLocation -ScriptPublishLocation $SourceLocation : Should work' { + $paramRegisterPSRepository = @{ + Name = $TestRepositoryName + SourceLocation = $SourceLocation + PublishLocation = $PublishLocation + ScriptSourceLocation = $ScriptSourceLocation + ScriptPublishLocation = $ScriptPublishLocation + } + + Register-PSRepository @paramRegisterPSRepository + + $paramSetPSRepository = @{ + Name = $TestRepositoryName + SourceLocation = $SourceLocation + PublishLocation = $SourceLocation + ScriptSourceLocation = $SourceLocation + ScriptPublishLocation = $SourceLocation + } + + { Set-PSRepository @paramSetPSRepository } | Should not Throw + + $repo = Get-PSRepository -Name $TestRepositoryName + $repo.SourceLocation | Should be $SourceLocation + $repo.ScriptSourceLocation | Should be $SourceLocation + $repo.PublishLocation | Should be $SourceLocation + $repo.ScriptPublishLocation | Should be $SourceLocation + } +} diff --git a/src/PowerShellGet/PSGet.Resource.psd1 b/src/PowerShellGet/PSGet.Resource.psd1 index 122b3235..b6704d17 100644 --- a/src/PowerShellGet/PSGet.Resource.psd1 +++ b/src/PowerShellGet/PSGet.Resource.psd1 @@ -95,6 +95,7 @@ ConvertFrom-StringData @' ModuleNotFound=Module '{0}' was not found. NoMatchFound=No match was found for the specified search criteria and module names '{0}'. NoMatchFoundForScriptName=No match was found for the specified search criteria and script names '{0}'. + MatchInvalidType=The name '{0}' is a {1} not a {2}. FailedToCreateCompressedModule=Failed to generate the compressed file for module '{0}'. FailedToPublish=Failed to publish module '{0}': '{1}'. PublishedSuccessfully=Successfully published module '{0}' to the module publish location '{1}'. Please allow few minutes for '{2}' to show up in the search results. @@ -208,7 +209,6 @@ ConvertFrom-StringData @' MissingRequiredPSScriptInfoProperties=Script '{0}' is missing required metadata properties. Verify that the script file has Version, Guid, Description and Author properties. You can use the Update-ScriptFileInfo or New-ScriptFileInfo cmdlet to add or update the PSScriptInfo to the script file. SkippedScriptDependency=Because dependent script '{0}' was skipped in the script dependencies list, users might not know how to install it. SourceLocationPathsForModulesAndScriptsShouldBeEqual=SourceLocation '{0}' and ScriptSourceLocation '{1}' should be same for SMB Share or Local directory based repositories. - SourceLocationUrisForModulesAndScriptsShouldBeDifferent=SourceLocation '{0}' and ScriptSourceLocation '{1}' should not be same for URI based repositories. PublishLocationPathsForModulesAndScriptsShouldBeEqual=PublishLocation '{0}' and ScriptPublishLocation '{1}' should be same for SMB Share or Local directory based repositories. SpecifiedNameIsAlearyUsed=The specified name '{0}' is already used for a different item on the specified repository '{1}'. Run '{2} -Name {0} -Repository {1}' to check whether the specified name '{0}' is already taken. InvalidScriptFilePath=The script file path '{0}' is not valid. The value of the Path argument must resolve to a single file that has a '.ps1' extension. Change the value of the Path argument to point to a valid ps1 file, and then try again. diff --git a/src/PowerShellGet/public/providerfunctions/Add-PackageSource.ps1 b/src/PowerShellGet/public/providerfunctions/Add-PackageSource.ps1 index 18667b84..5d9518f1 100644 --- a/src/PowerShellGet/public/providerfunctions/Add-PackageSource.ps1 +++ b/src/PowerShellGet/public/providerfunctions/Add-PackageSource.ps1 @@ -519,8 +519,7 @@ function Add-PackageSource } elseif($Options.ContainsKey($script:ScriptSourceLocation)) { - # ScriptSourceLocation and SourceLocation cannot be same for they are URLs - # Both should be equal in case of SMB Share or Local directory paths + # ScriptSourceLocation and SourceLocation should be equal for SMB Share or Local directory paths if(Microsoft.PowerShell.Management\Test-Path -LiteralPath $ScriptSourceLocation) { if($ScriptSourceLocation -ne $LocationString) @@ -534,26 +533,6 @@ function Add-PackageSource -ExceptionObject $Location } } - else - { - if($ScriptSourceLocation -eq $LocationString -and - -not ($LocationString.EndsWith('/nuget/v2', [System.StringComparison]::OrdinalIgnoreCase)) -and - -not ($LocationString.EndsWith('/nuget/v2/', [System.StringComparison]::OrdinalIgnoreCase)) -and - -not ($LocationString.EndsWith('/nuget', [System.StringComparison]::OrdinalIgnoreCase)) -and - -not ($LocationString.EndsWith('/nuget/', [System.StringComparison]::OrdinalIgnoreCase)) -and - -not ($LocationString.EndsWith('index.json', [System.StringComparison]::OrdinalIgnoreCase)) -and - -not ($LocationString.EndsWith('index.json/', [System.StringComparison]::OrdinalIgnoreCase)) - ) - { - $message = $LocalizedData.SourceLocationUrisForModulesAndScriptsShouldBeDifferent -f ($LocationString, $ScriptSourceLocation) - ThrowError -ExceptionName "System.InvalidOperationException" ` - -ExceptionMessage $message ` - -ErrorId "SourceLocationUrisForModulesAndScriptsShouldBeDifferent" ` - -CallerPSCmdlet $PSCmdlet ` - -ErrorCategory InvalidOperation ` - -ExceptionObject $Location - } - } } # no error so we can safely remove the source diff --git a/src/PowerShellGet/public/psgetfunctions/Find-Module.ps1 b/src/PowerShellGet/public/psgetfunctions/Find-Module.ps1 index b67821f7..f2e18750 100644 --- a/src/PowerShellGet/public/psgetfunctions/Find-Module.ps1 +++ b/src/PowerShellGet/public/psgetfunctions/Find-Module.ps1 @@ -146,16 +146,24 @@ function Find-Module { $psgetItemInfo = New-PSGetItemInfo -SoftwareIdentity $_ -Type $script:PSArtifactTypeModule - if ($AllVersions -and -not $AllowPrerelease) { - # If AllVersions is specified but not AllowPrerelease, we should only return stable release versions. - # PackageManagement returns ALL versions (including prerelease) when AllVersions is specified, regardless of the value of AllowPrerelease. - # Filtering results returned from PackageManagement based on flags. - if ($psgetItemInfo.AdditionalMetadata -and $psgetItemInfo.AdditionalMetadata.IsPrerelease -eq 'false') { + if ($psgetItemInfo.Type -eq $script:PSArtifactTypeModule) { + if ($AllVersions -and -not $AllowPrerelease) { + # If AllVersions is specified but not AllowPrerelease, we should only return stable release versions. + # PackageManagement returns ALL versions (including prerelease) when AllVersions is specified, regardless of the value of AllowPrerelease. + # Filtering results returned from PackageManagement based on flags. + if ($psgetItemInfo.AdditionalMetadata -and $psgetItemInfo.AdditionalMetadata.IsPrerelease -eq 'false') { + $psgetItemInfo + } + } + else { $psgetItemInfo } - } - else { - $psgetItemInfo + } elseif ($PSBoundParameters['Name'] -and -not (Test-WildcardPattern -Name ($Name | Microsoft.PowerShell.Core\Where-Object { $psgetItemInfo.Name -like $_ }))) { + $message = $LocalizedData.MatchInvalidType -f ($psgetItemInfo.Name, $psgetItemInfo.Type, $script:PSArtifactTypeModule) + Write-Error -Message $message ` + -ErrorId 'MatchInvalidType' ` + -Category InvalidArgument ` + -TargetObject $Name } if ($psgetItemInfo -and diff --git a/src/PowerShellGet/public/psgetfunctions/Find-Script.ps1 b/src/PowerShellGet/public/psgetfunctions/Find-Script.ps1 index 84597f6b..c169a946 100644 --- a/src/PowerShellGet/public/psgetfunctions/Find-Script.ps1 +++ b/src/PowerShellGet/public/psgetfunctions/Find-Script.ps1 @@ -154,16 +154,24 @@ function Find-Script { PackageManagement\Find-Package @PSBoundParameters | Microsoft.PowerShell.Core\ForEach-Object { $psgetItemInfo = New-PSGetItemInfo -SoftwareIdentity $_ -Type $script:PSArtifactTypeScript - if ($AllVersions -and -not $AllowPrerelease) { - # If AllVersions is specified but not AllowPrerelease, we should only return stable release versions. - # PackageManagement returns ALL versions (including prerelease) when AllVersions is specified, regardless of the value of AllowPrerelease. - # Filtering results returned from PackageManagement based on flags. - if ($psgetItemInfo.AdditionalMetadata -and $psgetItemInfo.AdditionalMetadata.IsPrerelease -eq $false) { + if ($psgetItemInfo.Type -eq $script:PSArtifactTypeScript) { + if ($AllVersions -and -not $AllowPrerelease) { + # If AllVersions is specified but not AllowPrerelease, we should only return stable release versions. + # PackageManagement returns ALL versions (including prerelease) when AllVersions is specified, regardless of the value of AllowPrerelease. + # Filtering results returned from PackageManagement based on flags. + if ($psgetItemInfo.AdditionalMetadata -and $psgetItemInfo.AdditionalMetadata.IsPrerelease -eq $false) { + $psgetItemInfo + } + } + else { $psgetItemInfo } - } - else { - $psgetItemInfo + } elseif ($PSBoundParameters['Name'] -and -not (Test-WildcardPattern -Name ($Name | Microsoft.PowerShell.Core\Where-Object { $psgetItemInfo.Name -like $_ }))) { + $message = $LocalizedData.MatchInvalidType -f ($psgetItemInfo.Name, $psgetItemInfo.Type, $script:PSArtifactTypeScript) + Write-Error -Message $message ` + -ErrorId 'MatchInvalidType' ` + -Category InvalidArgument ` + -TargetObject $Name } if ($psgetItemInfo -and