@@ -14,6 +14,7 @@ Describe 'Test Find-PSResource for local repositories' -tags 'CI' {
1414 $localUNCRepo = ' psgettestlocal3'
1515 $testModuleName = " test_local_mod"
1616 $testModuleName2 = " test_local_mod2"
17+ $similarTestModuleName = " test_local_mod.similar"
1718 $commandName = " cmd1"
1819 $dscResourceName = " dsc1"
1920 $prereleaseLabel = " "
@@ -31,6 +32,9 @@ Describe 'Test Find-PSResource for local repositories' -tags 'CI' {
3132
3233 New-TestModule - moduleName $testModuleName2 - repoName $localRepo - packageVersion " 5.0.0" - prereleaseLabel " " - tags $tagsEscaped
3334 New-TestModule - moduleName $testModuleName2 - repoName $localRepo - packageVersion " 5.2.5" - prereleaseLabel $prereleaseLabel - tags $tagsEscaped
35+
36+ New-TestModule - moduleName $similarTestModuleName - repoName $localRepo - packageVersion " 4.0.0" - prereleaseLabel " " - tags $tagsEscaped
37+ New-TestModule - moduleName $similarTestModuleName - repoName $localRepo - packageVersion " 5.0.0" - prereleaseLabel " " - tags $tagsEscaped
3438 }
3539
3640 AfterAll {
@@ -74,13 +78,25 @@ Describe 'Test Find-PSResource for local repositories' -tags 'CI' {
7478 }
7579
7680 It " should not find resource given nonexistant Name" {
81+ # FindName()
7782 $res = Find-PSResource - Name NonExistantModule - Repository $localRepo - ErrorVariable err - ErrorAction SilentlyContinue
7883 $res | Should - BeNullOrEmpty
7984 $err.Count | Should -Not - Be 0
8085 $err [0 ].FullyQualifiedErrorId | Should - BeExactly " PackageNotFound,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource"
8186 $res | Should - BeNullOrEmpty
8287 }
8388
89+ It " find resource given specific Name when another package with similar name (with period) exists" {
90+ # FindName()
91+ $res = Find-PSResource - Name $testModuleName - Repository $localRepo
92+ $res.Name | Should - Be $testModuleName
93+ $res.Version | Should - Be " 5.0.0"
94+
95+ $res = Find-PSResource - Name $similarTestModuleName - Repository $localRepo
96+ $res.Name | Should - Be $similarTestModuleName
97+ $res.Version | Should - Be " 5.0.0"
98+ }
99+
84100 It " find resource(s) given wildcard Name" {
85101 # FindNameGlobbing
86102 $res = Find-PSResource - Name " test_local_*" - Repository $localRepo
@@ -129,6 +145,22 @@ Describe 'Test Find-PSResource for local repositories' -tags 'CI' {
129145 $resPrerelease.Prerelease | Should - Be " alpha001"
130146 }
131147
148+ It " find resource given specific Name when another package with similar name (with period) exists" {
149+ # FindVersion()
150+ # Package $testModuleName version 4.0.0 does not exist
151+ # previously if Find-PSResource -Version against local repo did not find that package's version it kept looking at
152+ # similar named packages and would fault. This test is to ensure only the specified package and its version is checked
153+ $res = Find-PSResource - Name $testModuleName - Version " 4.0.0" - Repository $localRepo
154+ $res | Should - BeNullOrEmpty
155+ $err.Count | Should -Not - Be 0
156+ $err [0 ].FullyQualifiedErrorId | Should - BeExactly " PackageNotFound,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource"
157+ $res | Should - BeNullOrEmpty
158+
159+ $res = Find-PSResource - Name $similarTestModuleName - Version " 4.0.0" - Repository $localRepo
160+ $res.Name | Should - Be $similarTestModuleName
161+ $res.Version | Should - Be " 4.0.0"
162+ }
163+
132164 It " find resources, including Prerelease version resources, when given Prerelease parameter" {
133165 # FindVersionGlobbing()
134166 $resWithoutPrerelease = Find-PSResource - Name $testModuleName - Version " *" - Repository $localRepo
0 commit comments