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

Commit 0ebdc02

Browse files
edyoungalerickson
authored andcommitted
Fix #36 Allow piping psrepositories (#420)
1 parent eb4e2cc commit 0ebdc02

File tree

2 files changed

+43
-39
lines changed

2 files changed

+43
-39
lines changed

Tests/Pester.PSRepository.Tests.ps1

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@ Import-Module "$PSScriptRoot\PSGetTestUtils.psm1" -WarningAction SilentlyContinu
66

77
$RepositoryName = 'PSGallery'
88
$SourceLocation = 'https://www.poshtestgallery.com/api/v2/'
9-
$PublishLocation= 'https://www.poshtestgallery.com/api/v2/package/'
10-
$ScriptSourceLocation= 'https://www.poshtestgallery.com/api/v2/items/psscript/'
11-
$ScriptPublishLocation= 'https://www.poshtestgallery.com/api/v2/package/'
9+
$PublishLocation = 'https://www.poshtestgallery.com/api/v2/package/'
10+
$ScriptSourceLocation = 'https://www.poshtestgallery.com/api/v2/items/psscript/'
11+
$ScriptPublishLocation = 'https://www.poshtestgallery.com/api/v2/package/'
1212

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

15-
BeforeAll {
16-
Install-NuGetBinaries
15+
BeforeAll {
16+
Install-NuGetBinaries
1717
}
1818

1919
AfterAll {
20-
if(Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue)
21-
{
20+
if (Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue) {
2221
Set-PSRepository -Name $RepositoryName -InstallationPolicy Trusted
2322
}
24-
else
25-
{
23+
else {
2624
Register-PSRepository -Default -InstallationPolicy Trusted
2725
}
2826
}
@@ -31,6 +29,16 @@ Describe 'Test Register-PSRepository and Register-PackageSource for PSGallery re
3129
Unregister-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue
3230
}
3331

32+
It 'Should pipe from Get-PSRepository to Set' {
33+
Register-PSRepository -Default
34+
35+
Get-PSRepository $RepositoryName | Set-PSRepository -InstallationPolicy Trusted
36+
37+
$repo = Get-PSRepository $RepositoryName
38+
$repo.Name | should be $RepositoryName
39+
$repo.Trusted | should be $true
40+
}
41+
3442
It 'Register-PSRepository -Default: Should work' {
3543
Register-PSRepository -Default
3644
$repo = Get-PSRepository $RepositoryName
@@ -57,14 +65,14 @@ Describe 'Test Register-PSRepository and Register-PackageSource for PSGallery re
5765
Register-PSRepository -Default -ErrorVariable ev -ErrorAction SilentlyContinue
5866
$ev[0].FullyQualifiedErrorId | Should be 'PackageSourceExists,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource'
5967
} `
60-
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
68+
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
6169

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

6977
It 'Register-PSRepository -Name PSGallery -SourceLocation $SourceLocation : Should fail' {
7078
{ Register-PSRepository $RepositoryName $SourceLocation -ErrorVariable ev -ErrorAction SilentlyContinue } | Should Throw
@@ -100,51 +108,47 @@ Describe 'Test Register-PSRepository and Register-PackageSource for PSGallery re
100108
Register-PackageSource -ProviderName PowerShellGet -Name $RepositoryName -Location $SourceLocation -ErrorVariable ev -ErrorAction SilentlyContinue
101109
$ev[0].FullyQualifiedErrorId | Should be 'ParameterIsNotAllowedWithPSGallery,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource'
102110
} `
103-
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
104-
111+
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
112+
105113
It 'Register-PackageSource -ProviderName PowerShellGet -Name PSGallery -PublishLocation $PublishLocation : Should fail' {
106114
Register-PackageSource -ProviderName PowerShellGet -Name $RepositoryName -PublishLocation $PublishLocation -ErrorVariable ev -ErrorAction SilentlyContinue
107115
$ev[0].FullyQualifiedErrorId | Should be 'ParameterIsNotAllowedWithPSGallery,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource'
108116
} `
109-
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
117+
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
110118

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

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

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

126-
BeforeAll {
127-
Install-NuGetBinaries
134+
BeforeAll {
135+
Install-NuGetBinaries
128136
}
129137

130138
AfterAll {
131-
if(Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue)
132-
{
139+
if (Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue) {
133140
Set-PSRepository -Name $RepositoryName -InstallationPolicy Trusted
134141
}
135-
else
136-
{
142+
else {
137143
Register-PSRepository -Default -InstallationPolicy Trusted
138144
}
139145
}
140146

141147
BeforeEach {
142-
if(Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue)
143-
{
148+
if (Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue) {
144149
Set-PSRepository -Name $RepositoryName -InstallationPolicy Untrusted
145150
}
146-
else
147-
{
151+
else {
148152
Register-PSRepository -Default -InstallationPolicy Untrusted
149153
}
150154
}
@@ -168,25 +172,25 @@ Describe 'Test Set-PSRepository and Set-PackageSource for PSGallery repository'
168172
Set-PSRepository $RepositoryName $SourceLocation -ErrorVariable ev -ErrorAction SilentlyContinue
169173
$ev[0].FullyQualifiedErrorId | Should be 'ParameterIsNotAllowedWithPSGallery,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.SetPackageSource'
170174
} `
171-
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
175+
-Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
172176

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

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

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

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

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

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

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

src/PowerShellGet/public/psgetfunctions/Set-PSRepository.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function Set-PSRepository {
66
HelpUri = 'https://go.microsoft.com/fwlink/?LinkID=517128')]
77
Param
88
(
9-
[Parameter(Mandatory = $true, Position = 0)]
9+
[Parameter(Mandatory = $true, Position = 0, ValueFromPipelineByPropertyName = $true)]
1010
[ValidateNotNullOrEmpty()]
1111
[string]
1212
$Name,
@@ -166,7 +166,7 @@ function Set-PSRepository {
166166
}
167167

168168
$PSBoundParameters[$script:PackageManagementProviderParam] = $PackageManagementProvider
169-
$PSBoundParameters.Add("Trusted", $Trusted)
169+
$PSBoundParameters["Trusted"] = $Trusted
170170
$PSBoundParameters["Provider"] = $script:PSModuleProviderName
171171
$PSBoundParameters["MessageResolver"] = $script:PackageManagementMessageResolverScriptBlock
172172

0 commit comments

Comments
 (0)