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

Commit e959c32

Browse files
committed
Merge branch 'WikiPages-Update' of https://github.com/X-Guardian/DscResource.Tests into WikiPages-Update
2 parents d312598 + 8f179c0 commit e959c32

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
@@ -1539,6 +1539,7 @@ Configuration Example
15391539
$script:mockReadmePath = Join-Path -Path $script:mockSchemaFolder -ChildPath 'readme.md'
15401540
$script:mockOutputFile = Join-Path -Path $script:mockOutputPath -ChildPath "$($script:mockResourceName).md"
15411541
$script:mockSavePath = Join-Path -Path $script:mockModulePath -ChildPath "DscResources\$($script:mockResourceName)\en-US\about_$($script:mockResourceName).help.txt"
1542+
$script:mockOutputSavePath = Join-Path -Path $script:mockOutputPath -ChildPath "about_$($script:mockResourceName).help.txt"
15421543
$script:mockGetContentReadme = '# Description
15431544
15441545
The description of the resource.'
@@ -1610,6 +1611,10 @@ Configuration Example
16101611
$InputObject -eq $script:mockPowerShellHelpOutput -and
16111612
$FilePath -eq $script:mockSavePath
16121613
}
1614+
$script:outFileOutputInputObject_parameterFilter = {
1615+
$InputObject -eq $script:mockPowerShellHelpOutput -and
1616+
$FilePath -eq $script:mockOutputSavePath
1617+
}
16131618
$script:writeWarningDescription_parameterFilter = {
16141619
$Message -eq ($script:localizedData.NoDescriptionFileFoundWarning -f $mockResourceName)
16151620
}
@@ -1620,6 +1625,10 @@ Configuration Example
16201625
$script:newDscResourcePowerShellHelp_parameters = @{
16211626
ModulePath = $script:mockModulePath
16221627
}
1628+
$script:newDscResourcePowerShellHelpOutput_parameters = @{
1629+
ModulePath = $script:mockModulePath
1630+
OutputPath = $script:mockOutputPath
1631+
}
16231632

16241633
Context 'When there is no schemas found in the module folder' {
16251634
BeforeAll {
@@ -1776,7 +1785,7 @@ Configuration Example
17761785
}
17771786
}
17781787

1779-
Context 'When there is one schema found in the module folder and one example using .EXAMPLE' {
1788+
Context 'When there is one schema found in the module folder and one example using .EXAMPLE and the OutputPath is specified' {
17801789
BeforeAll {
17811790
Mock `
17821791
-CommandName Get-ChildItem `
@@ -1809,8 +1818,105 @@ Configuration Example
18091818
-MockWith { $script:mockExampleContent }
18101819

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

18151921
Mock `
18161922
-CommandName Write-Warning `
@@ -1848,7 +1954,7 @@ Configuration Example
18481954
-ParameterFilter $script:getTestPathReadme_parameterFilter `
18491955
-Exactly -Times 1
18501956

1851-
Assert-MockCalled `
1957+
Assert-MockCalled `
18521958
-CommandName Get-Content `
18531959
-ParameterFilter $script:getContentReadme_parameterFilter `
18541960
-Exactly -Times 1

0 commit comments

Comments
 (0)