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

Fix #36 Allow piping psrepositories #420

Merged
merged 1 commit into from
Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 41 additions & 37 deletions Tests/Pester.PSRepository.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@ Import-Module "$PSScriptRoot\PSGetTestUtils.psm1" -WarningAction SilentlyContinu

$RepositoryName = 'PSGallery'
$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/'
$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/'

Describe 'Test Register-PSRepository and Register-PackageSource for PSGallery repository' -tags 'BVT','InnerLoop' {
Describe 'Test Register-PSRepository and Register-PackageSource for PSGallery repository' -tags 'BVT', 'InnerLoop' {

BeforeAll {
Install-NuGetBinaries
BeforeAll {
Install-NuGetBinaries
}

AfterAll {
if(Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue)
{
if (Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue) {
Set-PSRepository -Name $RepositoryName -InstallationPolicy Trusted
}
else
{
else {
Register-PSRepository -Default -InstallationPolicy Trusted
}
}
Expand All @@ -31,6 +29,16 @@ Describe 'Test Register-PSRepository and Register-PackageSource for PSGallery re
Unregister-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue
}

It 'Should pipe from Get-PSRepository to Set' {
Register-PSRepository -Default

Get-PSRepository $RepositoryName | Set-PSRepository -InstallationPolicy Trusted

$repo = Get-PSRepository $RepositoryName
$repo.Name | should be $RepositoryName
$repo.Trusted | should be $true
}

It 'Register-PSRepository -Default: Should work' {
Register-PSRepository -Default
$repo = Get-PSRepository $RepositoryName
Expand All @@ -57,14 +65,14 @@ Describe 'Test Register-PSRepository and Register-PackageSource for PSGallery re
Register-PSRepository -Default -ErrorVariable ev -ErrorAction SilentlyContinue
$ev[0].FullyQualifiedErrorId | Should be 'PackageSourceExists,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource'
} `
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')

It 'Register-PSRepository -Default:$false : Should not register' {
Register-PSRepository -Default:$false
Get-PSRepository PSGallery -ErrorVariable ev -ErrorAction SilentlyContinue
$ev[0].FullyQualifiedErrorId | Should be 'SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageSource'
} `
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')

It 'Register-PSRepository -Name PSGallery -SourceLocation $SourceLocation : Should fail' {
{ Register-PSRepository $RepositoryName $SourceLocation -ErrorVariable ev -ErrorAction SilentlyContinue } | Should Throw
Expand Down Expand Up @@ -100,51 +108,47 @@ Describe 'Test Register-PSRepository and Register-PackageSource for PSGallery re
Register-PackageSource -ProviderName PowerShellGet -Name $RepositoryName -Location $SourceLocation -ErrorVariable ev -ErrorAction SilentlyContinue
$ev[0].FullyQualifiedErrorId | Should be 'ParameterIsNotAllowedWithPSGallery,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource'
} `
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')

It 'Register-PackageSource -ProviderName PowerShellGet -Name PSGallery -PublishLocation $PublishLocation : Should fail' {
Register-PackageSource -ProviderName PowerShellGet -Name $RepositoryName -PublishLocation $PublishLocation -ErrorVariable ev -ErrorAction SilentlyContinue
$ev[0].FullyQualifiedErrorId | Should be 'ParameterIsNotAllowedWithPSGallery,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource'
} `
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')

It 'Register-PackageSource -ProviderName PowerShellGet -Name PSGallery -ScriptPublishLocation $ScriptPublishLocation : should fail' {
Register-PackageSource -ProviderName PowerShellGet -Name $RepositoryName -ScriptPublishLocation $ScriptPublishLocation -ErrorVariable ev -ErrorAction SilentlyContinue
$ev[0].FullyQualifiedErrorId | Should be 'ParameterIsNotAllowedWithPSGallery,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource'
} `
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')

It 'Register-PackageSource -ProviderName PowerShellGet -Name PSGallery -ScriptSourceLocation $ScriptSourceLocation : should fail' {
Register-PackageSource -ProviderName PowerShellGet -Name PSGallery -ScriptSourceLocation $ScriptSourceLocation -ErrorVariable ev -ErrorAction SilentlyContinue
$ev[0].FullyQualifiedErrorId | Should be 'ParameterIsNotAllowedWithPSGallery,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource'
} `
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
}

Describe 'Test Set-PSRepository and Set-PackageSource for PSGallery repository' -tags 'BVT','InnerLoop' {
Describe 'Test Set-PSRepository and Set-PackageSource for PSGallery repository' -tags 'BVT', 'InnerLoop' {

BeforeAll {
Install-NuGetBinaries
BeforeAll {
Install-NuGetBinaries
}

AfterAll {
if(Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue)
{
if (Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue) {
Set-PSRepository -Name $RepositoryName -InstallationPolicy Trusted
}
else
{
else {
Register-PSRepository -Default -InstallationPolicy Trusted
}
}

BeforeEach {
if(Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue)
{
if (Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue) {
Set-PSRepository -Name $RepositoryName -InstallationPolicy Untrusted
}
else
{
else {
Register-PSRepository -Default -InstallationPolicy Untrusted
}
}
Expand All @@ -168,25 +172,25 @@ Describe 'Test Set-PSRepository and Set-PackageSource for PSGallery repository'
Set-PSRepository $RepositoryName $SourceLocation -ErrorVariable ev -ErrorAction SilentlyContinue
$ev[0].FullyQualifiedErrorId | Should be 'ParameterIsNotAllowedWithPSGallery,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.SetPackageSource'
} `
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')

It 'Set-PSRepository -Name PSGallery -PublishLocation $PublishLocation : should fail' {
Set-PSRepository $RepositoryName -PublishLocation $PublishLocation -ErrorVariable ev -ErrorAction SilentlyContinue
$ev[0].FullyQualifiedErrorId | Should be 'ParameterIsNotAllowedWithPSGallery,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.SetPackageSource'
} `
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')

It 'Set-PSRepository -Name PSGallery -ScriptPublishLocation $ScriptPublishLocation : should fail' {
Set-PSRepository $RepositoryName -ScriptPublishLocation $ScriptPublishLocation -ErrorVariable ev -ErrorAction SilentlyContinue
$ev[0].FullyQualifiedErrorId | Should be 'ParameterIsNotAllowedWithPSGallery,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.SetPackageSource'
} `
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')

It 'Set-PSRepository -Name PSGallery -ScriptSourceLocation $ScriptSourceLocation : should fail' {
Set-PSRepository -Name $RepositoryName -ScriptSourceLocation $ScriptSourceLocation -ErrorVariable ev -ErrorAction SilentlyContinue
$ev[0].FullyQualifiedErrorId | Should be 'ParameterIsNotAllowedWithPSGallery,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.SetPackageSource'
} `
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')

It 'Set-PackageSource -ProviderName PowerShellGet -Name PSGallery : should work actually this is a no-op. Installation policy should not be changed' {
Set-PackageSource -ProviderName PowerShellGet -Name $RepositoryName
Expand All @@ -206,23 +210,23 @@ Describe 'Test Set-PSRepository and Set-PackageSource for PSGallery repository'
Set-PackageSource -ProviderName PowerShellGet -Name $RepositoryName -NewLocation $SourceLocation -ErrorVariable ev -ErrorAction SilentlyContinue
$ev[0].FullyQualifiedErrorId | Should be 'ParameterIsNotAllowedWithPSGallery,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.SetPackageSource'
} `
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')

It 'Set-PackageSource -ProviderName PowerShellGet -Name PSGallery -PublishLocation $PublishLocation : should fail' {
Set-PackageSource -ProviderName PowerShellGet -Name $RepositoryName -PublishLocation $PublishLocation -ErrorVariable ev -ErrorAction SilentlyContinue
$ev[0].FullyQualifiedErrorId | Should be 'ParameterIsNotAllowedWithPSGallery,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.SetPackageSource'
} `
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')

It 'Set-PackageSource -ProviderName PowerShellGet -Name PSGallery -ScriptPublishLocation $ScriptPublishLocation : should fail' {
Set-PackageSource -ProviderName PowerShellGet -Name $RepositoryName -ScriptPublishLocation $ScriptPublishLocation -ErrorVariable ev -ErrorAction SilentlyContinue
$ev[0].FullyQualifiedErrorId | Should be 'ParameterIsNotAllowedWithPSGallery,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.SetPackageSource'
} `
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')

It 'Set-PackageSource -ProviderName PowerShellGet -Name PSGallery -ScriptSourceLocation $ScriptSourceLocation : should fail' {
Set-PackageSource -ProviderName PowerShellGet -Name $RepositoryName -ScriptSourceLocation $ScriptSourceLocation -ErrorVariable ev -ErrorAction SilentlyContinue
$ev[0].FullyQualifiedErrorId | Should be 'ParameterIsNotAllowedWithPSGallery,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.SetPackageSource'
} `
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
}
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
}
4 changes: 2 additions & 2 deletions src/PowerShellGet/public/psgetfunctions/Set-PSRepository.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Set-PSRepository {
HelpUri = 'https://go.microsoft.com/fwlink/?LinkID=517128')]
Param
(
[Parameter(Mandatory = $true, Position = 0)]
[Parameter(Mandatory = $true, Position = 0, ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[string]
$Name,
Expand Down Expand Up @@ -166,7 +166,7 @@ function Set-PSRepository {
}

$PSBoundParameters[$script:PackageManagementProviderParam] = $PackageManagementProvider
$PSBoundParameters.Add("Trusted", $Trusted)
$PSBoundParameters["Trusted"] = $Trusted
$PSBoundParameters["Provider"] = $script:PSModuleProviderName
$PSBoundParameters["MessageResolver"] = $script:PackageManagementMessageResolverScriptBlock

Expand Down