Skip to content

Commit

Permalink
(puppetlabsGH-153) - Add additional parameter validation to `Get-Read…
Browse files Browse the repository at this point in the history
…mecontent`

Makes the `PowerShellModuleName` and `PuppetModuleName` parameters in `Get-Readmecontent` mandatory and rejects null or empty values for any parameters
  • Loading branch information
david22swan committed Jun 3, 2021
1 parent 458f327 commit c1deca4
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- 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
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

0 comments on commit c1deca4

Please sign in to comment.