Skip to content
This repository was archived by the owner on Feb 24, 2021. It is now read-only.

Commit 8f179c0

Browse files
authored
Merge branch 'dev' into WikiPages-Update
2 parents e7a403b + 85e6783 commit 8f179c0

File tree

3 files changed

+135
-13
lines changed

3 files changed

+135
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
[issue #227](https://github.com/PowerShell/DscResource.Tests/issues/227) and
5959
[issue #228](https://github.com/PowerShell/DscResource.Tests/issues/228)).
6060
- Update New-DscResourcePowerShellHelp to output the PowerShell help files to
61+
to the relevant DSC resource GitHub Wiki ([issue #142](https://github.com/PowerShell/DscResource.Tests/issues/142)).
62+
- Update New-DscResourcePowerShellHelp to optionally output the PowerShell help files to
6163
the resource specific path and fix the example processing.
6264
- Added processing to `Test-PublishMetaData` for the InvalidGUID error from Test-ScriptFileInfo
6365
([issue #330](https://github.com/PowerShell/DscResource.Tests/issues/330)).

DscResource.DocumentationHelper/PowerShellHelp.psm1

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,28 @@ $script:localizedData = Get-LocalizedData -ModuleName $moduleName -ModuleRoot $P
2525

2626
<#
2727
.SYNOPSIS
28-
2928
New-DscResourcePowerShellHelp generates PowerShell compatible help files for a DSC
3029
resource module
3130
3231
.DESCRIPTION
33-
3432
The New-DscResourcePowerShellHelp cmdlet will review all of the MOF based resources
35-
in a specified module directory and will inject PowerShell help files for each resource
36-
in to the resource's subdirectory. These help files include details on the property types for
37-
each resource, as well as a text description and examples where they exist.
38-
a README.md with a text description must exist in the resource's subdirectory for the
33+
in a specified module directory and will inject PowerShell help files for each resource.
34+
These help files include details on the property types for each resource, as well as a text
35+
description and examples where they exist.
36+
37+
The help files are output to the OutputPath directory if specified, or if not, they are
38+
output to the releveant resource's 'en-US' directory.
39+
40+
A README.md with a text description must exist in the resource's subdirectory for the
3941
help file to be generated.
42+
4043
These help files can then be read by passing the name of the resource as a parameter to Get-Help.
4144
4245
.PARAMETER ModulePath
43-
4446
The path to the root of the DSC resource module (where the PSD1 file is found, not the folder for
4547
each individual DSC resource)
4648
4749
.EXAMPLE
48-
4950
This example shows how to generate help for a specific module
5051
5152
New-DscResourcePowerShellHelp -ModulePath C:\repos\SharePointdsc
@@ -58,7 +59,11 @@ function New-DscResourcePowerShellHelp
5859
(
5960
[parameter(Mandatory = $true)]
6061
[System.String]
61-
$ModulePath
62+
$ModulePath,
63+
64+
[parameter()]
65+
[System.String]
66+
$OutputPath
6267
)
6368

6469
Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'MofHelper.psm1') -Verbose:$false
@@ -135,7 +140,16 @@ function New-DscResourcePowerShellHelp
135140
Write-Warning -Message ($script:localizedData.NoExampleFileFoundWarning -f $result.FriendlyName)
136141
}
137142

138-
$savePath = Join-Path -Path $mofFileObject.DirectoryName -ChildPath "\en-US\about_$($result.FriendlyName).help.txt"
143+
# Output to $OutputPath if specified or the resource 'en-US' directory if not.
144+
$outputFileName = "about_$($result.FriendlyName).help.txt"
145+
if ($OutputPath)
146+
{
147+
$savePath = Join-Path -Path $OutputPath -ChildPath $outputFileName
148+
}
149+
else
150+
{
151+
$savePath = Join-Path -Path $mofFileObject.DirectoryName -ChildPath 'en-US' | Join-Path -ChildPath $outputFileName
152+
}
139153
Write-Verbose -Message ($script:localizedData.OutputHelpDocumentMessage -f $savePath)
140154
$output | Out-File -FilePath $savePath -Encoding utf8 -Force
141155
}

Tests/Unit/DscResource.DocumentationHelper.Tests.ps1

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,7 @@ Configuration Example
15381538
$script:mockReadmePath = Join-Path -Path $script:mockSchemaFolder -ChildPath 'readme.md'
15391539
$script:mockOutputFile = Join-Path -Path $script:mockOutputPath -ChildPath "$($script:mockResourceName).md"
15401540
$script:mockSavePath = Join-Path -Path $script:mockModulePath -ChildPath "DscResources\$($script:mockResourceName)\en-US\about_$($script:mockResourceName).help.txt"
1541+
$script:mockOutputSavePath = Join-Path -Path $script:mockOutputPath -ChildPath "about_$($script:mockResourceName).help.txt"
15411542
$script:mockGetContentReadme = '# Description
15421543
15431544
The description of the resource.'
@@ -1609,6 +1610,10 @@ Configuration Example
16091610
$InputObject -eq $script:mockPowerShellHelpOutput -and
16101611
$FilePath -eq $script:mockSavePath
16111612
}
1613+
$script:outFileOutputInputObject_parameterFilter = {
1614+
$InputObject -eq $script:mockPowerShellHelpOutput -and
1615+
$FilePath -eq $script:mockOutputSavePath
1616+
}
16121617
$script:writeWarningDescription_parameterFilter = {
16131618
$Message -eq ($script:localizedData.NoDescriptionFileFoundWarning -f $mockResourceName)
16141619
}
@@ -1619,6 +1624,10 @@ Configuration Example
16191624
$script:newDscResourcePowerShellHelp_parameters = @{
16201625
ModulePath = $script:mockModulePath
16211626
}
1627+
$script:newDscResourcePowerShellHelpOutput_parameters = @{
1628+
ModulePath = $script:mockModulePath
1629+
OutputPath = $script:mockOutputPath
1630+
}
16221631

16231632
Context 'When there is no schemas found in the module folder' {
16241633
BeforeAll {
@@ -1775,7 +1784,7 @@ Configuration Example
17751784
}
17761785
}
17771786

1778-
Context 'When there is one schema found in the module folder and one example using .EXAMPLE' {
1787+
Context 'When there is one schema found in the module folder and one example using .EXAMPLE and the OutputPath is specified' {
17791788
BeforeAll {
17801789
Mock `
17811790
-CommandName Get-ChildItem `
@@ -1808,8 +1817,105 @@ Configuration Example
18081817
-MockWith { $script:mockExampleContent }
18091818

18101819
Mock `
1820+
-CommandName Out-File
1821+
1822+
Mock `
1823+
-CommandName Write-Warning `
1824+
-ParameterFilter $script:writeWarningExample_parameterFilter
1825+
1826+
Mock `
1827+
-CommandName Write-Warning `
1828+
-ParameterFilter $script:writeWarningDescription_parameterFilter
1829+
}
1830+
1831+
It 'Should not throw an exception' {
1832+
{ New-DscResourcePowerShellHelp @script:newDscResourcePowerShellHelpOutput_parameters } | Should -Not -Throw
1833+
}
1834+
1835+
It 'Should produce the correct output' {
1836+
Assert-MockCalled `
18111837
-CommandName Out-File `
1812-
-ParameterFilter $script:outFile_parameterFilter
1838+
-ParameterFilter $script:outFileOutputInputObject_parameterFilter `
1839+
-Exactly -Times 1
1840+
}
1841+
1842+
It 'Should call the expected mocks ' {
1843+
Assert-MockCalled `
1844+
-CommandName Get-ChildItem `
1845+
-ParameterFilter $script:getChildItemSchema_parameterFilter `
1846+
-Exactly -Times 1
1847+
1848+
Assert-MockCalled `
1849+
-CommandName Get-MofSchemaObject `
1850+
-ParameterFilter $script:getMofSchemaObjectSchema_parameterfilter `
1851+
-Exactly -Times 1
1852+
1853+
Assert-MockCalled `
1854+
-CommandName Test-Path `
1855+
-ParameterFilter $script:getTestPathReadme_parameterFilter `
1856+
-Exactly -Times 1
1857+
1858+
Assert-MockCalled `
1859+
-CommandName Get-Content `
1860+
-ParameterFilter $script:getContentReadme_parameterFilter `
1861+
-Exactly -Times 1
1862+
1863+
Assert-MockCalled `
1864+
-CommandName Get-ChildItem `
1865+
-ParameterFilter $script:getChildItemExample_parameterFilter `
1866+
-Exactly -Times 1
1867+
1868+
Assert-MockCalled `
1869+
-CommandName Get-DscResourceHelpExampleContent `
1870+
-ParameterFilter $script:getDscResourceHelpExampleContent_parameterFilter `
1871+
-Exactly -Times 1
1872+
1873+
Assert-MockCalled `
1874+
-CommandName Write-Warning `
1875+
-ParameterFilter $script:writeWarningExample_parameterFilter `
1876+
-Exactly -Times 0
1877+
1878+
Assert-MockCalled `
1879+
-CommandName Write-Warning `
1880+
-ParameterFilter $script:writeWarningDescription_parameterFilter `
1881+
-Exactly -Times 0
1882+
}
1883+
}
1884+
1885+
Context 'When there is one schema found in the module folder and one example using .EXAMPLE and the OutputPath is not specified' {
1886+
BeforeAll {
1887+
Mock `
1888+
-CommandName Get-ChildItem `
1889+
-ParameterFilter $script:getChildItemSchema_parameterFilter `
1890+
-MockWith { $script:mockSchemaFiles }
1891+
1892+
Mock `
1893+
-CommandName Get-MofSchemaObject `
1894+
-ParameterFilter $script:getMofSchemaObjectSchema_parameterfilter `
1895+
-MockWith { $script:mockGetMofSchemaObject }
1896+
1897+
Mock `
1898+
-CommandName Test-Path `
1899+
-ParameterFilter $script:getTestPathReadme_parameterFilter `
1900+
-MockWith { $true }
1901+
1902+
Mock `
1903+
-CommandName Get-Content `
1904+
-ParameterFilter $script:getContentReadme_parameterFilter `
1905+
-MockWith { $script:mockGetContentReadme }
1906+
1907+
Mock `
1908+
-CommandName Get-ChildItem `
1909+
-ParameterFilter $script:getChildItemExample_parameterFilter `
1910+
-MockWith { $script:mockExampleFiles }
1911+
1912+
Mock `
1913+
-CommandName Get-DscResourceHelpExampleContent `
1914+
-ParameterFilter $script:getDscResourceHelpExampleContent_parameterFilter `
1915+
-MockWith { $script:mockExampleContent }
1916+
1917+
Mock `
1918+
-CommandName Out-File
18131919

18141920
Mock `
18151921
-CommandName Write-Warning `
@@ -1847,7 +1953,7 @@ Configuration Example
18471953
-ParameterFilter $script:getTestPathReadme_parameterFilter `
18481954
-Exactly -Times 1
18491955

1850-
Assert-MockCalled `
1956+
Assert-MockCalled `
18511957
-CommandName Get-Content `
18521958
-ParameterFilter $script:getContentReadme_parameterFilter `
18531959
-Exactly -Times 1

0 commit comments

Comments
 (0)