Skip to content

Commit

Permalink
Merge pull request #32 from ykuijs/master
Browse files Browse the repository at this point in the history
Fixed issue with Test-Path casing
  • Loading branch information
PlagueHO authored Jun 16, 2020
2 parents ac19bed + 2b04b08 commit d289c8b
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 28 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fixed issue with `New-DscResourceWikiPage` where Test-Path was case sensitive
on Linux machines and therefore didn't find some Readme.md files.

## [0.5.1] - 2020-05-01

### Added
Expand Down
2 changes: 1 addition & 1 deletion RequiredModules.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

InvokeBuild = 'latest'
PSScriptAnalyzer = 'latest'
Pester = 'latest'
Pester = '4.10.1'
Plaster = 'latest'
ModuleBuilder = '1.0.0'
Sampler = 'latest'
Expand Down
10 changes: 7 additions & 3 deletions source/Public/New-DscResourceWikiPage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ function New-DscResourceWikiPage
-and ($null -ne $_.FriendlyName)
}

$descriptionPath = Join-Path -Path $mofSchemaFile.DirectoryName -ChildPath 'readme.md'
[System.Array]$readmeFile = Get-ChildItem -Path $mofSchemaFile.DirectoryName | Where-Object -FilterScript { $_.Name -like 'readme.md' }

if (Test-Path -Path $descriptionPath)
if ($readmeFile.Count -eq 1)
{
Write-Verbose -Message ($script:localizedData.GenerateWikiPageMessage -f $mofSchema.FriendlyName)

Expand Down Expand Up @@ -91,7 +91,7 @@ function New-DscResourceWikiPage
$null = $output.AppendLine('|')
}

$descriptionContent = Get-Content -Path $descriptionPath -Raw
$descriptionContent = Get-Content -Path $readmeFile.FullName -Raw

# Change the description H1 header to an H2
$descriptionContent = $descriptionContent -replace '# Description', '## Description'
Expand Down Expand Up @@ -135,6 +135,10 @@ function New-DscResourceWikiPage
-Encoding utf8 `
-Force
}
elseif ($readmeFile.Count -gt 1)
{
Write-Warning -Message ($script:localizedData.MultipleDescriptionFileFoundWarning -f $mofSchema.FriendlyName, $readmeFile.Count)
}
else
{
Write-Warning -Message ($script:localizedData.NoDescriptionFileFoundWarning -f $mofSchema.FriendlyName)
Expand Down
15 changes: 8 additions & 7 deletions source/en-US/DscResource.DocGenerator.strings.psd1
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# English strings
ConvertFrom-StringData @'
FoundMofFilesMessage = Found {0} MOF files in path '{1}'.
GenerateHelpDocumentMessage = Generating help document for '{0}'.
OutputHelpDocumentMessage = Outputting help document to '{0}'.
GenerateWikiPageMessage = Generating wiki page for '{0}'.
OutputWikiPageMessage = Outputting wiki page to '{0}'.
NoDescriptionFileFoundWarning = No README.md description file found for '{0}', skipping.
NoExampleFileFoundWarning = No Example files found for resource '{0}'.
FoundMofFilesMessage = Found {0} MOF files in path '{1}'.
GenerateHelpDocumentMessage = Generating help document for '{0}'.
OutputHelpDocumentMessage = Outputting help document to '{0}'.
GenerateWikiPageMessage = Generating wiki page for '{0}'.
OutputWikiPageMessage = Outputting wiki page to '{0}'.
NoDescriptionFileFoundWarning = No README.md description file found for '{0}', skipping.
MultipleDescriptionFileFoundWarning = {1} README.md description files found for '{0}', skipping.
NoExampleFileFoundWarning = No Example files found for resource '{0}'.
'@
109 changes: 92 additions & 17 deletions tests/unit/public/New-DscResourceWikiPage.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ Configuration Example

# General mock values
$script:mockReadmePath = Join-Path -Path $script:mockSchemaFolder -ChildPath 'readme.md'
$script:mockReadmeFolder = $script:mockSchemaFolder
$script:mockOutputFile = Join-Path -Path $script:mockOutputPath -ChildPath "$($script:mockResourceName).md"
$script:mockSavePath = Join-Path -Path $script:mockOutputPath -ChildPath "$($script:mockResourceName).md"
$script:mockDestinationModulePathSavePath = Join-Path -Path $script:mockDestinationModulePath -ChildPath "DscResources\$($script:mockResourceName)\en-US\about_$($script:mockResourceName).help.txt"
Expand Down Expand Up @@ -197,6 +198,10 @@ Configuration Example
$Path -eq $script:expectedSchemaPath
}

$script:getChildItemDescription_parameterFilter = {
$Path -eq $script:mockReadmeFolder
}

$script:getChildItemExample_parameterFilter = {
$Path -eq $script:expectedExamplePath
}
Expand Down Expand Up @@ -235,6 +240,10 @@ Configuration Example
$Message -eq ($script:localizedData.NoDescriptionFileFoundWarning -f $script:mockResourceName)
}

$script:writeWarningMultipleDescription_parameterFilter = {
$Message -eq ($script:localizedData.MultipleDescriptionFileFoundWarning -f $script:mockResourceName, 2)
}

$script:writeWarningExample_parameterFilter = {
$Message -eq ($script:localizedData.NoExampleFileFoundWarning -f $script:mockResourceName)
}
Expand All @@ -257,7 +266,7 @@ Configuration Example
Verbose = $true
}

Context 'When there is no schemas found in the module folder' {
Context 'When there are no schemas found in the module folder' {
BeforeAll {
Mock `
-CommandName Get-ChildItem `
Expand Down Expand Up @@ -297,9 +306,9 @@ Configuration Example
-MockWith { $script:mockGetMofSchemaObject }

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

Mock `
-CommandName Out-File `
Expand All @@ -320,6 +329,11 @@ Configuration Example
-ParameterFilter $script:getChildItemSchema_parameterFilter `
-Exactly -Times 1

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

Assert-MockCalled `
-CommandName Write-Warning `
-ParameterFilter $script:writeWarningDescription_parameterFilter `
Expand All @@ -332,6 +346,61 @@ Configuration Example
}
}

Context 'When there are multiple resource descriptions found' {
BeforeAll {
Mock `
-CommandName Get-ChildItem `
-ParameterFilter $script:getChildItemSchema_parameterFilter `
-MockWith { $script:mockSchemaFiles }

Mock `
-CommandName Get-MofSchemaObject `
-ParameterFilter $script:getMofSchemaObjectSchema_parameterFilter `
-MockWith { $script:mockGetMofSchemaObject }

Mock `
-CommandName Get-ChildItem `
-ParameterFilter $script:getChildItemDescription_parameterFilter `
-MockWith { return @(
@{ Name = 'README.MD'; FullName = $script:mockReadmePath },
@{ Name = 'Readme.md'; FullName = $script:mockReadmePath }) }

Mock `
-CommandName Out-File `
-ParameterFilter $script:outFile_parameterFilter

Mock `
-CommandName Write-Warning `
-ParameterFilter $script:writeWarningMultipleDescription_parameterFilter
}

It 'Should not throw an exception' {
{ New-DscResourceWikiPage @script:newDscResourceWikiPageOutput_parameters } | Should -Not -Throw
}

It 'Should call the expected mocks ' {
Assert-MockCalled `
-CommandName Get-ChildItem `
-ParameterFilter $script:getChildItemSchema_parameterFilter `
-Exactly -Times 1

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

Assert-MockCalled `
-CommandName Write-Warning `
-ParameterFilter $script:writeWarningMultipleDescription_parameterFilter `
-Exactly -Times 1

Assert-MockCalled `
-CommandName Out-File `
-ParameterFilter $script:outFile_parameterFilter `
-Exactly -Times 0
}
}

Context 'When there is no resource example file found' {
BeforeAll {
Mock `
Expand All @@ -345,9 +414,9 @@ Configuration Example
-MockWith { $script:mockGetMofSchemaObject }

Mock `
-CommandName Test-Path `
-ParameterFilter $script:getTestPathReadme_parameterFilter `
-MockWith { $true }
-CommandName Get-ChildItem `
-ParameterFilter $script:getChildItemDescription_parameterFilter `
-MockWith { return @(@{ Name = 'README.MD'; FullName = $script:mockReadmePath }) }

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

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

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

Mock `
-CommandName Test-Path `
-ParameterFilter $script:getTestPathReadme_parameterFilter `
-MockWith { $true }
-CommandName Get-ChildItem `
-ParameterFilter $script:getChildItemDescription_parameterFilter `
-MockWith { return @(@{ Name = 'README.MD'; FullName = $script:mockReadmePath }) }


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

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

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

Mock `
-CommandName Test-Path `
-ParameterFilter $script:getTestPathReadme_parameterFilter `
-MockWith { $true }
-CommandName Get-ChildItem `
-ParameterFilter $script:getChildItemDescription_parameterFilter `
-MockWith { return @(@{ Name = 'README.MD'; FullName = $script:mockReadmePath }) }

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

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

Assert-MockCalled `
Expand Down

0 comments on commit d289c8b

Please sign in to comment.