Skip to content

Commit aa44e8f

Browse files
Update install tests to leverage passthru
1 parent 267d734 commit aa44e8f

1 file changed

Lines changed: 30 additions & 61 deletions

File tree

test/InstallPSResourceTests/InstallPSResourceADOServer.Tests.ps1

Lines changed: 30 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -29,69 +29,60 @@ Describe 'Test Install-PSResource for ADO V3Server scenarios' -tags 'CI' {
2929
@{Name="Test_local_m*"; ErrorId="NameContainsWildcard"},
3030
@{Name="Test?local","Test[local"; ErrorId="ErrorFilteringNamesForUnsupportedWildcards"}
3131

32-
It "Should not install resource with wildcard in name" -TestCases $testCases {
32+
It "Should not install resource with wildcard in name -- $Name" -TestCases $testCases {
3333
param($Name, $ErrorId)
34-
Install-PSResource -Name $Name -Repository $ADORepoName -ErrorVariable err -ErrorAction SilentlyContinue
34+
$installed = Install-PSResource -Name $Name -Repository $ADORepoName -ErrorVariable err -ErrorAction SilentlyContinue -PassThru
35+
$installed | Should -BeNullOrEmpty
3536
$err.Count | Should -BeGreaterThan 0
3637
$err[0].FullyQualifiedErrorId | Should -BeExactly "$ErrorId,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource"
37-
$res = Get-InstalledPSResource $testModuleName
38-
$res | Should -BeNullOrEmpty
3938
}
4039

4140
It "Install specific module resource by name" {
42-
Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository
43-
$pkg = Get-InstalledPSResource $testModuleName
41+
$pkg = Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -PassThru
4442
$pkg.Name | Should -Be $testModuleName
4543
$pkg.Version | Should -Be "5.0.0"
4644
}
4745

4846
It "Install specific script resource by name" {
49-
Install-PSResource -Name $testScriptName -Repository $ADORepoName -TrustRepository
50-
$pkg = Get-InstalledPSResource $testScriptName
47+
$pkg = Install-PSResource -Name $testScriptName -Repository $ADORepoName -TrustRepository -PassThru
5148
$pkg.Name | Should -Be $testScriptName
5249
$pkg.Version | Should -Be "1.0.0"
5350
}
5451

5552
It "Install multiple resources by name" {
5653
$pkgNames = @($testModuleName, $testModuleName2)
57-
Install-PSResource -Name $pkgNames -Repository $ADORepoName -TrustRepository
58-
$pkg = Get-InstalledPSResource $pkgNames
54+
$pkg = Install-PSResource -Name $pkgNames -Repository $ADORepoName -TrustRepository -PassThru
5955
$pkg.Name | Should -Be $pkgNames
6056
}
6157

6258
It "Should not install resource given nonexistent name" {
63-
Install-PSResource -Name "NonExistentModule" -Repository $ADORepoName -TrustRepository -ErrorVariable err -ErrorAction SilentlyContinue
64-
$pkg = Get-InstalledPSResource "NonExistentModule"
59+
$pkg = Install-PSResource -Name "NonExistentModule" -Repository $ADORepoName -TrustRepository -PassThru -ErrorVariable err -ErrorAction SilentlyContinue
6560
$pkg | Should -BeNullOrEmpty
6661
$err.Count | Should -BeGreaterThan 0
6762
$err[0].FullyQualifiedErrorId | Should -BeExactly "InstallPackageFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource"
6863
}
6964

7065
# Do some version testing, but Find-PSResource should be doing thorough testing
7166
It "Should install resource given name and exact version" {
72-
Install-PSResource -Name $testModuleName -Version "1.0.0" -Repository $ADORepoName -TrustRepository
73-
$pkg = Get-InstalledPSResource $testModuleName
67+
$pkg = Install-PSResource -Name $testModuleName -Version "1.0.0" -Repository $ADORepoName -TrustRepository -PassThru
7468
$pkg.Name | Should -Be $testModuleName
7569
$pkg.Version | Should -Be "1.0.0"
7670
}
7771

7872
It "Should install resource given name and exact version with bracket syntax" {
79-
Install-PSResource -Name $testModuleName -Version "[1.0.0]" -Repository $ADORepoName -TrustRepository
80-
$pkg = Get-InstalledPSResource $testModuleName
73+
$pkg = Install-PSResource -Name $testModuleName -Version "[1.0.0]" -Repository $ADORepoName -TrustRepository -PassThru
8174
$pkg.Name | Should -Be $testModuleName
8275
$pkg.Version | Should -Be "1.0.0"
8376
}
8477

8578
It "Should install resource given name and exact range inclusive [1.0.0, 5.0.0]" {
86-
Install-PSResource -Name $testModuleName -Version "[1.0.0, 5.0.0]" -Repository $ADORepoName -TrustRepository
87-
$pkg = Get-InstalledPSResource $testModuleName
79+
$pkg = Install-PSResource -Name $testModuleName -Version "[1.0.0, 5.0.0]" -Repository $ADORepoName -TrustRepository -PassThru
8880
$pkg.Name | Should -Be $testModuleName
8981
$pkg.Version | Should -Be "5.0.0"
9082
}
9183

9284
It "Should install resource given name and exact range exclusive (1.0.0, 5.0.0)" {
93-
Install-PSResource -Name $testModuleName -Version "(1.0.0, 5.0.0)" -Repository $ADORepoName -TrustRepository
94-
$pkg = Get-InstalledPSResource $testModuleName
85+
$pkg = Install-PSResource -Name $testModuleName -Version "(1.0.0, 5.0.0)" -Repository $ADORepoName -TrustRepository -PassThru
9586
$pkg.Name | Should -Be $testModuleName
9687
$pkg.Version | Should -Be "3.0.0"
9788
}
@@ -100,41 +91,37 @@ Describe 'Test Install-PSResource for ADO V3Server scenarios' -tags 'CI' {
10091
It "Should not install resource with incorrectly formatted version such as exclusive version (1.0.0.0)" {
10192
$Version = "(1.0.0.0)"
10293
try {
103-
Install-PSResource -Name $testModuleName -Version $Version -Repository $ADORepoName -TrustRepository -ErrorAction SilentlyContinue
94+
$res = Install-PSResource -Name $testModuleName -Version $Version -Repository $ADORepoName -TrustRepository -ErrorAction SilentlyContinue
10495
}
10596
catch
10697
{}
10798
$Error[0].FullyQualifiedErrorId | Should -be "IncorrectVersionFormat,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource"
10899

109-
$res = Get-InstalledPSResource $testModuleName
110100
$res | Should -BeNullOrEmpty
111101
}
112102

113103
It "Install resource when given Name, Version '*', should install the latest version" {
114-
Install-PSResource -Name $testModuleName -Version "*" -Repository $ADORepoName -TrustRepository
115-
$pkg = Get-InstalledPSResource $testModuleName
104+
$pkg = Install-PSResource -Name $testModuleName -Version "*" -Repository $ADORepoName -TrustRepository -PassThru
116105
$pkg.Name | Should -Be $testModuleName
117106
$pkg.Version | Should -Be "5.0.0"
118107
}
119108

120109
It "Install resource with latest (including prerelease) version given Prerelease parameter" {
121-
Install-PSResource -Name $testModuleName -Prerelease -Repository $ADORepoName -TrustRepository
122-
$pkg = Get-InstalledPSResource $testModuleName
110+
$pkg = Install-PSResource -Name $testModuleName -Prerelease -Repository $ADORepoName -TrustRepository -PassThru
123111
$pkg.Name | Should -Be $testModuleName
124112
$pkg.Version | Should -Be "5.2.5"
125113
$pkg.Prerelease | Should -Be "alpha001"
126114
}
127115

128116
It "Install resource via InputObject by piping from Find-PSresource" {
129-
Find-PSResource -Name $testModuleName -Repository $ADORepoName | Install-PSResource -TrustRepository
130-
$pkg = Get-InstalledPSResource $testModuleName
117+
$pkg = Find-PSResource -Name $testModuleName -Repository $ADORepoName | Install-PSResource -TrustRepository -PassThru
131118
$pkg.Name | Should -Be $testModuleName
132119
$pkg.Version | Should -Be "5.0.0"
133120
}
134121

135122
It "Install resource with companyname and repository source location and validate properties" {
136123
Install-PSResource -Name $testModuleName -Version "5.2.5-alpha001" -Repository $ADORepoName -TrustRepository
137-
$pkg = Get-InstalledPSResource $testModuleName
124+
$pkg = Install-PSResource -Name $testModuleName -Version "5.2.5-alpha001" -Repository $ADORepoName -TrustRepository -PassThru
138125
$pkg.Version | Should -Be "5.2.5"
139126
$pkg.Prerelease | Should -Be "alpha001"
140127

@@ -144,75 +131,61 @@ Describe 'Test Install-PSResource for ADO V3Server scenarios' -tags 'CI' {
144131

145132
# Windows only
146133
It "Install resource under CurrentUser scope - Windows only" -Skip:(!(Get-IsWindows)) {
147-
Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -Scope CurrentUser
148-
$pkg = Get-InstalledPSResource $testModuleName
134+
$pkg = Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -Scope CurrentUser -PassThru
149135
$pkg.Name | Should -Be $testModuleName
150136
$pkg.InstalledLocation.ToString().Contains("Documents") | Should -Be $true
151137
}
152138

153139
# Windows only
154140
It "Install resource under AllUsers scope - Windows only" -Skip:(!((Get-IsWindows) -and (Test-IsAdmin))) {
155-
Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -Scope AllUsers -Verbose
156-
$pkg = Get-InstalledPSResource $testModuleName -Scope AllUsers
141+
$pkg = Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -Scope AllUsers -Verbose -PassThru
157142
$pkg.Name | Should -Be $testModuleName
158143
$pkg.InstalledLocation.ToString().Contains("Program Files") | Should -Be $true
159144
}
160145

161146
# Windows only
162147
It "Install resource under no specified scope - Windows only" -Skip:(!(Get-IsWindows)) {
163-
Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository
164-
$pkg = Get-InstalledPSResource $testModuleName
148+
$pkg = Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -PassThru
165149
$pkg.Name | Should -Be $testModuleName
166150
$pkg.InstalledLocation.ToString().Contains("Documents") | Should -Be $true
167151
}
168152

169153
# Unix only
170154
# Expected path should be similar to: '/home/janelane/.local/share/powershell/Modules'
171155
It "Install resource under CurrentUser scope - Unix only" -Skip:(Get-IsWindows) {
172-
Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -Scope CurrentUser
173-
$pkg = Get-InstalledPSResource $testModuleName
156+
$pkg = Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -Scope CurrentUser -PassThru
174157
$pkg.Name | Should -Be $testModuleName
175158
$pkg.InstalledLocation.ToString().Contains("$env:HOME/.local") | Should -Be $true
176159
}
177160

178161
# Unix only
179162
# Expected path should be similar to: '/home/janelane/.local/share/powershell/Modules'
180163
It "Install resource under no specified scope - Unix only" -Skip:(Get-IsWindows) {
181-
Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository
182-
$pkg = Get-InstalledPSResource $testModuleName
164+
$pkg = Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -PassThru
183165
$pkg.Name | Should -Be $testModuleName
184166
$pkg.InstalledLocation.ToString().Contains("$env:HOME/.local") | Should -Be $true
185167
}
186168

187169
It "Should not install resource that is already installed" {
188-
Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository
189-
$pkg = Get-InstalledPSResource $testModuleName
170+
$pkg = Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -PassThru
190171
$pkg.Name | Should -Be $testModuleName
191172
Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -WarningVariable WarningVar -warningaction SilentlyContinue
192173
$WarningVar | Should -Not -BeNullOrEmpty
193174
}
194175

195176
It "Reinstall resource that is already installed with -Reinstall parameter" {
196-
Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository
197-
$pkg = Get-InstalledPSResource $testModuleName
177+
$pkg = Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -PassThru
198178
$pkg.Name | Should -Be $testModuleName
199179
$pkg.Version | Should -Be "5.0.0"
200-
Install-PSResource -Name $testModuleName -Repository $ADORepoName -Reinstall -TrustRepository
201-
$pkg = Get-InstalledPSResource $testModuleName
180+
$pkg = Install-PSResource -Name $testModuleName -Repository $ADORepoName -Reinstall -TrustRepository -PassThru
202181
$pkg.Name | Should -Be $testModuleName
203182
$pkg.Version | Should -Be "5.0.0"
204183
}
205184

206185
It "Install PSResourceInfo object piped in" {
207-
Find-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $ADORepoName | Install-PSResource -TrustRepository
208-
$res = Get-InstalledPSResource -Name $testModuleName
209-
$res.Name | Should -Be $testModuleName
210-
$res.Version | Should -Be "1.0.0"
211-
}
212-
213-
It "Install module using -PassThru" {
214-
$res = Install-PSResource -Name $testModuleName -Repository $ADORepoName -PassThru -TrustRepository
215-
$res.Name | Should -Contain $testModuleName
186+
$pkg = Find-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $ADORepoName | Install-PSResource -TrustRepository -PassThru
187+
$pkg.Name | Should -Be $testModuleName
188+
$pkg.Version | Should -Be "1.0.0"
216189
}
217190
}
218191

@@ -236,16 +209,14 @@ Describe 'Test Install-PSResource for ADO V3Server scenarios - Manual Validation
236209
# Unix only manual test
237210
# Expected path should be similar to: '/usr/local/share/powershell/Modules'
238211
It "Install resource under AllUsers scope - Unix only" -Skip:(Get-IsWindows) {
239-
Install-PSResource -Name $testModuleName -Repository $TestGalleryName -Scope AllUsers
240-
$pkg = Get-Module $testModuleName -ListAvailable
212+
$pkg = Install-PSResource -Name $testModuleName -Repository $TestGalleryName -Scope AllUsers -PassThru
241213
$pkg.Name | Should -Be $testModuleName
242214
$pkg.Path.Contains("/usr/") | Should -Be $true
243215
}
244216

245217
# This needs to be manually tested due to prompt
246218
It "Install resource that requires accept license without -AcceptLicense flag" {
247-
Install-PSResource -Name $testModuleName2 -Repository $TestGalleryName
248-
$pkg = Get-InstalledPSResource $testModuleName2
219+
$pkg = Install-PSResource -Name $testModuleName2 -Repository $TestGalleryName -PassThru
249220
$pkg.Name | Should -Be $testModuleName2
250221
$pkg.Version | Should -Be "0.0.1.0"
251222
}
@@ -254,9 +225,7 @@ Describe 'Test Install-PSResource for ADO V3Server scenarios - Manual Validation
254225
It "Install resource should prompt 'trust repository' if repository is not trusted" {
255226
Set-PSResourceRepository PoshTestGallery -Trusted:$false
256227

257-
Install-PSResource -Name $testModuleName -Repository $TestGalleryName -confirm:$false
258-
259-
$pkg = Get-Module $testModuleName -ListAvailable
228+
$pkg = Install-PSResource -Name $testModuleName -Repository $TestGalleryName -confirm:$false -PassThru
260229
$pkg.Name | Should -Be $testModuleName
261230

262231
Set-PSResourceRepository PoshTestGallery -Trusted

0 commit comments

Comments
 (0)