1818function SuiteSetup {
1919 Import-Module " $PSScriptRoot \PSGetTestUtils.psm1" - WarningAction SilentlyContinue
2020 Import-Module " $PSScriptRoot \Asserts.psm1" - WarningAction SilentlyContinue
21-
21+
2222 $script :ProgramFilesModulesPath = Get-AllUsersModulesPath
2323 $script :MyDocumentsModulesPath = Get-CurrentUserModulesPath
2424 $script :PSGetLocalAppDataPath = Get-PSGetLocalAppDataPath
@@ -84,7 +84,7 @@ function SuiteCleanup {
8484 RemoveItem $script :TempModulesPath
8585}
8686
87- Describe PowerShell.PSGet.ModuleSourceTests - Tags ' BVT' , ' InnerLoop' {
87+ Describe PowerShell.PSGet.ModuleSourceTests - Tags ' BVT' , ' InnerLoop' {
8888
8989 BeforeAll {
9090 SuiteSetup
@@ -103,11 +103,11 @@ Describe PowerShell.PSGet.ModuleSourceTests -Tags 'BVT','InnerLoop' {
103103 #>
104104 It RegisterAngGetModuleSource {
105105
106- $Name = ' MyTestModSourceForRegisterAngGet'
107- $Location = ' https://www.nuget.org/api/v2/'
106+ $Name = ' MyTestModSourceForRegisterAngGet'
107+ $Location = ' https://www.nuget.org/api/v2/'
108108
109109 Register-PSRepository - Default - ErrorAction SilentlyContinue
110-
110+
111111 try {
112112 Register-PSRepository - Name $Name - SourceLocation $Location
113113 $moduleSource = Get-PSRepository - Name $Name
@@ -137,19 +137,17 @@ Describe PowerShell.PSGet.ModuleSourceTests -Tags 'BVT','InnerLoop' {
137137 #>
138138 It RegisterSMBShareRepository {
139139
140- $Name = ' MyTestModSource'
141- $Location = $script :TempModulesPath
142- try
143- {
140+ $Name = ' MyTestModSource'
141+ $Location = $script :TempModulesPath
142+ try {
144143 Register-PSRepository - Name $Name - SourceLocation $Location - PublishLocation $Location
145144 $repo = Get-PSRepository - Name $Name
146145
147146 AssertEquals $repo.Name $Name " The repository name is not same as the registered name. Actual: $ ( $repo.Name ) , Expected: $Name "
148147 AssertEquals $repo.SourceLocation $Location " The SourceLocation is not same as the registered SourceLocation. Actual: $ ( $repo.SourceLocation ) , Expected: $Location "
149148 AssertEquals $repo.PublishLocation $Location " The PublishLocation is not same as the registered PublishLocation. Actual: $ ( $repo.PublishLocation ) , Expected: $Location "
150149 }
151- finally
152- {
150+ finally {
153151 Get-PSRepository - Name $Name | Unregister-PSRepository
154152 }
155153 }
@@ -163,10 +161,9 @@ Describe PowerShell.PSGet.ModuleSourceTests -Tags 'BVT','InnerLoop' {
163161 #>
164162 It SetPSRepositoryWithSMBSharePath {
165163
166- $Name = ' MyTestModSource'
167- $Location = $script :TempModulesPath
168- try
169- {
164+ $Name = ' MyTestModSource'
165+ $Location = $script :TempModulesPath
166+ try {
170167 Register-PSRepository - Name $Name - SourceLocation $Location
171168 Set-PSRepository - Name $Name - SourceLocation $Location - PublishLocation $Location
172169 $repo = Get-PSRepository - Name $Name
@@ -175,8 +172,7 @@ Describe PowerShell.PSGet.ModuleSourceTests -Tags 'BVT','InnerLoop' {
175172 AssertEquals $repo.SourceLocation $Location " The SourceLocation is not same as the registered SourceLocation. Actual: $ ( $repo.SourceLocation ) , Expected: $Location "
176173 AssertEquals $repo.PublishLocation $Location " The PublishLocation is not same as the registered PublishLocation. Actual: $ ( $repo.PublishLocation ) , Expected: $Location "
177174 }
178- finally
179- {
175+ finally {
180176 Get-PSRepository - Name $Name | Unregister-PSRepository
181177 }
182178 }
@@ -190,200 +186,18 @@ Describe PowerShell.PSGet.ModuleSourceTests -Tags 'BVT','InnerLoop' {
190186 #>
191187 It UnregisterModuleSource {
192188
193- $Name = ' MyTestModSource'
194- $Location = ' https://www.nuget.org/api/v2/'
189+ $Name = ' MyTestModSource'
190+ $Location = ' https://www.nuget.org/api/v2/'
195191
196192 Register-PSRepository - Name $Name - SourceLocation $Location
197193 Unregister-PSRepository - Name $Name
198194
199195 $expectedFullyQualifiedErrorId = ' SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageSource'
200196
201197 AssertFullyQualifiedErrorIdEquals - scriptblock {Get-PSRepository - Name $Name } `
202- - expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
203- }
204-
205- <#
206- Purpose: Test Check-PSGalleryApiAvailability and Get-PSGalleryApiAvailability cmdlet for Stage 1 of PSGallery V2/V3 Transition.
207-
208- Action: Check-PSGalleryApiAvailability -PSGalleryV2ApiUri $Uri200Ok -PSGalleryV3ApiUri $Uri404NotFound
209- Get-PSGalleryApiAvailability -Repository PSGallery
210-
211- Expected Result: Should show and do nothing.
212- #>
213- It CheckGetPSGalleryApiAvailabilityStage1 {
214-
215- $result = & $script :PowerShellGetModuleInfo Check- PSGalleryApiAvailability - PSGalleryV2ApiUri $script :Uri200Ok - PSGalleryV3ApiUri $script :Uri404NotFound
216- AssertNull $result " Check-PSGalleryApiAvailability Stage 1 should not return anything."
217-
218- $err = $null
219- try
220- {
221- $result = & $script :PowerShellGetModuleInfo Get-PSGalleryApiAvailability - Repository " PSGallery" - WarningVariable w
222- }
223- catch
224- {
225- $err = $_
226- }
227-
228- AssertNull $result " Get-PSGalleryApiAvailability Stage 1 should not return anything."
229- AssertEquals 0 $w.Count " Get-PSGalleryApiAvailability Stage 1 should not write a warning."
230- AssertNull $err " Get-PSGalleryApiAvailability Stage 1 should not throw an error message."
231- }
232-
233- <#
234- Purpose: Test Check-PSGalleryApiAvailability and Get-PSGalleryApiAvailability cmdlet for Stage 2 of PSGallery V2/V3 Transition.
235-
236- Action: Check-PSGalleryApiAvailability -PSGalleryV2ApiUri $Uri200Ok -PSGalleryV3ApiUri $Uri200Ok
237- Get-PSGalleryApiAvailability -Repository PSGallery
238-
239- Expected Result: Should display a warning.
240- #>
241- It CheckGetPSGalleryApiAvailabilityStage2 {
242-
243- try {
244- $result = & $script :PowerShellGetModuleInfo Check- PSGalleryApiAvailability - PSGalleryV2ApiUri $script :Uri200Ok - PSGalleryV3ApiUri $script :Uri200Ok
245- AssertNull $result " Check-PSGalleryApiAvailability Stage 2 should not return anything."
246-
247- $err = $null
248- try
249- {
250- $result = & $script :PowerShellGetModuleInfo Get-PSGalleryApiAvailability - Repository " PSGallery" - WarningVariable w - WarningAction SilentlyContinue
251- }
252- catch
253- {
254- $err = $_
255- }
256-
257- AssertNull $result " Get-PSGalleryApiAvailability Stage 2 should not return anything."
258- AssertNotEquals 0 $w.Count " Get-PSGalleryApiAvailability Stage 2 should write a warning."
259- # AssertEqualsCaseInsensitive $script:LocalizedData.PSGalleryApiV2Deprecated $w[0].Message "Get-PSGalleryApiAvailability Stage 2 wrote the wrong warning message."
260- AssertNull $err " Get-PSGalleryApiAvailability Stage 2 should not throw an error message."
261- }
262- finally {
263- # Set API availability for v2 back to true (no warnings or errors thrown)
264- $result = & $script :PowerShellGetModuleInfo Check- PSGalleryApiAvailability - PSGalleryV2ApiUri $script :Uri200Ok - PSGalleryV3ApiUri $script :URI404NotFound
265- }
266- }
267-
268- <#
269- Purpose: Test Check-PSGalleryApiAvailability and Get-PSGalleryApiAvailability cmdlet for Stage 3 of PSGallery V2/V3 Transition.
270-
271- Action: Check-PSGalleryApiAvailability -PSGalleryV2ApiUri $Uri404NotFound -PSGalleryV3ApiUri $Uri200Ok
272- Get-PSGalleryApiAvailability -Repository PSGallery
273-
274- Expected Result: Should throw an error.
275- #>
276- It CheckGetPSGalleryApiAvailabilityStage3 {
277- try {
278- $result = & $script :PowerShellGetModuleInfo Check- PSGalleryApiAvailability - PSGalleryV2ApiUri $script :Uri404NotFound - PSGalleryV3ApiUri $script :Uri200Ok
279- AssertNull $result " Check-PSGalleryApiAvailability Stage 3 should not return anything."
280-
281- $err = $null
282- try
283- {
284- $result = & $script :PowerShellGetModuleInfo Get-PSGalleryApiAvailability - Repository " PSGallery" - WarningVariable w
285- }
286- catch
287- {
288- $err = $_
289- }
290-
291- AssertNull $result " Get-PSGalleryApiAvailability Stage 3 should not return anything."
292- AssertEquals 0 $w.Count " Get-PSGalleryApiAvailability Stage 3 should not write a warning."
293- AssertNotNull $err " Get-PSGalleryApiAvailability Stage 3 should throw an error message."
294- AssertEqualsCaseInsensitive " PSGalleryApiV2Discontinued,Get-PSGalleryApiAvailability" $err.FullyQualifiedErrorId " Get-PSGalleryApiAvailability Stage 3 threw a different error: $err "
295- }
296- finally {
297- # Set API availability for v2 back to true (no warnings or errors thrown)
298- $result = & $script :PowerShellGetModuleInfo Check- PSGalleryApiAvailability - PSGalleryV2ApiUri $script :Uri200Ok - PSGalleryV3ApiUri $script :URI404NotFound
299- }
300- }
301-
302- <#
303- Purpose: Test Check-PSGalleryApiAvailability and Get-PSGalleryApiAvailability cmdlet when no API is available.
304- This indicates that the site is down.
305-
306- Action: Check-PSGalleryApiAvailability -PSGalleryV2ApiUri $Uri404NotFound -PSGalleryV3ApiUri $Uri404NotFound
307- Get-PSGalleryApiAvailability -Repository PSGallery
308-
309- Expected Result: Should throw an error.
310- #>
311- It CheckGetPSGalleryUnavailable {
312- try {
313- $result = & $script :PowerShellGetModuleInfo Check- PSGalleryApiAvailability - PSGalleryV2ApiUri $script :Uri404NotFound - PSGalleryV3ApiUri $script :Uri404NotFound
314- AssertNull $result " Check-PSGalleryApiAvailability should not return anything."
315-
316- $err = $null
317- try
318- {
319- $result = & $script :PowerShellGetModuleInfo Get-PSGalleryApiAvailability - Repository " PSGallery" - WarningVariable w
320- }
321- catch
322- {
323- $err = $_
324- }
325-
326- AssertNull $result " Get-PSGalleryApiAvailability should not return anything."
327- AssertEquals 0 $w.Count " Get-PSGalleryApiAvailability should not write a warning."
328- AssertNotNull $err " Get-PSGalleryApiAvailability Stage 3 should throw an error message."
329- AssertEqualsCaseInsensitive " PowerShellGalleryUnavailable,Get-PSGalleryApiAvailability" $err.FullyQualifiedErrorId " Get-PSGalleryApiAvailability Stage 3 threw a different error: $err "
330- }
331- finally {
332- # Set API availability for v2 back to true (no warnings or errors thrown)
333- $result = & $script :PowerShellGetModuleInfo Check- PSGalleryApiAvailability - PSGalleryV2ApiUri $script :Uri200Ok - PSGalleryV3ApiUri $script :URI404NotFound
334- }
335- }
336-
337- <#
338- Purpose: Test Get-PSGalleryApiAvailability cmdlet when no repository specified.
339-
340- Action: Get-PSGalleryApiAvailability
341-
342- Expected Result: Should show and do nothing.
343- #>
344- It GetPSGalleryApiAvailabilityNoRepositorySpecified {
345-
346- $err = $null
347- try
348- {
349- $result = & $script :PowerShellGetModuleInfo Get-PSGalleryApiAvailability - WarningVariable w
350- }
351- catch
352- {
353- $err = $_
354- }
355-
356- AssertNull $result " Get-PSGalleryApiAvailability should not return anything."
357- AssertEquals 0 $w.Count " Get-PSGalleryApiAvailability should not write a warning."
358- AssertNull $err " Get-PSGalleryApiAvailability should not throw an error message."
359- }
360-
361-
362- <#
363- Purpose: Test Get-PSGalleryApiAvailability cmdlet when no repository specified.
364-
365- Action: Get-PSGalleryApiAvailability
366-
367- Expected Result: Should show and do nothing.
368- #>
369- It GetPSGalleryApiAvailabilityDifferentRepositorySpecified {
370-
371- $err = $null
372- try
373- {
374- $result = & $script :PowerShellGetModuleInfo Get-PSGalleryApiAvailability - Repository " MSPSGallery" - WarningVariable w
375- }
376- catch
377- {
378- $err = $_
379- }
380-
381- AssertNull $result " Get-PSGalleryApiAvailability should not return anything."
382- AssertEquals 0 $w.Count " Get-PSGalleryApiAvailability should not write a warning."
383- AssertNull $err " Get-PSGalleryApiAvailability should not throw an error message."
198+ - expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
384199 }
385200}
386-
387201Describe PowerShell.PSGet.ModuleSourceTests.P1 - Tags ' P1' , ' OuterLoop' {
388202
389203 BeforeAll {
@@ -591,7 +405,7 @@ Describe PowerShell.PSGet.ModuleSourceTests.P1 -Tags 'P1','OuterLoop' {
591405 AssertFullyQualifiedErrorIdEquals - scriptblock {Register-PSRepository - Name myNuGetSource1 - SourceLocation myget.org/ F/ powershellgetdemo} `
592406 - expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
593407 }
594-
408+
595409 <#
596410 Purpose: Validate Register-PSRepository functionality with wildcard in source name
597411
@@ -697,7 +511,7 @@ Describe PowerShell.PSGet.ModuleSourceTests.P1 -Tags 'P1','OuterLoop' {
697511 - expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
698512 }
699513
700- It RegisterPSRepositoryShouldFailWithPSModuleAsPMProviderName {
514+ It RegisterPSRepositoryShouldFailWithPSModuleAsPMProviderName {
701515 AssertFullyQualifiedErrorIdEquals - scriptblock {Register-PSRepository - Name Foo - SourceLocation $script :TempPath - PackageManagementProvider PowerShellGet} `
702516 - expectedFullyQualifiedErrorId " InvalidPackageManagementProviderValue,Register-PSRepository"
703517 }
@@ -707,15 +521,15 @@ Describe PowerShell.PSGet.ModuleSourceTests.P1 -Tags 'P1','OuterLoop' {
707521 - expectedFullyQualifiedErrorId " InvalidPackageManagementProviderValue,Set-PSRepository"
708522 }
709523
710- It RegisterPackageSourceShouldFailWithPSModuleAsPMProviderName {
524+ It RegisterPackageSourceShouldFailWithPSModuleAsPMProviderName {
711525 AssertFullyQualifiedErrorIdEquals - scriptblock {Register-PackageSource - ProviderName PowerShellGet - Name Foo - Location $script :TempPath - PackageManagementProvider PowerShellGet} `
712526 - expectedFullyQualifiedErrorId " InvalidPackageManagementProviderValue,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource"
713527 }
714528}
715529
716530Describe PowerShell.PSGet.FindModule.ModuleSourceTests.P1 - Tags ' P1' , ' OuterLoop' {
717531
718- # Not executing these tests on MacOS as
532+ # Not executing these tests on MacOS as
719533 # the total execution time is exceeding allowed 50 min in TravisCI daily builds.
720534 if ($IsMacOS ) {
721535 return
@@ -789,7 +603,7 @@ Describe PowerShell.PSGet.FindModule.ModuleSourceTests.P1 -Tags 'P1','OuterLoop'
789603
790604Describe PowerShell.PSGet.InstallModule.ModuleSourceTests.P1 - Tags ' P1' , ' OuterLoop' {
791605
792- # Not executing these tests on MacOS as
606+ # Not executing these tests on MacOS as
793607 # the total execution time is exceeding allowed 50 min in TravisCI daily builds.
794608 if ($IsMacOS ) {
795609 return
0 commit comments