@@ -27,8 +27,7 @@ Describe "Get-Module -ListAvailable" -Tags "CI" {
27
27
New-Item - ItemType File - Path " $testdrive \Modules\Az\Az.psm1" > $null
28
28
29
29
$fullyQualifiedPathTestCases = @ (
30
- # The current behaviour in PowerShell is that version gets ignored when using Get-Module -FullyQualifiedName with a path
31
- @ { ModPath = " $TestDrive /Modules\Foo" ; Name = ' Foo' ; Version = ' 2.0' ; Count = 2 }
30
+ @ { ModPath = " $TestDrive /Modules\Foo" ; Name = ' Foo' ; Version = ' 2.0' ; Count = 1 }
32
31
@ { ModPath = " $TestDrive \Modules/Foo\1.1/Foo.psd1" ; Name = ' Foo' ; Version = ' 1.1' ; Count = 1 }
33
32
@ { ModPath = " $TestDrive \Modules/Bar.psd1" ; Name = ' Bar' ; Version = ' 0.0' ; Count = 1 }
34
33
@ { ModPath = " $TestDrive \Modules\Zoo\Too\Zoo.psm1" ; Name = ' Zoo' ; Version = ' 0.0' ; Count = 1 }
@@ -225,3 +224,101 @@ Describe "Get-Module -ListAvailable" -Tags "CI" {
225
224
}
226
225
}
227
226
}
227
+
228
+ Describe ' Get-Module -ListAvailable with path' - Tags " CI" {
229
+ BeforeAll {
230
+ $moduleName = ' Banana'
231
+ $modulePath = Join-Path $TestDrive $moduleName
232
+ $v1 = ' 1.2.3'
233
+ $v2 = ' 4.8.3'
234
+ $v1DirPath = Join-Path $modulePath $v1
235
+ $v2DirPath = Join-Path $modulePath $v2
236
+ $manifestV1Path = Join-Path $v1DirPath " $moduleName .psd1"
237
+ $manifestV2Path = Join-Path $v2DirPath " $moduleName .psd1"
238
+
239
+ New-Item - ItemType Directory $modulePath
240
+ New-Item - ItemType Directory - Path $v1DirPath
241
+ New-Item - ItemType Directory - Path $v2DirPath
242
+ New-ModuleManifest - Path $manifestV1Path - ModuleVersion $v1
243
+ New-ModuleManifest - Path $manifestV2Path - ModuleVersion $v2
244
+ }
245
+
246
+ It " Gets all versions by path" {
247
+ $modules = Get-Module - ListAvailable $modulePath | Sort-Object - Property Version
248
+
249
+ $modules | Should - HaveCount 2
250
+ $modules [0 ].Name | Should - BeExactly $moduleName
251
+ $modules [0 ].Path | Should - BeExactly $manifestV1Path
252
+ $modules [0 ].Version | Should - Be $v1
253
+ $modules [1 ].Name | Should - BeExactly $moduleName
254
+ $modules [1 ].Path | Should - BeExactly $manifestV2Path
255
+ $modules [1 ].Version | Should - Be $v2
256
+ }
257
+
258
+ It " Gets all versions by FullyQualifiedName with path with lower version" {
259
+ $modules = Get-Module - ListAvailable - FullyQualifiedName @ { ModuleName = $modulePath ; ModuleVersion = ' 0.0' } | Sort-Object - Property Version
260
+
261
+ $modules | Should - HaveCount 2
262
+ $modules [0 ].Name | Should - BeExactly $moduleName
263
+ $modules [0 ].Path | Should - BeExactly $manifestV1Path
264
+ $modules [0 ].Version | Should - Be $v1
265
+ $modules [1 ].Name | Should - BeExactly $moduleName
266
+ $modules [1 ].Path | Should - BeExactly $manifestV2Path
267
+ $modules [1 ].Version | Should - Be $v2
268
+ }
269
+
270
+ It " Gets high version by FullyQualifiedName with path with high version" {
271
+ $modules = Get-Module - ListAvailable - FullyQualifiedName @ { ModuleName = $modulePath ; ModuleVersion = ' 2.0' } | Sort-Object - Property Version
272
+
273
+ $modules | Should - HaveCount 1
274
+ $modules [0 ].Name | Should - BeExactly $moduleName
275
+ $modules [0 ].Path | Should - BeExactly $manifestV2Path
276
+ $modules [0 ].Version | Should - Be $v2
277
+ }
278
+
279
+ It " Gets low version by FullyQualifiedName with path with low maximum version" {
280
+ $modules = Get-Module - ListAvailable - FullyQualifiedName @ { ModuleName = $modulePath ; MaximumVersion = ' 2.0' } | Sort-Object - Property Version
281
+
282
+ $modules | Should - HaveCount 1
283
+ $modules [0 ].Name | Should - BeExactly $moduleName
284
+ $modules [0 ].Path | Should - BeExactly $manifestV1Path
285
+ $modules [0 ].Version | Should - Be $v1
286
+ }
287
+
288
+ It " Gets low version by FullyQualifiedName with path with low maximum version and version" {
289
+ $modules = Get-Module - ListAvailable - FullyQualifiedName @ { ModuleName = $modulePath ; MaximumVersion = ' 2.0' ; ModuleVersion = ' 1.0' } | Sort-Object - Property Version
290
+
291
+ $modules | Should - HaveCount 1
292
+ $modules [0 ].Name | Should - BeExactly $moduleName
293
+ $modules [0 ].Path | Should - BeExactly $manifestV1Path
294
+ $modules [0 ].Version | Should - Be $v1
295
+ }
296
+
297
+ It " Gets correct version by FullyQualifiedName with path with required version" - TestCases @ (
298
+ @ { Version = $v1 }
299
+ @ { Version = $v2 }
300
+ ) {
301
+ param ([version ]$Version )
302
+
303
+ switch ($Version )
304
+ {
305
+ $v1
306
+ {
307
+ $expectedPath = $manifestV1Path
308
+ break
309
+ }
310
+
311
+ $v2
312
+ {
313
+ $expectedPath = $manifestV2Path
314
+ }
315
+ }
316
+
317
+ $modules = Get-Module - ListAvailable - FullyQualifiedName @ { ModuleName = $modulePath ; RequiredVersion = $Version }
318
+
319
+ $modules | Should - HaveCount 1
320
+ $modules [0 ].Name | Should - BeExactly $moduleName
321
+ $modules [0 ].Path | Should - BeExactly $expectedPath
322
+ $modules [0 ].Version | Should - Be $Version
323
+ }
324
+ }
0 commit comments