Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe11ba4

Browse files
authored
Re-enable PowerShellGet tests targeting PowerShell gallery (#17062)
1 parent dc0eff2 commit fe11ba4

2 files changed

Lines changed: 40 additions & 69 deletions

File tree

test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,22 @@
1313
#
1414
# ------------------ PackageManagement Test -----------------------------------
1515

16-
$InternalGallery = "https://www.poshtestgallery.com/api/v2/"
17-
$InternalSource = 'OneGetTestSource'
16+
$gallery = "https://www.powershellgallery.com/api/v2"
17+
$source = 'OneGetTestSource'
1818

1919
Describe "PackageManagement Acceptance Test" -Tags "Feature" {
2020

2121
BeforeAll{
2222
Register-PackageSource -Name Nugettest -provider NuGet -Location https://www.nuget.org/api/v2 -Force
2323

24-
## Comment out this line because 'poshtestgallery.com' is down, tracked by https://github.com/PowerShell/PowerShell/issues/17019
25-
## Register-PackageSource -Name $InternalSource -Location $InternalGallery -ProviderName 'PowerShellGet' -Trusted -ErrorAction SilentlyContinue
24+
$packageSource = Get-PackageSource -Location $gallery -ErrorAction SilentlyContinue
25+
if ($packageSource) {
26+
$source = $packageSource.Name
27+
Set-PackageSource -Name $source -Trusted
28+
} else {
29+
Register-PackageSource -Name $source -Location $gallery -ProviderName 'PowerShellGet' -Trusted -ErrorAction SilentlyContinue
30+
}
31+
2632
$SavedProgressPreference = $ProgressPreference
2733
$ProgressPreference = "SilentlyContinue"
2834
}
@@ -43,10 +49,9 @@ Describe "PackageManagement Acceptance Test" -Tags "Feature" {
4349
$fpp | Should -Contain "PowerShellGet"
4450
}
4551

46-
## Make this test pending because 'poshtestgallery.com' is down, tracked by https://github.com/PowerShell/PowerShell/issues/17019
47-
It "install-packageprovider, Expect succeed" -Pending {
48-
$ipp = (Install-PackageProvider -Name gistprovider -Force -Source $InternalSource -Scope CurrentUser).name
49-
$ipp | Should -Contain "gistprovider"
52+
It "install-packageprovider, Expect succeed" {
53+
$ipp = (Install-PackageProvider -Name NanoServerPackage -Force -Source $source -Scope CurrentUser).name
54+
$ipp | Should -Contain "NanoServerPackage"
5055
}
5156

5257
It "Find-package" {

test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1

Lines changed: 27 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
# no progress output during these tests
55
$ProgressPreference = "SilentlyContinue"
66

7-
$RepositoryName = 'INTGallery'
8-
$SourceLocation = 'https://www.poshtestgallery.com'
9-
$RegisteredINTRepo = $false
10-
$ContosoServer = 'ContosoServer'
11-
$FabrikamServerScript = 'Fabrikam-ServerScript'
7+
$RepositoryName = 'PSGallery'
8+
$SourceLocation = 'https://www.powershellgallery.com'
9+
$TestModule = 'newTestModule'
10+
$TestScript = 'TestTestScript'
1211
$Initialized = $false
1312

1413
#region Utility functions
@@ -93,30 +92,24 @@ function Initialize
9392
if($repo)
9493
{
9594
$script:RepositoryName = $repo.Name
95+
Set-PackageSource -Name $repo.Name -Trusted
9696
}
9797
else
9898
{
9999
Register-PSRepository -Name $RepositoryName -SourceLocation $SourceLocation -InstallationPolicy Trusted
100-
$script:RegisteredINTRepo = $true
101100
}
102101
}
103102

104103
#endregion
105104

106105
function Remove-InstalledModules
107106
{
108-
Get-InstalledModule -Name $ContosoServer -AllVersions -ErrorAction SilentlyContinue | PowerShellGet\Uninstall-Module -Force
107+
Get-InstalledModule -Name $TestModule -AllVersions -ErrorAction SilentlyContinue | PowerShellGet\Uninstall-Module -Force
109108
}
110109

111110
Describe "PowerShellGet - Module tests" -tags "Feature" {
112111

113112
BeforeAll {
114-
# Setting all It block to pending as the test fail due to https://github.com/PowerShell/PowerShell/issues/17019
115-
# These should be re-enabled when the issue is fixed
116-
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
117-
$PSDefaultParameterValues["it:pending"] = $true
118-
return
119-
120113
if ($script:Initialized -eq $false) {
121114
Initialize
122115
$script:Initialized = $true
@@ -128,39 +121,32 @@ Describe "PowerShellGet - Module tests" -tags "Feature" {
128121
}
129122

130123
It "Should find a module correctly" {
131-
$psgetModuleInfo = Find-Module -Name $ContosoServer -Repository $RepositoryName
132-
$psgetModuleInfo.Name | Should -Be $ContosoServer
124+
$psgetModuleInfo = Find-Module -Name $TestModule -Repository $RepositoryName
125+
$psgetModuleInfo.Name | Should -Be $TestModule
133126
$psgetModuleInfo.Repository | Should -Be $RepositoryName
134127
}
135128

136129
It "Should install a module correctly to the required location with default CurrentUser scope" {
137-
Install-Module -Name $ContosoServer -Repository $RepositoryName
138-
$installedModuleInfo = Get-InstalledModule -Name $ContosoServer
130+
Install-Module -Name $TestModule -Repository $RepositoryName
131+
$installedModuleInfo = Get-InstalledModule -Name $TestModule
139132

140133
$installedModuleInfo | Should -Not -BeNullOrEmpty
141-
$installedModuleInfo.Name | Should -Be $ContosoServer
134+
$installedModuleInfo.Name | Should -Be $TestModule
142135
$installedModuleInfo.InstalledLocation.StartsWith($script:MyDocumentsModulesPath, [System.StringComparison]::OrdinalIgnoreCase) | Should -BeTrue
143136

144-
$module = Get-Module $ContosoServer -ListAvailable
145-
$module.Name | Should -Be $ContosoServer
137+
$module = Get-Module $TestModule -ListAvailable
138+
$module.Name | Should -Be $TestModule
146139
$module.ModuleBase | Should -Be $installedModuleInfo.InstalledLocation
147140
}
148141

149142
AfterAll {
150-
$global:PSDefaultParameterValues = $originalDefaultParameterValues
151143
Remove-InstalledModules
152144
}
153145
}
154146

155147
Describe "PowerShellGet - Module tests (Admin)" -Tags @('Feature', 'RequireAdminOnWindows', 'RequireSudoOnUnix') {
156148

157149
BeforeAll {
158-
# Setting all It block to pending as the test fail due to https://github.com/PowerShell/PowerShell/issues/17019
159-
# These should be re-enabled when the issue is fixed
160-
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
161-
$PSDefaultParameterValues["it:pending"] = $true
162-
return
163-
164150
if ($script:Initialized -eq $false) {
165151
Initialize
166152
$script:Initialized = $true
@@ -172,38 +158,31 @@ Describe "PowerShellGet - Module tests (Admin)" -Tags @('Feature', 'RequireAdmin
172158
}
173159

174160
It "Should install a module correctly to the required location with AllUsers scope" {
175-
Install-Module -Name $ContosoServer -Repository $RepositoryName -Scope AllUsers
176-
$installedModuleInfo = Get-InstalledModule -Name $ContosoServer
161+
Install-Module -Name $TestModule -Repository $RepositoryName -Scope AllUsers
162+
$installedModuleInfo = Get-InstalledModule -Name $TestModule
177163

178164
$installedModuleInfo | Should -Not -BeNullOrEmpty
179-
$installedModuleInfo.Name | Should -Be $ContosoServer
165+
$installedModuleInfo.Name | Should -Be $TestModule
180166
$installedModuleInfo.InstalledLocation.StartsWith($script:programFilesModulesPath, [System.StringComparison]::OrdinalIgnoreCase) | Should -BeTrue
181167

182-
$module = Get-Module $ContosoServer -ListAvailable
183-
$module.Name | Should -Be $ContosoServer
168+
$module = Get-Module $TestModule -ListAvailable
169+
$module.Name | Should -Be $TestModule
184170
$module.ModuleBase | Should -Be $installedModuleInfo.InstalledLocation
185171
}
186172

187173
AfterAll {
188-
$global:PSDefaultParameterValues = $originalDefaultParameterValues
189174
Remove-InstalledModules
190175
}
191176
}
192177

193178
function Remove-InstalledScripts
194179
{
195-
Get-InstalledScript -Name $FabrikamServerScript -ErrorAction SilentlyContinue | Uninstall-Script -Force
180+
Get-InstalledScript -Name $TestScript -ErrorAction SilentlyContinue | Uninstall-Script -Force
196181
}
197182

198183
Describe "PowerShellGet - Script tests" -tags "Feature" {
199184

200185
BeforeAll {
201-
# Setting all It block to pending as the test fail due to https://github.com/PowerShell/PowerShell/issues/17019
202-
# These should be re-enabled when the issue is fixed
203-
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
204-
$PSDefaultParameterValues["it:pending"] = $true
205-
return
206-
207186
if ($script:Initialized -eq $false) {
208187
Initialize
209188
$script:Initialized = $true
@@ -215,35 +194,28 @@ Describe "PowerShellGet - Script tests" -tags "Feature" {
215194
}
216195

217196
It "Should find a script correctly" {
218-
$psgetScriptInfo = Find-Script -Name $FabrikamServerScript -Repository $RepositoryName
219-
$psgetScriptInfo.Name | Should -Be $FabrikamServerScript
197+
$psgetScriptInfo = Find-Script -Name $TestScript -Repository $RepositoryName
198+
$psgetScriptInfo.Name | Should -Be $TestScript
220199
$psgetScriptInfo.Repository | Should -Be $RepositoryName
221200
}
222201

223202
It "Should install a script correctly to the required location with default CurrentUser scope" {
224-
Install-Script -Name $FabrikamServerScript -Repository $RepositoryName -NoPathUpdate
225-
$installedScriptInfo = Get-InstalledScript -Name $FabrikamServerScript
203+
Install-Script -Name $TestScript -Repository $RepositoryName -NoPathUpdate
204+
$installedScriptInfo = Get-InstalledScript -Name $TestScript
226205

227206
$installedScriptInfo | Should -Not -BeNullOrEmpty
228-
$installedScriptInfo.Name | Should -Be $FabrikamServerScript
207+
$installedScriptInfo.Name | Should -Be $TestScript
229208
$installedScriptInfo.InstalledLocation.StartsWith($script:MyDocumentsScriptsPath, [System.StringComparison]::OrdinalIgnoreCase) | Should -BeTrue
230209
}
231210

232211
AfterAll {
233-
$global:PSDefaultParameterValues = $originalDefaultParameterValues
234212
Remove-InstalledScripts
235213
}
236214
}
237215

238216
Describe "PowerShellGet - Script tests (Admin)" -Tags @('Feature', 'RequireAdminOnWindows', 'RequireSudoOnUnix') {
239217

240218
BeforeAll {
241-
# Setting all It block to pending as the test fail due to https://github.com/PowerShell/PowerShell/issues/17019
242-
# These should be re-enabled when the issue is fixed
243-
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
244-
$PSDefaultParameterValues["it:pending"] = $true
245-
return
246-
247219
if ($script:Initialized -eq $false) {
248220
Initialize
249221
$script:Initialized = $true
@@ -255,16 +227,15 @@ Describe "PowerShellGet - Script tests (Admin)" -Tags @('Feature', 'RequireAdmin
255227
}
256228

257229
It "Should install a script correctly to the required location with AllUsers scope" {
258-
Install-Script -Name $FabrikamServerScript -Repository $RepositoryName -NoPathUpdate -Scope AllUsers
259-
$installedScriptInfo = Get-InstalledScript -Name $FabrikamServerScript
230+
Install-Script -Name $TestScript -Repository $RepositoryName -NoPathUpdate -Scope AllUsers
231+
$installedScriptInfo = Get-InstalledScript -Name $TestScript
260232

261233
$installedScriptInfo | Should -Not -BeNullOrEmpty
262-
$installedScriptInfo.Name | Should -Be $FabrikamServerScript
234+
$installedScriptInfo.Name | Should -Be $TestScript
263235
$installedScriptInfo.InstalledLocation.StartsWith($script:ProgramFilesScriptsPath, [System.StringComparison]::OrdinalIgnoreCase) | Should -BeTrue
264236
}
265237

266238
AfterAll {
267-
$global:PSDefaultParameterValues = $originalDefaultParameterValues
268239
Remove-InstalledScripts
269240
}
270241
}
@@ -300,8 +271,3 @@ Describe 'PowerShellGet Type tests' -tags @('CI') {
300271
}
301272
}
302273
}
303-
304-
if($RegisteredINTRepo)
305-
{
306-
Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue | Unregister-PSRepository
307-
}

0 commit comments

Comments
 (0)