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 132
Expand file tree
/
Copy pathPSGetInstallModule.Tests.ps1
More file actions
1466 lines (1253 loc) · 69.5 KB
/
Copy pathPSGetInstallModule.Tests.ps1
File metadata and controls
1466 lines (1253 loc) · 69.5 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
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<#####################################################################################
# File: PSGetInstallModuleTests.ps1
# Tests for PSGet module functionality
#
# Copyright (c) Microsoft Corporation, 2014
#####################################################################################>
<#
Name: PowerShell.PSGet.InstallModuleTests
Description: Tests for Install-Module cmdlet functionality
Local PSGet Test Gallery (ex: http://localhost:8765/packages) is pre-populated with static modules:
ContosoClient: versions 1.0, 1.5, 2.0, 2.5
ContosoServer: versions 1.0, 1.5, 2.0, 2.5
#>
function SuiteSetup {
Import-Module "$PSScriptRoot\PSGetTestUtils.psm1" -WarningAction SilentlyContinue
Import-Module "$PSScriptRoot\Asserts.psm1" -WarningAction SilentlyContinue
$script:IsWindowsOS = (-not (Get-Variable -Name IsWindows -ErrorAction Ignore)) -or $IsWindows
$script:ProgramFilesModulesPath = Get-AllUsersModulesPath
$script:MyDocumentsModulesPath = Get-CurrentUserModulesPath
$script:PSGetLocalAppDataPath = Get-PSGetLocalAppDataPath
$script:TempPath = Get-TempPath
$null = New-Item -Path $script:MyDocumentsModulesPath -ItemType Directory -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
#Bootstrap NuGet binaries
Install-NuGetBinaries
$psgetModuleInfo = Import-Module PowerShellGet -Global -Force -Passthru
Import-LocalizedData script:LocalizedData -filename PSGet.Resource.psd1 -BaseDirectory $psgetModuleInfo.ModuleBase
$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
}
$Global:PSGallerySourceUri = ''
GetAndSet-PSGetTestGalleryDetails -SetPSGallery -PSGallerySourceUri ([REF]$Global:PSGallerySourceUri)
PSGetTestUtils\Uninstall-Module ContosoServer
PSGetTestUtils\Uninstall-Module ContosoClient
$script:assertTimeOutms = 20000
$script:UntrustedRepoSourceLocation = 'https://powershell.myget.org/F/powershellget-test-items/api/v2/'
$script:UntrustedRepoPublishLocation = 'https://powershell.myget.org/F/powershellget-test-items/api/v2/package'
# Create temp module to be published
$script:TempModulesPath = Join-Path -Path $script:TempPath -ChildPath "PSGet_$(Get-Random)"
$script:TestPSModulePath = Join-Path -Path $script:TempPath -ChildPath "PSGet_$(Get-Random)"
$null = New-Item -Path $script:TempModulesPath -ItemType Directory -Force
$null = New-Item -Path $script:TestPSModulePath -ItemType Directory -Force
# Set up local "gallery"
$script:localGalleryName = [System.Guid]::NewGuid().ToString()
$script:PSGalleryRepoPath = Join-Path -Path $script:TempPath -ChildPath 'PSGalleryRepo'
RemoveItem $script:PSGalleryRepoPath
$null = New-Item -Path $script:PSGalleryRepoPath -ItemType Directory -Force
Set-PSGallerySourceLocation -Name $script:localGalleryName -Location $script:PSGalleryRepoPath -PublishLocation $script:PSGalleryRepoPath -UseExistingModuleSourcesFile
# Set up signed modules if signing is available
if ((Get-Module PKI -ListAvailable)) {
$pesterDestination = Join-Path -Path $script:TempModulesPath -ChildPath "Pester"
$pesterv1Destination = Join-Path -Path $pesterDestination -ChildPath "99.99.99.98"
$pesterv2Destination = Join-Path -Path $pesterDestination -ChildPath "99.99.99.99"
if (Test-Path -Path $pesterDestination) {
$null = Remove-Item -Path $pesterDestination -Force
}
$null = New-Item -Path $pesterDestination -Force -ItemType Directory
$null = New-Item -Path $pesterv1Destination -Force -ItemType Directory
$null = New-Item -Path $pesterv2Destination -Force -ItemType Directory
$null = New-ModuleManifest -Path (Join-Path -Path $pesterv1Destination -ChildPath "Pester.psd1") -Description "Test signed module v1" -ModuleVersion 99.99.99.98
$null = New-ModuleManifest -Path (Join-Path -Path $pesterv2Destination -ChildPath "Pester.psd1") -Description "Test signed module v2" -ModuleVersion 99.99.99.99
# Move Pester 3.4.0 to $script:TestPSModulePath
# If it doesn't exist, attempt to download it.
# If this is run offline, just fail the test for now.
# This module is expected to be Microsoft-signed.
# This is essentially a test hook to get around the hardcoded allowlist.
$signedPester = (Get-Module Pester -ListAvailable | Where-Object { $_.Version -eq '3.4.0' }).ModuleBase
if (-not $signedPester) {
$psName = [System.Guid]::NewGuid().ToString()
Register-PackageSource -Name $psName -Location "https://www.powershellgallery.com/api/v2" -ProviderName PowerShellGet -Trusted
try {
Save-Module Pester -RequiredVersion 3.4.0 -Repository $psName -Path $script:TestPSModulePath
}
finally {
Unregister-PackageSource -Name $psName
}
}
else {
$signedPesterDestination = Join-Path -Path $script:TestPSModulePath -ChildPath "Pester"
if (-not (Test-Path -Path $signedPesterDestination)) {
$null = New-Item -Path $signedPesterDestination -ItemType Directory
}
Copy-Item -Path $signedPester -Destination $signedPesterDestination -Recurse -Force
}
$csCert = Get-CodeSigningCert -IncludeLocalMachineCerts
if (-not $csCert) {
Create-CodeSigningCert
$csCert = Get-CodeSigningCert -IncludeLocalMachineCerts
}
$null = Set-AuthenticodeSignature -FilePath (Join-Path -Path $pesterv1Destination -ChildPath "Pester.psd1") -Certificate $csCert
$null = Set-AuthenticodeSignature -FilePath (Join-Path -Path $pesterv2Destination -ChildPath "Pester.psd1") -Certificate $csCert
}
}
function SuiteCleanup {
if (Test-Path $script:moduleSourcesBackupFilePath) {
Move-Item $script:moduleSourcesBackupFilePath $script:moduleSourcesFilePath -Force
}
else {
RemoveItem $script:moduleSourcesFilePath
}
# Import the PowerShellGet provider to reload the repositories.
$null = Import-PackageProvider -Name PowerShellGet -Force
if ($script:IsWindowsOS) {
# Delete the user
net user $script:UserName /delete | Out-Null
# Delete the user profile
# run only if cmd is available
if (Get-Command -Name Get-WmiObject -ErrorAction SilentlyContinue) {
$userProfile = (Get-WmiObject -Class Win32_UserProfile | Where-Object { $_.LocalPath -match $script:UserName })
if ($userProfile) {
RemoveItem $userProfile.LocalPath
}
}
}
RemoveItem $script:TempModulesPath
RemoveItem $script:TestPSModulePath
}
Describe PowerShell.PSGet.InstallModuleTests -Tags 'BVT', 'InnerLoop' {
BeforeAll {
SuiteSetup
}
AfterAll {
SuiteCleanup
}
AfterEach {
PSGetTestUtils\Uninstall-Module Contoso
PSGetTestUtils\Uninstall-Module ContosoServer
PSGetTestUtils\Uninstall-Module ContosoClient
PSGetTestUtils\Uninstall-Module DscTestModule
}
# Purpose: InstallShouldBeSilent
#
# Action: Install-Module "ContosoServer"
#
# Expected Result: Should pass
#
It "Install-Module ContosoServer should return be silent" {
$result = Install-Module -Name "ContosoServer"
$result | Should -BeNullOrEmpty
}
# Purpose: InstallShouldReturnOutput
#
# Action: Install-Module "ContosoServer" -PassThru
#
# Expected Result: Should pass
#
It "Install-Module ContosoServer -PassThru should return output" {
$result = Install-Module -Name "ContosoServer" -PassThru
$result | Should -Not -BeNullOrEmpty
}
# Purpose: InstallNotAvailableModuleWithWildCard
#
# Action: Install-Module "Co[nN]t?soS[a-z]r?eW"
#
# Expected Result: Should fail with an error
#
It "InstallNotAvailableModuleWithWildCard" {
AssertFullyQualifiedErrorIdEquals -scriptblock { Install-Module -Name "Co[nN]t?soS[a-z]r?eW" } `
-expectedFullyQualifiedErrorId 'NameShouldNotContainWildcardCharacters,Install-Module'
}
# Purpose: InstallModuleWithVersionParams
#
# Action: Install-Module ContosoServer -MinimumVersion 1.0 -RequiredVersion 5.0
#
# Expected Result: Should fail with an error id
#
It "InstallModuleWithVersionParams" {
AssertFullyQualifiedErrorIdEquals -scriptblock { Install-Module ContosoServer -MinimumVersion 1.0 -RequiredVersion 5.0 } `
-expectedFullyQualifiedErrorId "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Install-Module"
}
# Purpose: InstallMultipleNamesWithReqVersion
#
# Action: Install-Module ContosoClient,ContosoServer -RequiredVersion 2.0
#
# Expected Result: Should fail with an error id
#
It "InstallMultipleNamesWithReqVersion" {
AssertFullyQualifiedErrorIdEquals -scriptblock { Install-Module ContosoClient, ContosoServer -RequiredVersion 2.0 } `
-expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Install-Module"
}
# Purpose: InstallMultipleNamesWithMinVersion
#
# Action: Install-Module ContosoClient,ContosoServer -MinimumVersion 2.0
#
# Expected Result: Should fail with an error id
#
It "InstallMultipleNamesWithMinVersion" {
AssertFullyQualifiedErrorIdEquals -scriptblock { Install-Module ContosoClient, ContosoServer -MinimumVersion 2.0 } `
-expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Install-Module"
}
# Purpose: InstallMultipleModules
#
# Action: Install-Module ContosoClient,ContosoServer
#
# Expected Result: two modules should be installed
#
It "InstallMultipleModules" {
Install-Module ContosoClient, ContosoServer
$res = Get-Module ContosoClient, ContosoServer -ListAvailable
Assert ($res.Count -eq 2) "Install-Module with multiple names should not fail"
}
# Purpose: InstallSingleModule
#
# Action: Install-Module ContosoServer
#
# Expected Result: module should be installed
#
It "InstallSingleModule" {
Install-Module ContosoServer
$res = Get-Module ContosoServer -ListAvailable
Assert (($res.Count -eq 1) -and ($res.Name -eq "ContosoServer")) "Install-Module failed to install ContosoServer"
}
# Purpose: InstallAModuleWithMinVersion
#
# Action: Install-Module ContosoServer -MinimumVersion 1.0
#
# Expected Result: Should install the module
#
It "InstallAModuleWithMinVersion" {
Install-Module ContosoServer -MinimumVersion 1.0
$res = Get-Module ContosoServer -ListAvailable
Assert (($res.Count -eq 1) -and ($res.Name -eq "ContosoServer") -and ($res.Version -ge [Version]"2.5")) "Install-Module failed to install with Version"
}
# Purpose: InstallAModuleWithReqVersion
#
# Action: Install-Module ContosoServer -RequiredVersion 1.5
#
# Expected Result: Should install the module with exact version
#
It "InstallAModuleWithReqVersion" {
Install-Module ContosoServer -RequiredVersion 1.5
$res = Get-Module ContosoServer -ListAvailable
Assert (($res.Count -eq 1) -and ($res.Name -eq "ContosoServer") -and ($res.Version -eq [Version]"1.5")) "Install-Module failed to install with Version"
}
# Purpose: InstallModuleShouldFailIfReqVersionNotAlreadyInstalled
#
# Action: install a module with 1.5 version, then try to install 2.0 as required version
#
# Expected Result: second install module cmdlet should fail with an error id
#
It "InstallModuleShouldFailIfReqVersionNotAlreadyInstalled" {
Install-Module ContosoServer -RequiredVersion 1.5
$expectedFullyQualifiedErrorId = 'ModuleAlreadyInstalled,Install-Package,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage'
AssertFullyQualifiedErrorIdEquals -scriptblock { Install-Module ContosoServer -RequiredVersion 2.0 -WarningAction SilentlyContinue } `
-expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
}
# Purpose: InstallModuleShouldFailIfMinVersionNotAlreadyInstalled
#
# Action: install a module with 1.5 version, then try to install 2.0 as minimum version
#
# Expected Result: second install module cmdlet should fail with an error id
#
It "InstallModuleShouldFailIfMinVersionNotAlreadyInstalled" {
Install-Module ContosoServer -RequiredVersion 1.5
$expectedFullyQualifiedErrorId = 'ModuleAlreadyInstalled,Install-Package,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage'
AssertFullyQualifiedErrorIdEquals -scriptblock { Install-Module ContosoServer -MinimumVersion 2.0 -WarningAction SilentlyContinue } `
-expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
}
# Purpose: InstallModuleShouldNotFailIfReqVersionAlreadyInstalled
#
# Action: install a module with 2.0 version, then try to install 2.0 as required version
#
# Expected Result: second install module cmdlet should not fail
#
It "InstallModuleShouldNotFailIfReqVersionAlreadyInstalled" {
Install-Module ContosoServer -RequiredVersion 2.0
$MyError = $null
Install-Module ContosoServer -RequiredVersion 2.0 -ErrorVariable MyError
Assert ($MyError.Count -eq 0) "There should not be any error from second install with required, $MyError"
}
# Purpose: InstallModuleShouldNotFailIfMinVersionAlreadyInstalled
#
# Action: install a module with 2.5 version, then try to install 2.0 as minimum version
#
# Expected Result: second install module cmdlet should not fail
#
It "InstallModuleShouldNotFailIfMinVersionAlreadyInstalled" {
Install-Module ContosoServer -RequiredVersion 2.5
$MyError = $null
Install-Module ContosoServer -MinimumVersion 2.0 -ErrorVariable MyError
Assert ($MyError.Count -eq 0) "There should not be any error from second install with min version, $MyError"
}
# Purpose: InstallModuleWithForce
#
# Action:
# Install-Module ContosoServer -RequiredVersion 1.0
# Install-Module ContosoServer -RequiredVersion 1.5 -Force
#
# Expected Result: Second install should not fail
#
It InstallModuleWithForce {
Install-Module ContosoServer -RequiredVersion 1.0
$MyError = $null
Install-Module ContosoServer -RequiredVersion 1.5 -Force -ErrorVariable MyError
Assert ($MyError.Count -eq 0) "There should not be any error from force install, $MyError"
if (Test-ModuleSxSVersionSupport) {
$res = Get-Module -FullyQualifiedName @{ModuleName = 'ContosoServer'; RequiredVersion = '1.5' } -ListAvailable
}
else {
$res = Get-Module ContosoServer -ListAvailable
}
Assert (($res.Count -eq 1) -and ($res.Name -eq "ContosoServer") -and ($res.Version -eq [Version]"1.5")) "Install-Module with existing module should be overwritten if force is specified"
}
# Purpose: InstallModuleSameVersionWithForce
#
# Action:
# Install-Module ContosoServer -RequiredVersion 1.5
# Install-Module ContosoServer -RequiredVersion 1.5 -Force
#
# Expected Result: Second install should not fail
#
It InstallModuleSameVersionWithForce {
Install-Module ContosoServer -RequiredVersion 1.5
$MyError = $null
Install-Module ContosoServer -RequiredVersion 1.5 -Force -ErrorVariable MyError
Assert ($MyError.Count -eq 0) "There should not be any error from force install, $MyError"
$res = Get-Module ContosoServer -ListAvailable
Assert (($res.Count -eq 1) -and ($res.Name -eq "ContosoServer") -and ($res.Version -eq [Version]"1.5")) "Install-Module with existing module should be overwritten if force is specified"
}
# Purpose: Install a module using non available MinimumVersion
#
# Action: Install-Module ContosoServer -MinimumVersion 10.0
#
# Expected Result: should fail with error id
#
It "InstallModuleWithNotAvailableMinVersion" {
$expectedFullyQualifiedErrorId = 'NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage'
AssertFullyQualifiedErrorIdEquals -scriptblock { Install-Module ContosoServer -MinimumVersion 10.0 } `
-expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
}
# Purpose: Install a module using non available RequiredVersion
#
# Action: Install-Module ContosoServer -RequiredVersion 1.44
#
# Expected Result: should fail with error id
#
It "InstallModuleWithNotAvailableReqVersion" {
$expectedFullyQualifiedErrorId = 'NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage'
AssertFullyQualifiedErrorIdEquals -scriptblock { Install-Module ContosoServer -RequiredVersion 1.44 } `
-expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
}
# Purpose: Install a module using RequiredVersion
#
# Action: Install-Module ContosoServer -RequiredVersion 1.5
#
# Expected Result: should install the specified version
#
It "InstallModuleWithReqVersion" {
Install-Module ContosoServer -RequiredVersion 1.5 -Confirm:$false
$res = Get-Module ContosoServer -ListAvailable
Assert (($res.Count -eq 1) -and ($res.Name -eq "ContosoServer") -and ($res.Version -eq [Version]"1.5")) "Install-Module failed to install with RequiredVersion"
}
# Purpose: Install a module using MinimumVersion
#
# Action: Install-Module ContosoServer -MinimumVersion 1.5
#
# Expected Result: should install the module with latest or specified version
#
It "InstallModuleWithMinVersion" {
Install-Module ContosoServer -MinimumVersion 1.5
$res = Get-Module ContosoServer -ListAvailable
Assert (($res.Count -eq 1) -and ($res.Name -eq "ContosoServer") -and ($res.Version -ge [Version]"2.5")) "Install-Module failed to install with MinimumVersion"
}
# Purpose: InstallNotAvailableModule
#
# Action: Install-Module NonExistentModule
#
# Expected Result: should fail with error
#
It "InstallNotAvailableModule" {
$expectedFullyQualifiedErrorId = 'NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage'
AssertFullyQualifiedErrorIdEquals -scriptblock { Install-Module NonExistentModule } `
-expectedFullyQualifiedErrorId $expectedFullyQualifiedErrorId
}
# Purpose: InstallModuleWithPipelineInput
#
# Action: Find-Module ContosoServer | Install-Module
#
# Expected Result: ContosoServer should be installed
#
It "InstallModuleWithPipelineInput" {
Find-Module ContosoServer | Install-Module
$res = Get-Module ContosoServer -ListAvailable
Assert (($res.Count -eq 1) -and ($res.Name -eq "ContosoServer")) "Install-Module failed to install ContosoServer with pipeline input"
}
# Purpose: InstallMultipleModulesWithPipelineInput
#
# Action: Find-Module ContosoClient,ContosoServer | Install-Module
#
# Expected Result: ContosoServer and ContosoClient should be installed
#
It "InstallMultipleModulesWithPipelineInput" {
Find-Module ContosoClient, ContosoServer | Install-Module
$res = Get-Module ContosoClient, ContosoServer -ListAvailable
Assert ($res.Count -eq 2) "Install-Module failed to install multiple modules from Find-Module output"
}
# Purpose: InstallMultipleModulesUsingInputObjectParam
#
# Action: find two modules and use pass it's output as -InputObject param to Install-Module cmdlet
#
# Expected Result: ContosoServer and ContosoClient should be installed
#
It "InstallMultipleModulesUsingInputObjectParam" {
$items = Find-Module ContosoClient, ContosoServer
Install-Module -InputObject $items
$res = Get-Module ContosoClient, ContosoServer -ListAvailable
Assert ($res.Count -eq 2) "Install-Module failed to install multiple modules with -InputObject parameter"
}
# Purpose: InstallToCurrentUserScopeWithPipelineInput
#
# Action: Find-Module ContosoServer | Install-Module -Scope CurrentUser
#
# Expected Result: module should be installed to current user's modules folder under $Home\WindowsPowerShell\Modules
#
It "InstallToCurrentUserScopeWithPipelineInput" {
Find-Module ContosoServer | Install-Module -Scope CurrentUser
$mod = Get-Module ContosoServer -ListAvailable
Assert ($mod.ModuleBase.StartsWith($script:MyDocumentsModulesPath, [System.StringComparison]::OrdinalIgnoreCase)) "Install-Module with CurrentUser scope did not install ContosoServer to user documents folder"
}
# Purpose: InstallToCurrentUserScope
#
# Action: Install-Module ContosoServer -Scope CurrentUser
#
# Expected Result: module should be installed to current user's modules folder under $Home\WindowsPowerShell\Modules
#
It "InstallToCurrentUserScope" {
Install-Module ContosoServer -Scope CurrentUser
$mod = Get-Module ContosoServer -ListAvailable
Assert ($mod.ModuleBase.StartsWith($script:MyDocumentsModulesPath, [System.StringComparison]::OrdinalIgnoreCase)) "Install-Module with CurrentUser scope did not install ContosoServer to user documents folder"
}
# Purpose: InstallModuleWithForceAndDifferentScope
#
# Action: Install-Module ContosoServer -Scope CurrentUser; Install-Module ContosoServer -Scope AllUsers -Force
#
# Expected Result: module should be installed to the specified scope with -Force
#
It "InstallModuleWithForceAndDifferentScope" {
Install-Module ContosoServer -Scope CurrentUser -RequiredVersion 1.0
$mod1 = Get-Module ContosoServer -ListAvailable
Assert ($mod1.ModuleBase.StartsWith($script:MyDocumentsModulesPath, [System.StringComparison]::OrdinalIgnoreCase)) "Install-Module with CurrentUser scope did not install ContosoServer to user documents folder, $mod1"
Install-Module ContosoServer -Scope AllUsers -Force -RequiredVersion 2.5
$mod2 = Get-Module ContosoServer -ListAvailable
AssertEquals $mod2.Count 2 "Only two modules should be available after changing the -Scope with -Force and without -AllowClobber on Install-Module cmdlet, $mod2"
$mod3 = Get-InstalledModule ContosoServer -RequiredVersion 2.5
AssertNotNull $mod3 "Install-Module with Force and without AllowClobber should install the module to a different scope, $mod3"
}
It "InstallModuleWithForceAllowClobberAndDifferentScope" {
Install-Module ContosoServer -Scope CurrentUser
$mod1 = Get-Module ContosoServer -ListAvailable
Assert ($mod1.ModuleBase.StartsWith($script:MyDocumentsModulesPath, [System.StringComparison]::OrdinalIgnoreCase)) "Install-Module with CurrentUser scope did not install ContosoServer to user documents folder, $mod1"
Install-Module ContosoServer -Scope AllUsers -Force -AllowClobber
$mod2 = Get-Module ContosoServer -ListAvailable
Assert ($mod2.Count -ge 2) "Atleast two versions of ContosoServer should be available after changing the -Scope with -Force and without -AllowClobber on Install-Module cmdlet, $mod2"
}
# Purpose: ValidateModuleIsInUseError
#
# Action: Install and import a module then try to install the same version again with -Force
#
# Expected Result: should fail with an error
#
It "ValidateModuleIsInUseError" {
$NonAdminConsoleOutput = Join-Path ([System.IO.Path]::GetTempPath()) 'nonadminconsole-out.txt'
Start-Process "$PSHOME\PowerShell.exe" -ArgumentList '$null = Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Scope CurrentUser;
$null = Import-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force;
Install-Module -Name DscTestModule -Scope CurrentUser;
Import-Module -Name DscTestModule;
Install-Module -Name DscTestModule -Scope CurrentUser -Force' `
-Wait `
-RedirectStandardOutput $NonAdminConsoleOutput
waitFor { Test-Path $NonAdminConsoleOutput } -timeoutInMilliseconds $script:assertTimeOutms -exceptionMessage "Install-Module on non-admin console failed to complete"
$content = Get-Content $NonAdminConsoleOutput
Assert ($content -and ($content -match 'DscTestModule')) "Install-module with -force should fail when a module version being installed is in use, $content."
RemoveItem $NonAdminConsoleOutput
} `
-Skip:$(
$whoamiValue = (whoami)
($PSEdition -eq 'Core') -or
($whoamiValue -eq "NT AUTHORITY\SYSTEM") -or
($whoamiValue -eq "NT AUTHORITY\LOCAL SERVICE") -or
($whoamiValue -eq "NT AUTHORITY\NETWORK SERVICE") -or
($PSCulture -ne 'en-US') -or
($PSVersionTable.PSVersion -lt '5.0.0')
)
# Purpose: InstallModuleWithWhatIf
#
# Action: Find-Module ContosoServer | Install-Module -WhatIf
#
# Expected Result: it should not install the module
#
It "InstallModuleWithWhatIf" {
$outputPath = $script:TempPath
$guid = [system.guid]::newguid().tostring()
$outputFilePath = Join-Path $outputPath "$guid"
$runspace = CreateRunSpace $outputFilePath 1
$content = $null
try {
$result = ExecuteCommand $runspace 'Install-Module -Name ContosoServer -WhatIf'
}
finally {
$fileName = "WriteLine-0.txt"
$path = join-path $outputFilePath $fileName
if (Test-Path $path) {
$content = get-content $path
}
CloseRunSpace $runspace
RemoveItem $outputFilePath
}
$itemInfo = Find-Module ContosoServer -Repository PSGallery
$installShouldProcessMessage = $script:LocalizedData.InstallModulewhatIfMessage -f ($itemInfo.Name, $itemInfo.Version)
Assert ($content -and ($content -match $installShouldProcessMessage)) "Install module whatif message is missing, Expected:$installShouldProcessMessage, Actual:$content"
$mod = Get-Module ContosoServer -ListAvailable
Assert (-not $mod) "Install-Module should not install the module with -WhatIf option"
} `
-Skip:$(($PSEdition -eq 'Core') -or ([System.Environment]::OSVersion.Version -lt "6.2.9200.0") -or ($PSCulture -ne 'en-US'))
# Purpose: InstallModuleWithConfirmAndNoToPrompt
#
# Action: Install-Module ContosoServer -Confirm
#
# Expected Result: module should not be installed after confirming NO
#
It "InstallModuleWithConfirmAndNoToPrompt" {
$outputPath = $script:TempPath
$guid = [system.guid]::newguid().tostring()
$outputFilePath = Join-Path $outputPath "$guid"
$runspace = CreateRunSpace $outputFilePath 1
# 2 is mapped to NO in ShouldProcess prompt
$Global:proxy.UI.ChoiceToMake = 2
$content = $null
try {
$result = ExecuteCommand $runspace 'Install-Module ContosoServer -Repository PSGallery -Confirm'
}
finally {
$fileName = "PromptForChoice-0.txt"
$path = join-path $outputFilePath $fileName
if (Test-Path $path) {
$content = get-content $path
}
CloseRunSpace $runspace
RemoveItem $outputFilePath
}
$itemInfo = Find-Module ContosoServer -Repository PSGallery
$installShouldProcessMessage = $script:LocalizedData.InstallModulewhatIfMessage -f ($itemInfo.Name, $itemInfo.Version)
Assert ($content -and ($content -match $installShouldProcessMessage)) "Install module confirm prompt is not working, Expected:$installShouldProcessMessage, Actual:$content"
$res = Get-Module ContosoServer -ListAvailable
AssertNull $res "Install-Module should not install a module if Confirm is not accepted"
} `
-Skip:$(($PSEdition -eq 'Core') -or ([System.Environment]::OSVersion.Version -lt "6.2.9200.0") -or ($PSCulture -ne 'en-US'))
# Purpose: InstallModuleWithConfirmAndYesToPrompt
#
# Action: Find-Module ContosoServer | Install-Module -Confirm
#
# Expected Result: module should be installed after confirming YES
#
It "InstallModuleWithConfirmAndYesToPrompt" {
$outputPath = $script:TempPath
$guid = [system.guid]::newguid().tostring()
$outputFilePath = Join-Path $outputPath "$guid"
$runspace = CreateRunSpace $outputFilePath 1
# 0 is mapped to YES in ShouldProcess prompt
$Global:proxy.UI.ChoiceToMake = 0
$content = $null
try {
$result = ExecuteCommand $runspace 'Find-Module ContosoServer | Install-Module -Confirm'
}
finally {
$fileName = "PromptForChoice-0.txt"
$path = join-path $outputFilePath $fileName
if (Test-Path $path) {
$content = get-content $path
}
CloseRunSpace $runspace
RemoveItem $outputFilePath
}
$itemInfo = Find-Module ContosoServer -Repository PSGallery
$installShouldProcessMessage = $script:LocalizedData.InstallModulewhatIfMessage -f ($itemInfo.Name, $itemInfo.Version)
Assert ($content -and ($content -match $installShouldProcessMessage)) "Install module confirm prompt is not working, Expected:$installShouldProcessMessage, Actual:$content"
$res = Get-Module ContosoServer -ListAvailable
Assert (($res.Count -eq 1) -and ($res.Name -eq "ContosoServer")) "Install-Module should install a module if Confirm is accepted"
} `
-Skip:$(($PSEdition -eq 'Core') -or ([System.Environment]::OSVersion.Version -lt "6.2.9200.0") -or ($PSCulture -ne 'en-US'))
# Purpose: Validate PowerShellGet related properties on PSModuleInfo
#
# Action: Install a module, then Get it's PSModuleInfo using Get-Module -ListAvailable
#
# Expected Result: PSModuleInfo should have Tags, LicenseUri, ProjectUri, IconUri, ReleaseNotes, SourceName, SourceLocation, DateUpdated properties
#
It ValidatePSGetPropertiesOnPSModuleInfoFromGetModule {
Install-Module ContosoServer -Repository PSGallery
$res = Get-Module ContosoServer -ListAvailable
Assert (($res.Count -eq 1) -and ($res.Name -eq "ContosoServer") -and ($res.Version -ge [Version]"2.5")) "Install-Module failed to install ContosoServer"
AssertNotNull $res.Tags "Tags value is missing on PSModuleInfo"
AssertNotNull $res.LicenseUri "LicenseUri value is missing on PSModuleInfo"
AssertNotNull $res.ProjectUri "ProjectUri value is missing on PSModuleInfo"
AssertNotNull $res.IconUri "IconUri value is missing on PSModuleInfo"
AssertNotNull $res.ReleaseNotes "ReleaseNotes value is missing on PSModuleInfo"
AssertNotNull $res.RepositorySourceLocation "RepositorySourceLocation value is missing on PSModuleInfo"
} -Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
# Purpose: Install a module with Find-RoleCapability output
#
# Action: Find-RoleCapability -Name Lev1Maintenance,Lev2Maintenance | Install-Module
#
# Expected Result: DscTestModule should be installed
#
It InstallModuleUsingFindRoleCapabilityOutput {
$moduleName = "DscTestModule"
Find-RoleCapability -Name Lev1Maintenance, Lev2Maintenance | Where-Object { $_.ModuleName -eq $moduleName } | Install-Module
$res = Get-Module $moduleName -ListAvailable
AssertEquals $res.Name $moduleName "Install-Module failed to install with Find-RoleCapability output"
}
# Purpose: Install a module with Find-DscResource output
#
# Action: Find-DscResource -Name DscTestResource,NewDscTestResource | Install-Module
#
# Expected Result: DscTestModule should be installed
#
It InstallModuleUsingFindDscResourceOutput {
$moduleName = "DscTestModule"
Find-DscResource -Name DscTestResource, NewDscTestResource | Where-Object { $_.ModuleName -eq $moduleName } | Install-Module
$res = Get-Module $moduleName -ListAvailable
AssertEquals $res.Name $moduleName "Install-Module failed to install with Find-DscResource output"
}
<#
Purpose: Validate the Get-InstalledModule
Action: Install a module, get installed module count, update the module, get module count
Expected Result: should be able to get the installed module.
#>
It ValidateGetInstalledModuleCmdlet {
$ModuleName = 'ContosoServer'
$ContosoClient = 'ContosoClient'
$DateTimeBeforeInstall = Get-Date
Install-Module -Name $ContosoClient
$mod = Get-InstalledModule -Name $ContosoClient
AssertEquals $mod.Name $ContosoClient "Get-InstalledModule results are not expected, $mod"
AssertNotNull $mod.InstalledDate "Get-InstalledModule results are not expected, InstalledDate should not be null, $mod"
Assert ($mod.InstalledDate.AddSeconds(1) -ge $DateTimeBeforeInstall) "Get-InstalledModule results are not expected, InstalledDate $($mod.InstalledDate.Ticks) should be after $($DateTimeBeforeInstall.Ticks)"
AssertNull $mod.UpdatedDate "Get-InstalledModule results are not expected, UpdateDate should be null, $mod"
Install-Module -Name $ModuleName -RequiredVersion 1.0 -Force
$modules = Get-InstalledModule
AssertNotNull $modules "Get-InstalledModule is not working properly"
$mod = Get-InstalledModule -Name $ModuleName
AssertEquals $mod.Name $ModuleName "Get-InstalledModule returned wrong module, $mod"
AssertEquals $mod.Version "1.0" "Get-InstalledModule returned wrong module version, $mod"
$modules1 = Get-InstalledModule
Update-Module -Name $ModuleName -RequiredVersion 2.0
$mod2 = Get-InstalledModule -Name $ModuleName -RequiredVersion "2.0"
AssertEquals $mod2.Name $ModuleName "Get-InstalledModule returned wrong module after Update-Module, $mod2"
AssertEquals $mod2.Version "2.0" "Get-InstalledModule returned wrong module version after Update-Module, $mod2"
$modules2 = Get-InstalledModule
# Because of TFS:1908563, we changed Get-Package to show only the latest version by default
# hence the count is same after the update.
AssertEquals $modules1.count $modules2.count "module count should be same before and after updating a module, before: $($modules1.count), after: $($modules2.count)"
}
It ValidateGetInstalledModuleAndUninstallModuleCmdletsWithMinimumVersion {
$ModuleName = 'ContosoServer'
$version = "2.0"
try {
Install-Module -Name $ModuleName -RequiredVersion $version -Force
$module = Get-InstalledModule -Name $ModuleName -MinimumVersion 1.0
AssertEquals $module.Name $ModuleName "Get-InstalledModule is not working properly, $module"
AssertEquals $module.Version $Version "Get-InstalledModule is not working properly, $module"
}
finally {
PowerShellGet\Uninstall-Module -Name $ModuleName -MinimumVersion $Version
$module = Get-InstalledModule -Name $ModuleName -ErrorAction SilentlyContinue
AssertNull $module "Module uninstallation is not working properly, $module"
}
}
It ValidateGetInstalledModuleAndUninstallModuleCmdletWithMinMaxRange {
$ModuleName = 'ContosoServer'
$version = "2.0"
try {
Install-Module -Name $ModuleName -RequiredVersion $version -Force
$module = Get-InstalledModule -Name $ModuleName -MinimumVersion $Version -MaximumVersion $Version
AssertEquals $module.Name $ModuleName "Get-InstalledModule is not working properly, $module"
AssertEquals $module.Version $Version "Get-InstalledModule is not working properly, $module"
}
finally {
PowerShellGet\Uninstall-Module -Name $ModuleName -MinimumVersion $Version -MaximumVersion $Version
$module = Get-InstalledModule -Name $ModuleName -ErrorAction SilentlyContinue
AssertNull $module "Module uninstallation is not working properly, $module"
}
}
It ValidateGetInstalledModuleAndUninstallModuleCmdletWithRequiredVersion {
$ModuleName = 'ContosoServer'
$version = "2.0"
try {
Install-Module -Name $ModuleName -RequiredVersion $version -Force
$module = Get-InstalledModule -Name $ModuleName -RequiredVersion $Version
AssertEquals $module.Name $ModuleName "Get-InstalledModule is not working properly, $module"
AssertEquals $module.Version $Version "Get-InstalledModule is not working properly, $module"
}
finally {
PowerShellGet\Uninstall-Module -Name $ModuleName -RequiredVersion $Version
$module = Get-InstalledModule -Name $ModuleName -ErrorAction SilentlyContinue
AssertNull $module "Module uninstallation is not working properly, $module"
}
}
It ValidateGetInstalledModuleAndUninstallModuleCmdletWithMiximumVersion {
$ModuleName = 'ContosoServer'
$version = "2.0"
try {
Install-Module -Name $ModuleName -RequiredVersion $version -Force
$module = Get-InstalledModule -Name $ModuleName -MaximumVersion $Version
AssertEquals $module.Name $ModuleName "Get-InstalledModule is not working properly, $module"
AssertEquals $module.Version $Version "Get-InstalledModule is not working properly, $module"
}
finally {
PowerShellGet\Uninstall-Module -Name $ModuleName -RequiredVersion $Version
$module = Get-InstalledModule -Name $ModuleName -ErrorAction SilentlyContinue
AssertNull $module "Module uninstallation is not working properly, $module"
}
}
# Purpose: Install a module with Find-Command output
#
# Action: Find-Command -Name Get-ContosoServer,Get-ContosoClient | Install-Module
#
# Expected Result: DscTestModule should be installed
#
It InstallModuleUsingFindCommandOutput {
$moduleName1 = "ContosoServer"
$moduleName2 = "ContosoClient"
Find-Command -Name Get-ContosoServer, Get-ContosoClient | Where-Object { ($_.ModuleName -eq $moduleName1) -or ($_.ModuleName -eq $moduleName2) } | Install-Module
$res = Get-Module $moduleName1 -ListAvailable
AssertEquals $res.Name $moduleName1 "Install-Module failed to install with Find-Command output"
$res = Get-Module $moduleName2 -ListAvailable
AssertEquals $res.Name $moduleName2 "Install-Module failed to install with Find-Command output"
}
# Purpose: Install a allowlisted non-Microsoft signed Pester or PSReadline version without -SkipPublisherCheck
#
# Action: Install-Module -Name Pester -RequiredVersion <Anything non-Microsoft signed>
#
# Expected Result: Warning and installed
#
It 'InstallNonMsSignedModuleOverMsSignedModule' {
$pesterRoot = Join-Path -Path $script:TempModulesPath -ChildPath "Pester"
$v1Path = Join-Path -Path $pesterRoot -ChildPath "99.99.99.98"
$v2Path = Join-Path -Path $pesterRoot -ChildPath "99.99.99.99"
# Publish signed modules
Publish-Module -Path $v1Path -Repository $script:localGalleryName
Publish-Module -Path $v2Path -Repository $script:localGalleryName
$oldPSModulePath = $env:PSModulePath
$env:PSModulePath = $script:TestPSModulePath
try {
# Install v1 of signed module
Install-Module Pester -RequiredVersion 99.99.99.98 -Repository $script:localGalleryName -ErrorVariable iev -WarningVariable iwv -WarningAction SilentlyContinue -Force
# Expect: Warning and Success
$iev | should be $null
$iwv | should not be $null
$iwv | should not belike "*root*authority*"
# Fix PSModulePath
# This is done before installing v2 because
# PSGet will install to hardcoded paths regardless of PSModulePath
# Meaning the hacked $env:PSModulePath won't have the new 99.99.99.98 module
$env:PSModulePath = $oldPSModulePath
# Install v2 of signed module
Install-Module Pester -RequiredVersion 99.99.99.99 -Repository $script:localGalleryName -ErrorVariable iev -WarningVariable iwv -Force
# Expect: No warning and Success
$iev | should be $null
$iwv | should be $null
}
finally {
# Fix PSModulePath again in case the fix in the try-block didn't work
$env:PSModulePath = $oldPSModulePath
# If v1 exists, uninstall
if (Get-Module Pester -ListAvailable | Where-Object { $_.Version -eq '99.99.99.98' }) {
$moduleBase = (Get-Module Pester -ListAvailable | Where-Object { $_.Version -eq '99.99.99.98' }).ModuleBase
$null = Remove-Item -Path $moduleBase -Force -Recurse
if (Get-Module Pester -ListAvailable | Where-Object { $_.Version -eq '99.99.99.98' }) {
Write-Error "Failed to uninstall v1"
}
}
# If v2 exists, uninstall
if (Get-Module Pester -ListAvailable | Where-Object { $_.Version -eq '99.99.99.99' }) {
$moduleBase = (Get-Module Pester -ListAvailable | Where-Object { $_.Version -eq '99.99.99.99' }).ModuleBase
$null = Remove-Item -Path $moduleBase -Force -Recurse
if (Get-Module Pester -ListAvailable | Where-Object { $_.Version -eq '99.99.99.99' }) {
Write-Error "Failed to uninstall v2"
}
}
}
} `
-Skip:$((-not (Get-Module PKI -ListAvailable)) -or ([Environment]::OSVersion.Version -lt '10.0'))
}
Describe PowerShell.PSGet.InstallModuleTests.P1 -Tags 'P1', 'OuterLoop' {
BeforeAll {
SuiteSetup
}
AfterAll {
SuiteCleanup
}
AfterEach {
PSGetTestUtils\Uninstall-Module Contoso
PSGetTestUtils\Uninstall-Module ContosoServer
PSGetTestUtils\Uninstall-Module ContosoClient
PSGetTestUtils\Uninstall-Module DscTestModule
}
# Purpose: Install a module with prefixed wildcard
#
# Action: Install-Module *ontosoServer
#
# Expected Result: Should fail with an error
#
It "InstallModuleWithPrefixWildCard" {
AssertFullyQualifiedErrorIdEquals -scriptblock { Install-Module *ontosoServer } `
-expectedFullyQualifiedErrorId 'NameShouldNotContainWildcardCharacters,Install-Module'
}
# Purpose: Install a module with postfixed wildcard
#
# Action: Install-Module ContosoServe*
#
# Expected Result: Should fail with an error
#
It "InstallModuleWithPostfixWildCard" {
AssertFullyQualifiedErrorIdEquals -scriptblock { Install-Module ContosoServe* } `
-expectedFullyQualifiedErrorId 'NameShouldNotContainWildcardCharacters,Install-Module'
}
# Purpose: InstallModuleWithRangeWildCards
#
# Action: Install-Module "Co[nN]t?soS[a-z]r?er"
#
# Expected Result: should fail with an error
#
It "InstallModuleWithRangeWildCards" {
AssertFullyQualifiedErrorIdEquals -scriptblock { Install-Module -Name "Co[nN]t?soS[a-z]r?er" } `
-expectedFullyQualifiedErrorId 'NameShouldNotContainWildcardCharacters,Install-Module'
}
# Purpose: Install a module with wildcard
#
# Action: Install-Module *ContosoServer*
#
# Expected Result: Should fail with an error
#
It "InstallModuleWithWildCards" {
AssertFullyQualifiedErrorIdEquals -scriptblock { Install-Module *ContosoServer* } `
-expectedFullyQualifiedErrorId 'NameShouldNotContainWildcardCharacters,Install-Module'
}
# Purpose: Validate PowerShellGet related properties on PSModuleInfo got from Import-Module
#
# Action: Install a module, then Get it's PSModuleInfo using Import-Module
#
# Expected Result: PSModuleInfo should have Tags, LicenseUri, ProjectUri, IconUri, ReleaseNotes, SourceName, SourceLocation, DateUpdated properties
#
It ValidatePSGetPropertiesOnPSModuleInfoFromImportModule {
Install-Module ContosoServer -Repository PSGallery
$res = Import-Module ContosoServer -PassThru -Force
$res | Remove-Module -Force
Assert (($res.Count -eq 1) -and ($res.Name -eq "ContosoServer") -and ($res.Version -ge [Version]"2.5")) "Install-Module failed to install ContosoServer"
AssertNotNull $res.Tags "Tags value is missing on PSModuleInfo"
AssertNotNull $res.LicenseUri "LicenseUri value is missing on PSModuleInfo"
AssertNotNull $res.ProjectUri "ProjectUri value is missing on PSModuleInfo"
AssertNotNull $res.IconUri "IconUri value is missing on PSModuleInfo"
AssertNotNull $res.ReleaseNotes "ReleaseNotes value is missing on PSModuleInfo"
AssertNotNull $res.RepositorySourceLocation "RepositorySourceLocation value is missing on PSModuleInfo"
} -Skip:$($PSVersionTable.PSVersion -lt '5.0.0')
# Purpose: Install a modul from an untrusted repository and press No to the prompt
#
# Action: Install-Module ContosoServer -Repostory UntrustedTestRepo
#
# Expected Result: module should not be installed
#
It InstallAModulFromUntrustedRepositoryAndNoToPrompt {