diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ab7d4d..69526a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 index 90338d5..84a412c 100644 --- a/RequiredModules.psd1 +++ b/RequiredModules.psd1 @@ -9,7 +9,7 @@ InvokeBuild = 'latest' PSScriptAnalyzer = 'latest' - Pester = 'latest' + Pester = '4.10.1' Plaster = 'latest' ModuleBuilder = '1.0.0' Sampler = 'latest' diff --git a/source/Public/New-DscResourceWikiPage.ps1 b/source/Public/New-DscResourceWikiPage.ps1 index 83f9cf4..4dce175 100644 --- a/source/Public/New-DscResourceWikiPage.ps1 +++ b/source/Public/New-DscResourceWikiPage.ps1 @@ -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) @@ -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' @@ -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) diff --git a/source/en-US/DscResource.DocGenerator.strings.psd1 b/source/en-US/DscResource.DocGenerator.strings.psd1 index e5e22fa..d6bf756 100644 --- a/source/en-US/DscResource.DocGenerator.strings.psd1 +++ b/source/en-US/DscResource.DocGenerator.strings.psd1 @@ -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}'. '@ diff --git a/tests/unit/public/New-DscResourceWikiPage.Tests.ps1 b/tests/unit/public/New-DscResourceWikiPage.Tests.ps1 index 08e35be..a0ce1cb 100644 --- a/tests/unit/public/New-DscResourceWikiPage.Tests.ps1 +++ b/tests/unit/public/New-DscResourceWikiPage.Tests.ps1 @@ -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" @@ -197,6 +198,10 @@ Configuration Example $Path -eq $script:expectedSchemaPath } + $script:getChildItemDescription_parameterFilter = { + $Path -eq $script:mockReadmeFolder + } + $script:getChildItemExample_parameterFilter = { $Path -eq $script:expectedExamplePath } @@ -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) } @@ -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 ` @@ -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 ` @@ -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 ` @@ -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 ` @@ -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 ` @@ -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 ` @@ -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 ` @@ -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 ` @@ -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 ` @@ -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 `