This repository was archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathPSGetModuleSource.Tests.ps1
More file actions
667 lines (519 loc) · 27.1 KB
/
PSGetModuleSource.Tests.ps1
File metadata and controls
667 lines (519 loc) · 27.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
<#####################################################################################
# File: PSGetModuleSourceTests.ps1
# Tests for PowerShellGet module functionality with multiple module sources
#
# Copyright (c) Microsoft Corporation, 2014
#####################################################################################>
<#
Name: PowerShell.PSGet.ModuleSourceTests
Description: Tests for PowerShellGet module functionality with multiple module sources
The local directory based NuGet repository is used for publishing the modules.
#>
. "$PSScriptRoot\PSGetTests.Manifests.ps1"
. "$PSScriptRoot\PSGetTests.Generators.ps1"
function SuiteSetup {
Import-Module "$PSScriptRoot\PSGetTestUtils.psm1" -WarningAction SilentlyContinue
Import-Module "$PSScriptRoot\Asserts.psm1" -WarningAction SilentlyContinue
$script:ProgramFilesModulesPath = Get-AllUsersModulesPath
$script:MyDocumentsModulesPath = Get-CurrentUserModulesPath
$script:PSGetLocalAppDataPath = Get-PSGetLocalAppDataPath
$script:TempPath = Get-TempPath
$script:BuiltInModuleSourceName = "PSGallery"
$script:URI200OK = "http://go.microsoft.com/fwlink/?LinkID=533903&clcid=0x409"
$script:URI404NotFound = "http://go.microsoft.com/fwlink/?LinkID=533902&clcid=0x409"
#Bootstrap NuGet binaries
Install-NuGetBinaries
$script:PowerShellGetModuleInfo = Import-Module PowerShellGet -Global -Force -PassThru
Import-LocalizedData script:LocalizedData -filename PSGet.Resource.psd1 -BaseDirectory $PowerShellGetModuleInfo.ModuleBase
# Backup the existing module sources information
$script:moduleSourcesFilePath= Join-Path $script:PSGetLocalAppDataPath "PSRepositories.xml"
$script:moduleSourcesBackupFilePath = Join-Path $script:PSGetLocalAppDataPath "PSRepositories.xml_$(get-random)_backup"
if(Test-Path $script:moduleSourcesFilePath)
{
Rename-Item $script:moduleSourcesFilePath $script:moduleSourcesBackupFilePath -Force
}
$script:TestModuleSourceUri = ''
GetAndSet-PSGetTestGalleryDetails -PSGallerySourceUri ([REF]$script:TestModuleSourceUri)
# Register the test module source
$script:TestModuleSourceName = "PSGetTestModuleSource"
Register-PSRepository -Name $script:TestModuleSourceName -SourceLocation $script:TestModuleSourceUri -InstallationPolicy Trusted
$repo = Get-PSRepository -Name $script:BuiltInModuleSourceName -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
if($repo)
{
Set-PSRepository -Name $script:BuiltInModuleSourceName -InstallationPolicy Trusted -ErrorAction SilentlyContinue
}
else
{
Register-PSRepository -Default -InstallationPolicy Trusted
}
$modSource = Get-PSRepository -Name $script:TestModuleSourceName
AssertEquals $modSource.SourceLocation $script:TestModuleSourceUri "Test module source is not set properly"
# Create a temp folder
$script:TempModulesPath= Join-Path $script:TempPath "PSGet_$(Get-Random)"
$null = New-Item -Path $script:TempModulesPath -ItemType Directory -Force
}
function SuiteCleanup {
if(Test-Path $script:moduleSourcesBackupFilePath)
{
Move-Item $script:moduleSourcesBackupFilePath $script:moduleSourcesFilePath -Force
}
else
{
Unregister-PSRepository -Name $script:TestModuleSourceName
}
# To reload the repositories
$null = Import-PackageProvider -Name PowerShellGet -Force
RemoveItem $script:TempModulesPath
}
Describe PowerShell.PSGet.ModuleSourceTests -Tags 'BVT', 'InnerLoop' {
BeforeAll {
SuiteSetup
}
AfterAll {
SuiteCleanup
}
<#
Purpose: Validate the Register-PSRepository and Get-PSRepository functionality
Action: Register a module source and Get the registered module source details
Expected Result: should be able to register and get the module source
#>
It RegisterAngGetModuleSource {
$Name = 'MyTestModSourceForRegisterAngGet'
$Location = 'https://www.nuget.org/api/v2/'
Register-PSRepository -Default -ErrorAction SilentlyContinue
try {
Register-PSRepository -Name $Name -SourceLocation $Location
$moduleSource = Get-PSRepository -Name $Name
$allModuleSources = Get-PSRepository
$defaultModuleSourceDetails = Get-PSRepository -Name $script:BuiltInModuleSourceName
AssertEquals $moduleSource.Name $Name "The module source name is not same as the registered name"
AssertEquals $moduleSource.SourceLocation $Location "The module source location is not same as the registered location"
Assert (Test-Path $script:moduleSourcesFilePath) "Missing $script:moduleSourcesFilePath file after module source registration"
Assert ($allModuleSources.Count -ge 3) "ModuleSources count should be >=3 with registed module source along with default PSGallery Source, $allModuleSources"
AssertEquals $defaultModuleSourceDetails.Name $script:BuiltInModuleSourceName "The default module source name is not same as the expected module source name"
}
finally {
Get-PSRepository -Name $Name -ErrorAction SilentlyContinue | Unregister-PSRepository
}
}
<#
Purpose: Validate the Register-PSRepository with SMB share
Action: Register a repository with directory and Get the registered repository details
Expected Result: should be able to register and get the repository
#>
It RegisterSMBShareRepository {
$Name = 'MyTestModSource'
$Location = $script:TempModulesPath
try {
Register-PSRepository -Name $Name -SourceLocation $Location -PublishLocation $Location
$repo = Get-PSRepository -Name $Name
AssertEquals $repo.Name $Name "The repository name is not same as the registered name. Actual: $($repo.Name), Expected: $Name"
AssertEquals $repo.SourceLocation $Location "The SourceLocation is not same as the registered SourceLocation. Actual: $($repo.SourceLocation), Expected: $Location"
AssertEquals $repo.PublishLocation $Location "The PublishLocation is not same as the registered PublishLocation. Actual: $($repo.PublishLocation), Expected: $Location"
}
finally {
Get-PSRepository -Name $Name | Unregister-PSRepository
}
}
<#
Purpose: Validate the Set-PSRepository with SMB share
Action: Register and Set a repository with directory and Get the registered repository details
Expected Result: should be able to set and get the repository
#>
It SetPSRepositoryWithSMBSharePath {
$Name = 'MyTestModSource'
$Location = $script:TempModulesPath
try {
Register-PSRepository -Name $Name -SourceLocation $Location
Set-PSRepository -Name $Name -SourceLocation $Location -PublishLocation $Location
$repo = Get-PSRepository -Name $Name
AssertEquals $repo.Name $Name "The repository name is not same as the registered name. Actual: $($repo.Name), Expected: $Name"
AssertEquals $repo.SourceLocation $Location "The SourceLocation is not same as the registered SourceLocation. Actual: $($repo.SourceLocation), Expected: $Location"
AssertEquals $repo.PublishLocation $Location "The PublishLocation is not same as the registered PublishLocation. Actual: $($repo.PublishLocation), Expected: $Location"
}
finally {
Get-PSRepository -Name $Name | Unregister-PSRepository
}
}
<#
Purpose: Validate the Unregister-PSRepository functionality
Action: Unregister the registered module source
Expected Result: module source should be unregistered and Get-PSRepository should fail with that name
#>
It UnregisterModuleSource {
$Name = 'MyTestModSource'
$Location = 'https://www.nuget.org/api/v2/'
Register-PSRepository -Name $Name -SourceLocation $Location
Unregister-PSRepository -Name $Name
$expectedFullyQualifiedErrorId = 'SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageSource'
AssertFullyQualifiedErrorIdEquals -scriptblock {Get-PSRepository -Name $Name} `
-expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
}
}
Describe PowerShell.PSGet.ModuleSourceTests.P1 -Tags 'P1','OuterLoop' {
BeforeAll {
SuiteSetup
}
AfterAll {
SuiteCleanup
}
<#
Purpose: Validate the Register-PSRepository with not available directory path
Action: Register a repository with not available directory path
Expected Result: should fail
#>
It RegisterPSRepositoryWithInvalidSMBShareSourceLocation {
$Name='MyTestModSource'
$Location = Join-Path $script:TempPath 'DirNotAvailable'
AssertFullyQualifiedErrorIdEquals -scriptblock {Register-PSRepository -Name $Name -SourceLocation $Location} `
-expectedFullyQualifiedErrorId "PathNotFound,Register-PSRepository"
}
<#
Purpose: Validate the Register-PSRepository with invalid SMB share value
Action: Register a repository with not available directory path
Expected Result: should fail
#>
It RegisterPSRepositoryWithInvalidSMBSharePublishLocation {
$Name='MyTestModSource'
$Location=$script:TempModulesPath
$PublishLocation = Join-Path $script:TempPath 'DirNotAvailable'
AssertFullyQualifiedErrorIdEquals -scriptblock {Register-PSRepository -Name $Name -SourceLocation $Location -PublishLocation $PublishLocation} `
-expectedFullyQualifiedErrorId "PathNotFound,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource"
}
<#
Purpose: Validate the Set-PSRepository with invalid SMB share value
Action: Register a repository with a valid directory and set it to invalid directory
Expected Result: should fail
#>
It SetPSRepositoryWithInvalidSMBShareSourceLocation {
$Name='MyTestModSource'
$Location=$script:TempModulesPath
$Location2 = Join-Path $script:TempPath 'DirNotAvailable'
try
{
Register-PSRepository -Name $Name -SourceLocation $Location
AssertFullyQualifiedErrorIdEquals -scriptblock {Set-PSRepository -Name $Name -SourceLocation $Location2} `
-expectedFullyQualifiedErrorId "PathNotFound,Set-PSRepository"
}
finally
{
Get-PSRepository -Name $Name | Unregister-PSRepository
}
}
<#
Purpose: Validate the Set-PSRepository with invalid SMB share value
Action: Register a repository with a valid directory and set it to invalid directory
Expected Result: should fail
#>
It SetPSRepositoryWithInvalidSMBSharePublishLocation {
$Name='MyTestModSource'
$Location=$script:TempModulesPath
$Location2 = Join-Path $script:TempPath 'DirNotAvailable'
try
{
Register-PSRepository -Name $Name -SourceLocation $Location -PublishLocation $Location
AssertFullyQualifiedErrorIdEquals -scriptblock {Set-PSRepository -Name $Name -SourceLocation $Location -PublishLocation $Location2} `
-expectedFullyQualifiedErrorId "PathNotFound,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.SetPackageSource"
}
finally
{
Get-PSRepository -Name $Name | Unregister-PSRepository
}
}
<#
Purpose: Validate the Get-PSRepository functionality with wildcards in name
Action: Register a module source and Get the registered module source with wildcards in name
Expected Result: should get the module source names with wildcards
#>
It GetModuleSourceWithWildCards {
$Name='MyTestModSource'
$Location='https://www.nuget.org/api/v2/'
try
{
Register-PSRepository -Name $Name -SourceLocation $Location
$moduleSource = Get-PSRepository -Name 'MyTestModS*rce'
AssertEquals $moduleSource.Name $Name "The module source name is not same as the registered name"
AssertEquals $moduleSource.SourceLocation $Location "The module source location is not same as the registered location"
Assert (Test-Path $script:moduleSourcesFilePath) "Missing $script:moduleSourcesFilePath file after module source registration"
}
finally
{
Get-PSRepository -Name $Name | Unregister-PSRepository
}
}
<#
Purpose: Validate Register-PSRepository functionality with existing source name
Action: Register a module source with existing name
Expected Result: Should fail with an error
#>
It RegisterModuleSourceWithSameName {
$Name='MyTestModSource'
$Location='https://www.nuget.org/api/v2/'
try
{
Register-PSRepository -Name $Name -SourceLocation $Location
AssertFullyQualifiedErrorIdEquals -scriptblock {Register-PSRepository -Name $Name -SourceLocation $Location} `
-expectedFullyQualifiedErrorId 'PackageSourceExists,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource'
}
finally
{
Get-PSRepository -Name $Name | Unregister-PSRepository
}
}
<#
Purpose: Validate Register-PSRepository functionality with location same as the existing source
Action: Register a module source with same location as the already registered module source
Expected Result: Should fail with an error
#>
It RegisterModuleSourceWithAlreadyRegisteredLocation {
$Name='MyTestModSource'
$Location='https://www.nuget.org/api/v2/'
try
{
Register-PSRepository -Name $Name -SourceLocation $Location
$expectedFullyQualifiedErrorId = 'RepositoryAlreadyRegistered,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource'
AssertFullyQualifiedErrorIdEquals -scriptblock {Register-PSRepository -Name 'MyTestModSource2' -SourceLocation $Location} `
-expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
}
finally
{
Get-PSRepository -Name $Name | Unregister-PSRepository
}
}
<#
Purpose: Validate Register-PSRepository functionality with non available location
Action: Register a module source with non available location
Expected Result: Should fail with an error
#>
It RegisterModuleSourceWithNotAvailableLocation {
$expectedFullyQualifiedErrorId = 'InvalidWebUri,Register-PSRepository'
AssertFullyQualifiedErrorIdEquals -scriptblock {Register-PSRepository -Name myNuGetSource -SourceLocation https://www.nonexistingcompany.com/api/v2/} `
-expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
}
<#
Purpose: Validate Register-PSRepository functionality with non available location and without api/v2
Action: Register a module source with non available location
Expected Result: Should fail with an error
#>
It RegisterModuleSourceWithNotAvailableLocation2 {
$expectedFullyQualifiedErrorId = 'InvalidWebUri,Register-PSRepository'
AssertFullyQualifiedErrorIdEquals -scriptblock {Register-PSRepository -Name myNuGetSource2 -SourceLocation https://www.nonexistingcompany.com} `
-expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
}
<#
Purpose: Validate Register-PSRepository functionality with invalid URL
Action: Register a module source with invalid URL
Expected Result: Should fail with an error
#>
It RegisterModuleSourceWithInvalidWebUri {
$expectedFullyQualifiedErrorId = 'PathNotFound,Register-PSRepository'
AssertFullyQualifiedErrorIdEquals -scriptblock {Register-PSRepository -Name myNuGetSource1 -SourceLocation myget.org/F/powershellgetdemo} `
-expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
}
<#
Purpose: Validate Register-PSRepository functionality with wildcard in source name
Action: Register a module source with wildcard in source name
Expected Result: Should fail with an error
#>
It RegisterModuleSourceWithWildCardInName {
$expectedFullyQualifiedErrorId = 'RepositoryNameContainsWildCards,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource'
AssertFullyQualifiedErrorIdEquals -scriptblock {Register-PSRepository -Name my*NuGetSource -SourceLocation https://www.myget.org/F/powershellgetdemo} `
-expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
}
<#
Purpose: Validate Get-PSRepository functionality with non registered modul source
Action: Get the non-registered module source details
Expected Result: Should fail with an error
#>
It GetNonRegisteredModuleSource {
$expectedFullyQualifiedErrorId = 'SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageSource'
AssertFullyQualifiedErrorIdEquals -scriptblock {Get-PSRepository -Name 'MyTestModSourceNotRegistered'} `
-expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
}
<#
Purpose: Validate Get-PSRepository functionality with wildcard in non registered modul source name
Action: Get the non-registered module source details with wildcard in the name
Expected Result: Should return null results without any error
#>
It GetNonRegisteredModuleSourceNameWithWildCards {
$moduleSources = Get-PSRepository -Name 'MyTestModSourceNotRegiste*ed' -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
AssertNull $moduleSources "Get-PSRepository should not return the $moduleSources module source"
}
<#
Purpose: Validate the Unregister-PSRepository functionality with wildcards in name
Action: Unregister a registered module source name with wildcards
Expected Result: should fail with an error
#>
It UnregisterModuleSourceWithWildCards {
$Name='MyTestModSource'
$Location='https://www.nuget.org/api/v2/'
try
{
Register-PSRepository -Name $Name -SourceLocation $Location
AssertFullyQualifiedErrorIdEquals -scriptblock {Unregister-PSRepository -Name 'MyTestMo*ource'} `
-expectedFullyQualifiedErrorId 'RepositoryNameContainsWildCards,Unregister-PSRepository'
}
finally
{
Get-PSRepository $Name -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Unregister-PSRepository
}
}
<#
Purpose: Validate the Unregister-PSRepository functionality with built-in repository name
Action: Unregister built-in module source $script:BuiltInModuleSourceName
Expected Result: should not fail
#>
It UnregisterBuiltinModuleSource {
try {
Unregister-PSRepository -Name $script:BuiltInModuleSourceName
$expectedFullyQualifiedErrorId = 'SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageSource'
AssertFullyQualifiedErrorIdEquals -scriptblock {Get-PSRepository -Name $script:BuiltInModuleSourceName} `
-expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
$expectedFullyQualifiedErrorId = 'PSGalleryNotFound,Publish-Module'
AssertFullyQualifiedErrorIdEquals -scriptblock {Publish-Module -Name MyTempModule} `
-expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
}
finally {
Register-PSRepository -Default -InstallationPolicy Trusted
}
} `
-Skip:$($PSEdition -eq 'Core')
<#
Purpose: Validate the Unregister-PSRepository functionality with non-registered module source name
Action: Unregister a not registered module source
Expected Result: should fail with an error
#>
It UnregisterNotRegisteredModuleSource {
$expectedFullyQualifiedErrorId = 'SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.UnregisterPackageSource'
AssertFullyQualifiedErrorIdEquals -scriptblock {Unregister-PSRepository -Name "NonAvailableModuleSource"} `
-expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
}
It RegisterPSRepositoryShouldFailWithPSModuleAsPMProviderName {
AssertFullyQualifiedErrorIdEquals -scriptblock {Register-PSRepository -Name Foo -SourceLocation $script:TempPath -PackageManagementProvider PowerShellGet} `
-expectedFullyQualifiedErrorId "InvalidPackageManagementProviderValue,Register-PSRepository"
}
It SetPSRepositoryShouldFailWithPSModuleAsPMProviderName {
AssertFullyQualifiedErrorIdEquals -scriptblock {Set-PSRepository -Name PSGallery -PackageManagementProvider PowerShellGet} `
-expectedFullyQualifiedErrorId "InvalidPackageManagementProviderValue,Set-PSRepository"
}
It RegisterPackageSourceShouldFailWithPSModuleAsPMProviderName {
AssertFullyQualifiedErrorIdEquals -scriptblock {Register-PackageSource -ProviderName PowerShellGet -Name Foo -Location $script:TempPath -PackageManagementProvider PowerShellGet} `
-expectedFullyQualifiedErrorId "InvalidPackageManagementProviderValue,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource"
}
}
Describe PowerShell.PSGet.FindModule.ModuleSourceTests.P1 -Tags 'P1','OuterLoop' {
# Not executing these tests on MacOS as
# the total execution time is exceeding allowed 50 min in TravisCI daily builds.
if($IsMacOS) {
return
}
BeforeAll {
SuiteSetup
}
AfterAll {
SuiteCleanup
}
<#
Purpose: Verify the Find-Module functionality with different values for -Repository parameter.
Action: Use parameter generator to get different values to be tested with Find-Module cmdlet
Expected Result: Module list or Error depending on the input variation
#>
$ParameterSets = Get-FindModuleWithSourcesParameterSets
$ParameterSetCount = $ParameterSets.Count
$i = 1
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)
$scriptBlock = $null
if($inputParameters.Name -and $inputParameters.Source)
{
$scriptBlock = { Find-Module -Name $inputParameters.Name -Repository $inputParameters.Source }.GetNewClosure()
}
elseif($inputParameters.Name)
{
$scriptBlock = { Find-Module -Name $inputParameters.Name }.GetNewClosure()
}
elseif($inputParameters.Source)
{
$scriptBlock = { Find-Module -Repository $inputParameters.Source }.GetNewClosure()
}
else
{
$scriptBlock = { Find-Module }
}
It "FindModuleWithModuleSourcesTests - Combination $i/$ParameterSetCount" {
if($inputParameters.PositiveCase)
{
$res = Invoke-Command -ScriptBlock $scriptBlock
if($inputParameters.ExpectedModuleCount -gt 1)
{
Assert ($res.Count -ge $inputParameters.ExpectedModuleCount) "Combination #$i : Find-Module did not return expected module count with Source input. Actual value $($res.Count) should be greater than or equal to the expected value $($inputParameters.ExpectedModuleCount)."
}
else
{
AssertEqualsCaseInsensitive $res.Name $inputParameters.Name "Combination #$i : Find-Module did not return expected module with Source input"
}
}
else
{
AssertFullyQualifiedErrorIdEquals -scriptblock $scriptBlock -expectedFullyQualifiedErrorId $inputParameters.FullyQualifiedErrorID
}
}
$i = $i+1
}
}
Describe PowerShell.PSGet.InstallModule.ModuleSourceTests.P1 -Tags 'P1','OuterLoop' {
# Not executing these tests on MacOS as
# the total execution time is exceeding allowed 50 min in TravisCI daily builds.
if($IsMacOS) {
return
}
BeforeAll {
SuiteSetup
}
AfterAll {
SuiteCleanup
}
<#
Purpose: Verify the Install-Module functionality with different values for -Repository parameter.
Action: Use parameter generator to get different values to be tested with Install-Module cmdlet
Expected Result: The specified module should be installed or fail with an error depending on the input variation
#>
$ParameterSets = Get-InstallModuleWithSourcesParameterSets
$ParameterSetCount = $ParameterSets.Count
$i = 1
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)
$scriptBlock = $null
if($inputParameters.Source)
{
$scriptBlock = { Install-Module -Name $inputParameters.Name -Repository $inputParameters.Source }.GetNewClosure()
}
else
{
$scriptBlock = { Install-Module -Name $inputParameters.Name }.GetNewClosure()
}
It "InstallModuleWithModuleSourcesTests - Combination $i/$ParameterSetCount" {
try {
if($inputParameters.PositiveCase)
{
Invoke-Command -ScriptBlock $scriptBlock
$res = Get-Module -ListAvailable -Name $inputParameters.Name
AssertEqualsCaseInsensitive $res.Name $inputParameters.Name "Combination #$i : Install-Module did not install the expected module with Source input, $res"
}
else
{
AssertFullyQualifiedErrorIdEquals -scriptblock $scriptBlock -expectedFullyQualifiedErrorId $inputParameters.FullyQualifiedErrorID
}
} finally {
PSGetTestUtils\Uninstall-Module $inputParameters.Name
}
}
$i = $i+1
}
}