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

(GH-153) Ensure generated readme contains module name info #163

Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Ability to set generated modules fixtures to something other than the latest released version of `puppetlabs-pwshlib` on the Forge ([#93](https://github.com/puppetlabs/Puppet.Dsc/issues/93))
- A check to `New-PuppetDscModule` which validates that PSRemoting is enabled and errors clearly if not in order to prevent unexpected execution failures later in the process ([#133](https://github.com/puppetlabs/Puppet.Dsc/issues/133))

### Fixed

- Ensure that the auto-generated readme of a Puppetized module contains both the PowerShell and Puppet module names ([#153](https://github.com/puppetlabs/Puppet.Dsc/issues/153))
- Make all `Update-PuppetModuleReadme` parameters except `PuppetModuleName` mandatory and do not accept null or empty values ([#153](https://github.com/puppetlabs/Puppet.Dsc/issues/153))
- Make the `PowerShellModuleName` and `PuppetModuleName` parameters in `Get-Readmecontent` mandatory and do not accept null or empty values for any parameters ([#153](https://github.com/puppetlabs/Puppet.Dsc/issues/153))

## [0.5.0] - 2021-2-10

### Added
Expand Down
2 changes: 2 additions & 0 deletions src/functions/New-PuppetDscModule.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ Describe "New-PuppetDscModule" {
}
It 'Updates the Puppet README based on the PowerShell metadata' {
Should -Invoke Update-PuppetModuleReadme -ParameterFilter {
$PuppetModuleName -match 'foo' -and
$PowerShellModuleName -match 'Foo' -and
$PuppetModuleFolderPath -match 'import(/|\\)foo' -and
$PowerShellModuleManifestPath -match 'import(/|\\)foo\S+(/|\\)foo(/|\\)foo.psd1'
} -Scope Context
Expand Down
2 changes: 1 addition & 1 deletion src/functions/New-PuppetDscModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Function New-PuppetDscModule {

# Write the Puppet module README
Write-PSFMessage -Message 'Writing the Puppet Module readme'
Update-PuppetModuleReadme -PuppetModuleFolderPath $PuppetModuleRootFolderDirectory -PowerShellModuleManifestPath $PowerShellModuleManifestPath
Update-PuppetModuleReadme -PuppetModuleName $PuppetModuleName -PowerShellModuleName $PowerShellModuleName -PuppetModuleFolderPath $PuppetModuleRootFolderDirectory -PowerShellModuleManifestPath $PowerShellModuleManifestPath

# Write the Puppet module changelog based on PowerShell module
Write-PSFMessage -Message 'Writing the Puppet Module changelog'
Expand Down
88 changes: 88 additions & 0 deletions src/internal/functions/Get-ReadmeContent.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,93 @@ Describe 'Get-ReadmeContent' {
$Result | Should -MatchExactly "\[file an issue\]\($($Parameters.PowerShellModuleProjectUri)\)"
}
}
Context 'Parameter handling' {
It 'Errors if the PowerShellModuleName is not specified' {
$Parameters = @{
PowerShellModuleDescription = 'Foo and bar and baz!'
PowerShellModuleGalleryUri = 'https://powershellgallery.com/Foo.Bar/1.0.0'
PowerShellModuleProjectUri = 'https://github.com/Baz/Foo.Bar'
PowerShellModuleVersion = '1.0.0'
PuppetModuleName = 'foo_bar'
}
{ Get-ReadmeContent @Parameters } | Should -Throw "Cannot process command because of one or more missing mandatory parameters: PowerShellModuleName."
}
It 'Errors if the PuppetModuleName is not specified' {
$Parameters = @{
PowerShellModuleName = 'Foo.Bar'
PowerShellModuleDescription = 'Foo and bar and baz!'
PowerShellModuleGalleryUri = 'https://powershellgallery.com/Foo.Bar/1.0.0'
PowerShellModuleProjectUri = 'https://github.com/Baz/Foo.Bar'
PowerShellModuleVersion = '1.0.0'
}
{ Get-ReadmeContent @Parameters } | Should -Throw "Cannot process command because of one or more missing mandatory parameters: PuppetModuleName."
}
It 'Errors if the PowerShellModuleName is specified as an empty string' {
$Parameters = @{
PowerShellModuleName = ''
PowerShellModuleDescription = 'Foo and bar and baz!'
PowerShellModuleGalleryUri = 'https://powershellgallery.com/Foo.Bar/1.0.0'
PowerShellModuleProjectUri = 'https://github.com/Baz/Foo.Bar'
PowerShellModuleVersion = '1.0.0'
PuppetModuleName = 'foo_bar'
}
{ Get-ReadmeContent @Parameters } | Should -Throw "Cannot validate argument on parameter 'PowerShellModuleName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again."
}
It 'Errors if the PowerShellModuleDescription is specified as an empty string' {
$Parameters = @{
PowerShellModuleName = 'Foo.Bar'
PowerShellModuleDescription = ''
PowerShellModuleGalleryUri = 'https://powershellgallery.com/Foo.Bar/1.0.0'
PowerShellModuleProjectUri = 'https://github.com/Baz/Foo.Bar'
PowerShellModuleVersion = '1.0.0'
PuppetModuleName = 'foo_bar'
}
{ Get-ReadmeContent @Parameters } | Should -Throw "Cannot validate argument on parameter 'PowerShellModuleDescription'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again."
}
It 'Errors if the PowerShellModuleGalleryUri is specified as an empty string' {
$Parameters = @{
PowerShellModuleName = 'Foo.Bar'
PowerShellModuleDescription = 'Foo and bar and baz!'
PowerShellModuleGalleryUri = ''
PowerShellModuleProjectUri = 'https://github.com/Baz/Foo.Bar'
PowerShellModuleVersion = '1.0.0'
PuppetModuleName = 'foo_bar'
}
{ Get-ReadmeContent @Parameters } | Should -Throw "Cannot validate argument on parameter 'PowerShellModuleGalleryUri'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again."
}
It 'Errors if the PowerShellModuleProjectUri is specified as an empty string' {
$Parameters = @{
PowerShellModuleName = 'Foo.Bar'
PowerShellModuleDescription = 'Foo and bar and baz!'
PowerShellModuleGalleryUri = 'https://powershellgallery.com/Foo.Bar/1.0.0'
PowerShellModuleProjectUri = ''
PowerShellModuleVersion = '1.0.0'
PuppetModuleName = 'foo_bar'
}
{ Get-ReadmeContent @Parameters } | Should -Throw "Cannot validate argument on parameter 'PowerShellModuleProjectUri'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again."
}
It 'Errors if the PowerShellModuleVersion is specified as an empty string' {
$Parameters = @{
PowerShellModuleName = 'Foo.Bar'
PowerShellModuleDescription = 'Foo and bar and baz!'
PowerShellModuleGalleryUri = 'https://powershellgallery.com/Foo.Bar/1.0.0'
PowerShellModuleProjectUri = 'https://github.com/Baz/Foo.Bar'
PowerShellModuleVersion = ''
PuppetModuleName = 'foo_bar'
}
{ Get-ReadmeContent @Parameters } | Should -Throw "Cannot validate argument on parameter 'PowerShellModuleVersion'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again."
}
It 'Errors if the PuppetModuleName is specified as an empty string' {
$Parameters = @{
PowerShellModuleName = 'Foo.Bar'
PowerShellModuleDescription = 'Foo and bar and baz!'
PowerShellModuleGalleryUri = 'https://powershellgallery.com/Foo.Bar/1.0.0'
PowerShellModuleProjectUri = 'https://github.com/Baz/Foo.Bar'
PowerShellModuleVersion = '1.0.0'
PuppetModuleName = ''
}
{ Get-ReadmeContent @Parameters } | Should -Throw "Cannot validate argument on parameter 'PuppetModuleName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again."
}
}
}
}
12 changes: 6 additions & 6 deletions src/internal/functions/Get-ReadmeContent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ function Get-ReadmeContent {
[cmdletbinding()]
param (
[OutputType([String])]
[string]$PowerShellModuleName,
[string]$PowerShellModuleDescription,
[string]$PowerShellModuleGalleryUri,
[string]$PowerShellModuleProjectUri,
[string]$PowerShellModuleVersion,
[string]$PuppetModuleName
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string]$PowerShellModuleName,
[ValidateNotNullOrEmpty()][string]$PowerShellModuleDescription,
[ValidateNotNullOrEmpty()][string]$PowerShellModuleGalleryUri,
[ValidateNotNullOrEmpty()][string]$PowerShellModuleProjectUri,
[ValidateNotNullOrEmpty()][string]$PowerShellModuleVersion,
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string]$PuppetModuleName
)

Begin {
Expand Down
65 changes: 65 additions & 0 deletions src/internal/functions/Update-PuppetModuleReadme.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,30 @@ Describe 'Update-PuppetModuleReadme' {
}
{ Update-PuppetModuleReadme @Parameters } | Should -Throw "Cannot find path 'TestDrive:\foo\bar' because it does not exist."
}
It 'Errors if the PowerShellModuleManifestPath is not specified' {
$Parameters = @{
PowerShellModuleName = 'PowerShellGet'
PuppetModuleFolderPath = $PuppetFolderPath
PuppetModuleName = 'powershellget'
}
{ Update-PuppetModuleReadme @Parameters } | Should -Throw "Cannot process command because of one or more missing mandatory parameters: PowerShellModuleManifestPath."
}
It 'Errors if the PowerShellModuleName is not specified' {
$Parameters = @{
PowerShellModuleManifestPath = 'TestDrive:\foo\bar'
PuppetModuleFolderPath = $PuppetFolderPath
PuppetModuleName = 'powershellget'
}
{ Update-PuppetModuleReadme @Parameters } | Should -Throw "Cannot process command because of one or more missing mandatory parameters: PowerShellModuleName."
}
It 'Errors if the PuppetModuleFolderPath is not specified' {
$Parameters = @{
PowerShellModuleManifestPath = 'TestDrive:\foo\bar'
PowerShellModuleName = 'PowerShellGet'
PuppetModuleName = 'powershellget'
}
{ Update-PuppetModuleReadme @Parameters } | Should -Throw "Cannot process command because of one or more missing mandatory parameters: PuppetModuleFolderPath."
}
It 'Sets the Puppet module name if not specified' {
$Parameters = @{
PowerShellModuleManifestPath = $ManifestFilePath
Expand All @@ -70,6 +94,47 @@ Describe 'Update-PuppetModuleReadme' {
$PuppetModuleName -ceq 'foo'
}
}
It 'Errors if the PowerShellModuleManifestPath is specified as an empty string' {
$Parameters = @{
PowerShellModuleManifestPath = ''
PowerShellModuleName = 'PowerShellGet'
PuppetModuleFolderPath = $PuppetFolderPath
PuppetModuleName = 'powershellget'
}
{ Update-PuppetModuleReadme @Parameters } | Should -Throw "Cannot validate argument on parameter 'PowerShellModuleManifestPath'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again."
}
It 'Errors if the PowerShellModuleName is specified as an empty string' {
$Parameters = @{
PowerShellModuleManifestPath = 'TestDrive:\foo\bar'
PowerShellModuleName = ''
PuppetModuleFolderPath = $PuppetFolderPath
PuppetModuleName = 'powershellget'
}
{ Update-PuppetModuleReadme @Parameters } | Should -Throw "Cannot validate argument on parameter 'PowerShellModuleName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again."
}
It 'Errors if the PuppetModuleFolderPath is specified as an empty string' {
$Parameters = @{
PowerShellModuleManifestPath = 'TestDrive:\foo\bar'
PowerShellModuleName = 'PowerShellGet'
PuppetModuleFolderPath = ''
PuppetModuleName = 'powershellget'
}
{ Update-PuppetModuleReadme @Parameters } | Should -Throw "Cannot validate argument on parameter 'PuppetModuleFolderPath'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again."
}
It 'Sets the Puppet module name if specified as an empty string' {
$Parameters = @{
PowerShellModuleManifestPath = $ManifestFilePath
PowerShellModuleName = 'PowerShellGet'
PuppetModuleFolderPath = $PuppetFolderPath
PuppetModuleName = ''
}
# empty
{ Update-PuppetModuleReadme @Parameters } | Should -Not -Throw
Should -Invoke Get-PuppetizedModuleName -Times 1
Should -Invoke Get-ReadmeContent -Times 1 -ParameterFilter {
$PuppetModuleName -ceq 'foo'
}
}
}
Context 'Updating Readme' {
BeforeAll {
Expand Down
6 changes: 3 additions & 3 deletions src/internal/functions/Update-PuppetModuleReadme.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ function Update-PuppetModuleReadme {
#>
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
param (
[string]$PowerShellModuleManifestPath,
[string]$PowerShellModuleName,
[string]$PuppetModuleFolderPath,
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string]$PowerShellModuleManifestPath,
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string]$PowerShellModuleName,
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string]$PuppetModuleFolderPath,
[string]$PuppetModuleName
)

Expand Down