Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New-DscResourcePowerShellHelp: Case-insensitive when it looks for the README.md #43

Merged
merged 4 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- New-DscResourcePowerShellHelp
- Fixed so the cmdlet is case-insensitive when it looks for the README.md
file in a resource source folder ([issue #42](https://github.com/dsccommunity/DscResource.DocGenerator/issues/42)).

## [0.7.0] - 2020-07-08

### Added
Expand All @@ -20,7 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update README.md with the correct build task name; 'Publish_GitHub_Wiki_Content'.
- Fixed wiki generation to correctly describe embedded instances in
parameters and made new section for each embedded instances with
their parameters ([issue #37](https://github.com/dsccommunity/DscResource.DocGenerator/issues/37))
their parameters ([issue #37](https://github.com/dsccommunity/DscResource.DocGenerator/issues/37)).

### Changed

Expand Down
10 changes: 8 additions & 2 deletions source/Public/New-DscResourcePowerShellHelp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,16 @@ function New-DscResourcePowerShellHelp
-and ($null -ne $_.FriendlyName)
}

$descriptionPath = Join-Path -Path $mofSchema.DirectoryName -ChildPath 'readme.md'
# This is a workaround for issue #42.
$readMeFile = Get-ChildItem -Path $mofSchema.DirectoryName -ErrorAction 'SilentlyContinue' |
Where-Object -FilterScript {
$_.Name -like 'readme.md'
}

if (Test-Path -Path $descriptionPath)
if ($readMeFile)
{
$descriptionPath = $readMeFile.FullName

Write-Verbose -Message ($script:localizedData.GenerateHelpDocumentMessage -f $result.FriendlyName)

$output = ".NAME`r`n"
Expand Down
91 changes: 62 additions & 29 deletions tests/unit/public/New-DscResourcePowerShellHelp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Configuration Example
}'

# General mock values
$script:mockReadmePath = Join-Path -Path $script:mockSchemaFolder -ChildPath 'readme.md'
$script:mockReadmePath = $script:mockSchemaFolder
$script:mockOutputFile = Join-Path -Path $script:mockOutputPath -ChildPath "$($script:mockResourceName).md"
$script:mockSavePath = Join-Path -Path $script:mockModulePath -ChildPath "DscResources\$($script:mockResourceName)\en-US\about_$($script:mockResourceName).help.txt"
$script:mockOutputSavePath = Join-Path -Path $script:mockOutputPath -ChildPath "about_$($script:mockResourceName).help.txt"
Expand Down Expand Up @@ -212,12 +212,12 @@ Configuration Example
$Filename -eq $script:mockSchemaFilePath
}

$script:getTestPathReadme_parameterFilter = {
$script:getChildItemReadme_parameterFilter = {
$Path -eq $script:mockReadmePath
}

$script:getContentReadme_parameterFilter = {
$Path -eq $script:mockReadmePath
$Path -eq (Join-Path -Path $script:mockReadmePath -ChildPath 'README.md')
}

$script:getDscResourceHelpExampleContent_parameterFilter = {
Expand Down Expand Up @@ -309,9 +309,8 @@ Configuration Example
-MockWith { $script:mockGetMofSchemaObject }

Mock `
-CommandName Test-Path `
-ParameterFilter $script:getTestPathReadme_parameterFilter `
-MockWith { $false }
-CommandName Get-ChildItem `
-ParameterFilter $script:getChildItemReadme_parameterFilter

Mock `
-CommandName Out-File `
Expand Down Expand Up @@ -357,9 +356,15 @@ Configuration Example
-MockWith { $script:mockGetMofSchemaObject }

Mock `
-CommandName Test-Path `
-ParameterFilter $script:getTestPathReadme_parameterFilter `
-MockWith { $true }
-CommandName Get-ChildItem `
-ParameterFilter $script:getChildItemReadme_parameterFilter `
-MockWith {
return [PSCustomObject] @{
# This is intentionally using the upper-case 'README.md'.
Name = 'README.md'
FullName = Join-Path -Path $script:mockReadmePath -ChildPath 'README.md'
}
}

Mock `
-CommandName Get-Content `
Expand Down Expand Up @@ -392,6 +397,11 @@ Configuration Example
-ParameterFilter $script:getChildItemSchema_parameterFilter `
-Exactly -Times 1

Assert-MockCalled `
-CommandName Get-ChildItem `
-ParameterFilter $script:getChildItemReadme_parameterFilter `
-Exactly -Times 1

Assert-MockCalled `
-CommandName Get-Content `
-ParameterFilter $script:getContentReadme_parameterFilter `
Expand Down Expand Up @@ -437,9 +447,15 @@ Configuration Example
-MockWith { $script:mockGetMofSchemaObject }

Mock `
-CommandName Test-Path `
-ParameterFilter $script:getTestPathReadme_parameterFilter `
-MockWith { $true }
-CommandName Get-ChildItem `
-ParameterFilter $script:getChildItemReadme_parameterFilter `
-MockWith {
return [PSCustomObject] @{
# This is intentionally using the upper-case 'README.md'.
Name = 'README.md'
FullName = Join-Path -Path $script:mockReadmePath -ChildPath 'README.md'
}
}

Mock `
-CommandName Get-Content `
Expand Down Expand Up @@ -491,8 +507,8 @@ Configuration Example
-Exactly -Times 1

Assert-MockCalled `
-CommandName Test-Path `
-ParameterFilter $script:getTestPathReadme_parameterFilter `
-CommandName Get-ChildItem `
-ParameterFilter $script:getChildItemReadme_parameterFilter `
-Exactly -Times 1

Assert-MockCalled `
Expand Down Expand Up @@ -535,9 +551,15 @@ Configuration Example
-MockWith { $script:mockGetMofSchemaObject }

Mock `
-CommandName Test-Path `
-ParameterFilter $script:getTestPathReadme_parameterFilter `
-MockWith { $true }
-CommandName Get-ChildItem `
-ParameterFilter $script:getChildItemReadme_parameterFilter `
-MockWith {
return [PSCustomObject] @{
# This is intentionally using the upper-case 'README.md'.
Name = 'README.md'
FullName = Join-Path -Path $script:mockReadmePath -ChildPath 'README.md'
}
}

Mock `
-CommandName Get-Content `
Expand Down Expand Up @@ -589,8 +611,8 @@ Configuration Example
-Exactly -Times 1

Assert-MockCalled `
-CommandName Test-Path `
-ParameterFilter $script:getTestPathReadme_parameterFilter `
-CommandName Get-ChildItem `
-ParameterFilter $script:getChildItemReadme_parameterFilter `
-Exactly -Times 1

Assert-MockCalled `
Expand Down Expand Up @@ -633,9 +655,15 @@ Configuration Example
-MockWith { $script:mockGetMofSchemaObject }

Mock `
-CommandName Test-Path `
-ParameterFilter $script:getTestPathReadme_parameterFilter `
-MockWith { $true }
-CommandName Get-ChildItem `
-ParameterFilter $script:getChildItemReadme_parameterFilter `
-MockWith {
return [PSCustomObject] @{
# This is intentionally using the lower-case 'readme.md'.
Name = 'readme.md'
FullName = Join-Path -Path $script:mockReadmePath -ChildPath 'readme.md'
}
}

Mock `
-CommandName Get-Content `
Expand Down Expand Up @@ -687,8 +715,8 @@ Configuration Example
-Exactly -Times 1

Assert-MockCalled `
-CommandName Test-Path `
-ParameterFilter $script:getTestPathReadme_parameterFilter `
-CommandName Get-ChildItem `
-ParameterFilter $script:getChildItemReadme_parameterFilter `
-Exactly -Times 1

Assert-MockCalled `
Expand Down Expand Up @@ -774,9 +802,14 @@ Configuration Example
-MockWith { $script:mockGetMofSchemaObject }

Mock `
-CommandName Test-Path `
-ParameterFilter $script:getTestPathReadme_parameterFilter `
-MockWith { $true }
-CommandName Get-ChildItem `
-ParameterFilter $script:getChildItemReadme_parameterFilter `
-MockWith {
return [PSCustomObject] @{
Name = 'README.md'
FullName = Join-Path -Path $script:mockReadmePath -ChildPath 'README.md'
}
}

Mock `
-CommandName Get-Content `
Expand Down Expand Up @@ -833,8 +866,8 @@ Configuration Example
-Exactly -Times 1

Assert-MockCalled `
-CommandName Test-Path `
-ParameterFilter $script:getTestPathReadme_parameterFilter `
-CommandName Get-ChildItem `
-ParameterFilter $script:getChildItemReadme_parameterFilter `
-Exactly -Times 1

Assert-MockCalled `
Expand Down