Skip to content

Commit 02cc8da

Browse files
authored
Fix bug introduced with PR #383 (#391)
1 parent dade014 commit 02cc8da

File tree

4 files changed

+95
-5
lines changed

4 files changed

+95
-5
lines changed

CHANGELOG.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020

2121
### Changed
2222

23-
- Some unnecessary code was removed from the script `Set-SamplerTaskVariable`
24-
since the functions `Get-SamplerBuiltModuleManifest`, `Get-SamplerBuiltModuleBase`,
25-
and `Get-SamplerModuleRootPath` already handle returning the absolute path.
26-
It also simplified mocking the functions for the unit tests.
2723
- Task `copy_paths_to_choco_staging`
2824
- Now handle property `Exclude` and `Force` correctly.
2925

@@ -35,6 +31,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3531
- Removed one unused line of code.
3632
- Moved one line of code so that code coverage threshold value
3733
will output correctly in some circumstances.
34+
- `Set-SamplerTaskVariable`
35+
- Reverted code that was removed in pull request #383. The code is
36+
necessary because how the commands `Get-BuiltModuleVersion`,
37+
`Get-SamplerBuiltModuleManifest`, `Get-SamplerBuiltModuleBase`, and
38+
`Get-SamplerModuleRootPath` are currently built. The code that was
39+
reverted handles resolving the wildcard (`*`) in the returned paths
40+
from the mentioned commands.
3841

3942
## [0.115.0] - 2022-06-09
4043

Sampler/scripts/Set-SamplerTaskVariable.ps1

+17
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,21 @@ else
176176

177177
$BuiltModuleManifest = Get-SamplerBuiltModuleManifest @GetBuiltModuleManifestParams
178178

179+
# Resolve path to replace '*' with version number.
180+
if ($BuiltModuleManifest)
181+
{
182+
$BuiltModuleManifest = (Get-Item -Path $BuiltModuleManifest -ErrorAction 'SilentlyContinue').FullName
183+
}
184+
179185
"`tBuilt Module Manifest = '$BuiltModuleManifest'"
180186

181187
$BuiltModuleBase = Get-SamplerBuiltModuleBase @GetBuiltModuleManifestParams
182188

189+
# Resolve path to replace '*' with version number.
190+
if ($BuiltModuleBase)
191+
{
192+
$BuiltModuleBase = (Get-Item -Path $BuiltModuleBase -ErrorAction 'SilentlyContinue').FullName
193+
}
183194

184195
"`tBuilt Module Base = '$BuiltModuleBase'"
185196

@@ -199,6 +210,12 @@ else
199210
if ($BuiltModuleManifest)
200211
{
201212
$BuiltModuleRootScriptPath = Get-SamplerModuleRootPath -ModuleManifestPath $BuiltModuleManifest
213+
214+
# Resolve path to replace '*' with version number.
215+
if ($BuiltModuleRootScriptPath)
216+
{
217+
$BuiltModuleRootScriptPath = (Get-Item -Path $BuiltModuleRootScriptPath -ErrorAction 'SilentlyContinue').FullName
218+
}
202219
}
203220

204221
"`tBuilt Module Root Script = '$BuiltModuleRootScriptPath'"

tests/Unit/TestHelpers/MockSetSamplerTaskVariable.ps1

+66
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Mock -CommandName Get-SamplerAbsolutePath -ParameterFilter {
5454
)
5555
}
5656

57+
$script:mockGetSamplerBuiltModuleManifestReturnValue =
58+
5759
Mock -CommandName Get-SamplerBuiltModuleManifest -MockWith {
5860
return (
5961
Join-Path -Path $TestDrive -ChildPath 'output' |
@@ -64,6 +66,28 @@ Mock -CommandName Get-SamplerBuiltModuleManifest -MockWith {
6466
)
6567
}
6668

69+
# This is called after the mock of Get-SamplerBuiltModuleManifest
70+
Mock -CommandName Get-Item -MockWith {
71+
return @{
72+
FullName = (
73+
Join-Path -Path $TestDrive -ChildPath 'output' |
74+
Join-Path -ChildPath 'builtModule' |
75+
Join-Path -ChildPath 'MyModule' |
76+
Join-Path -ChildPath '2.0.0' |
77+
Join-Path -ChildPath 'MyModule.psd1'
78+
)
79+
}
80+
} -ParameterFilter {
81+
# Must be the same path that the mock for Get-SamplerBuiltModuleManifest returns.
82+
$Path -contains (
83+
Join-Path -Path $TestDrive -ChildPath 'output' |
84+
Join-Path -ChildPath 'builtModule' |
85+
Join-Path -ChildPath 'MyModule' |
86+
Join-Path -ChildPath '2.0.0' |
87+
Join-Path -ChildPath 'MyModule.psd1'
88+
)
89+
}
90+
6791
Mock -CommandName Get-SamplerBuiltModuleBase -MockWith {
6892
return (
6993
Join-Path -Path $TestDrive -ChildPath 'output' |
@@ -73,6 +97,26 @@ Mock -CommandName Get-SamplerBuiltModuleBase -MockWith {
7397
)
7498
}
7599

100+
# This is called after the mock of Get-SamplerBuiltModuleBase
101+
Mock -CommandName Get-Item -MockWith {
102+
@{
103+
FullName = (
104+
Join-Path -Path $TestDrive -ChildPath 'output' |
105+
Join-Path -ChildPath 'builtModule' |
106+
Join-Path -ChildPath 'MyModule' |
107+
Join-Path -ChildPath '2.0.0'
108+
)
109+
}
110+
} -ParameterFilter {
111+
# Must be the same path that the mock for Get-SamplerBuiltModuleManifest returns.
112+
$Path -contains (
113+
Join-Path -Path $TestDrive -ChildPath 'output' |
114+
Join-Path -ChildPath 'builtModule' |
115+
Join-Path -ChildPath 'MyModule' |
116+
Join-Path -ChildPath '2.0.0'
117+
)
118+
}
119+
76120
Mock -CommandName Get-BuiltModuleVersion -MockWith {
77121
return '2.0.0'
78122
}
@@ -87,6 +131,28 @@ Mock -CommandName Get-SamplerModuleRootPath -MockWith {
87131
)
88132
}
89133

134+
# This is called after the mock of Get-SamplerModuleRootPath
135+
Mock -CommandName Get-Item -MockWith {
136+
@{
137+
FullName = (
138+
Join-Path -Path $TestDrive -ChildPath 'output' |
139+
Join-Path -ChildPath 'builtModule' |
140+
Join-Path -ChildPath 'MyModule' |
141+
Join-Path -ChildPath '2.0.0' |
142+
Join-Path -ChildPath 'MyModule.psm1'
143+
)
144+
}
145+
} -ParameterFilter {
146+
# Must be the same path that the mock for Get-SamplerBuiltModuleManifest returns.
147+
$Path -contains (
148+
Join-Path -Path $TestDrive -ChildPath 'output' |
149+
Join-Path -ChildPath 'builtModule' |
150+
Join-Path -ChildPath 'MyModule' |
151+
Join-Path -ChildPath '2.0.0' |
152+
Join-Path -ChildPath 'MyModule.psm1'
153+
)
154+
}
155+
90156
# This is only used when calling Set-SamplerTaskVariable with parameter -AsNewBuild
91157
Mock -CommandName Get-BuildVersion -MockWith {
92158
return '2.0.0'

tests/Unit/tasks/Build-Module.ModuleBuilder.build.Tests.ps1

+5-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,11 @@ Describe 'Build_NestedModules_ModuleBuilder' {
415415
It 'Should run the build task without throwing' {
416416
{
417417
Invoke-Build -Task 'Build_NestedModules_ModuleBuilder' -File $taskAlias.Definition @mockTaskParameters
418-
} | Should -Throw -ExpectedMessage '*Path must point to a .psd1 file*'
418+
} | Should -Not -Throw
419+
420+
Should -Invoke -CommandName Update-Metadata -ParameterFilter {
421+
$Value -contains '.{0}{0}Modules{0}DscResource.Common{0}DscResource.Common.psm1' -f $([System.IO.Path]::DirectorySeparatorChar)
422+
} -Exactly -Times 1 -Scope It
419423
}
420424
}
421425
}

0 commit comments

Comments
 (0)