Skip to content

Commit

Permalink
Fix bug introduced with PR #383 (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju authored Aug 1, 2022
1 parent dade014 commit 02cc8da
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 5 deletions.
11 changes: 7 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

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

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

## [0.115.0] - 2022-06-09

Expand Down
17 changes: 17 additions & 0 deletions Sampler/scripts/Set-SamplerTaskVariable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,21 @@ else

$BuiltModuleManifest = Get-SamplerBuiltModuleManifest @GetBuiltModuleManifestParams

# Resolve path to replace '*' with version number.
if ($BuiltModuleManifest)
{
$BuiltModuleManifest = (Get-Item -Path $BuiltModuleManifest -ErrorAction 'SilentlyContinue').FullName
}

"`tBuilt Module Manifest = '$BuiltModuleManifest'"

$BuiltModuleBase = Get-SamplerBuiltModuleBase @GetBuiltModuleManifestParams

# Resolve path to replace '*' with version number.
if ($BuiltModuleBase)
{
$BuiltModuleBase = (Get-Item -Path $BuiltModuleBase -ErrorAction 'SilentlyContinue').FullName
}

"`tBuilt Module Base = '$BuiltModuleBase'"

Expand All @@ -199,6 +210,12 @@ else
if ($BuiltModuleManifest)
{
$BuiltModuleRootScriptPath = Get-SamplerModuleRootPath -ModuleManifestPath $BuiltModuleManifest

# Resolve path to replace '*' with version number.
if ($BuiltModuleRootScriptPath)
{
$BuiltModuleRootScriptPath = (Get-Item -Path $BuiltModuleRootScriptPath -ErrorAction 'SilentlyContinue').FullName
}
}

"`tBuilt Module Root Script = '$BuiltModuleRootScriptPath'"
Expand Down
66 changes: 66 additions & 0 deletions tests/Unit/TestHelpers/MockSetSamplerTaskVariable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Mock -CommandName Get-SamplerAbsolutePath -ParameterFilter {
)
}

$script:mockGetSamplerBuiltModuleManifestReturnValue =

Mock -CommandName Get-SamplerBuiltModuleManifest -MockWith {
return (
Join-Path -Path $TestDrive -ChildPath 'output' |
Expand All @@ -64,6 +66,28 @@ Mock -CommandName Get-SamplerBuiltModuleManifest -MockWith {
)
}

# This is called after the mock of Get-SamplerBuiltModuleManifest
Mock -CommandName Get-Item -MockWith {
return @{
FullName = (
Join-Path -Path $TestDrive -ChildPath 'output' |
Join-Path -ChildPath 'builtModule' |
Join-Path -ChildPath 'MyModule' |
Join-Path -ChildPath '2.0.0' |
Join-Path -ChildPath 'MyModule.psd1'
)
}
} -ParameterFilter {
# Must be the same path that the mock for Get-SamplerBuiltModuleManifest returns.
$Path -contains (
Join-Path -Path $TestDrive -ChildPath 'output' |
Join-Path -ChildPath 'builtModule' |
Join-Path -ChildPath 'MyModule' |
Join-Path -ChildPath '2.0.0' |
Join-Path -ChildPath 'MyModule.psd1'
)
}

Mock -CommandName Get-SamplerBuiltModuleBase -MockWith {
return (
Join-Path -Path $TestDrive -ChildPath 'output' |
Expand All @@ -73,6 +97,26 @@ Mock -CommandName Get-SamplerBuiltModuleBase -MockWith {
)
}

# This is called after the mock of Get-SamplerBuiltModuleBase
Mock -CommandName Get-Item -MockWith {
@{
FullName = (
Join-Path -Path $TestDrive -ChildPath 'output' |
Join-Path -ChildPath 'builtModule' |
Join-Path -ChildPath 'MyModule' |
Join-Path -ChildPath '2.0.0'
)
}
} -ParameterFilter {
# Must be the same path that the mock for Get-SamplerBuiltModuleManifest returns.
$Path -contains (
Join-Path -Path $TestDrive -ChildPath 'output' |
Join-Path -ChildPath 'builtModule' |
Join-Path -ChildPath 'MyModule' |
Join-Path -ChildPath '2.0.0'
)
}

Mock -CommandName Get-BuiltModuleVersion -MockWith {
return '2.0.0'
}
Expand All @@ -87,6 +131,28 @@ Mock -CommandName Get-SamplerModuleRootPath -MockWith {
)
}

# This is called after the mock of Get-SamplerModuleRootPath
Mock -CommandName Get-Item -MockWith {
@{
FullName = (
Join-Path -Path $TestDrive -ChildPath 'output' |
Join-Path -ChildPath 'builtModule' |
Join-Path -ChildPath 'MyModule' |
Join-Path -ChildPath '2.0.0' |
Join-Path -ChildPath 'MyModule.psm1'
)
}
} -ParameterFilter {
# Must be the same path that the mock for Get-SamplerBuiltModuleManifest returns.
$Path -contains (
Join-Path -Path $TestDrive -ChildPath 'output' |
Join-Path -ChildPath 'builtModule' |
Join-Path -ChildPath 'MyModule' |
Join-Path -ChildPath '2.0.0' |
Join-Path -ChildPath 'MyModule.psm1'
)
}

# This is only used when calling Set-SamplerTaskVariable with parameter -AsNewBuild
Mock -CommandName Get-BuildVersion -MockWith {
return '2.0.0'
Expand Down
6 changes: 5 additions & 1 deletion tests/Unit/tasks/Build-Module.ModuleBuilder.build.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,11 @@ Describe 'Build_NestedModules_ModuleBuilder' {
It 'Should run the build task without throwing' {
{
Invoke-Build -Task 'Build_NestedModules_ModuleBuilder' -File $taskAlias.Definition @mockTaskParameters
} | Should -Throw -ExpectedMessage '*Path must point to a .psd1 file*'
} | Should -Not -Throw

Should -Invoke -CommandName Update-Metadata -ParameterFilter {
$Value -contains '.{0}{0}Modules{0}DscResource.Common{0}DscResource.Common.psm1' -f $([System.IO.Path]::DirectorySeparatorChar)
} -Exactly -Times 1 -Scope It
}
}
}
Expand Down

0 comments on commit 02cc8da

Please sign in to comment.