Add parameter validation functions and enhance tests for configuration data
This commit is contained in:
@@ -84,6 +84,54 @@ Describe "Resolve-DSCConfigurationData" {
|
||||
{ Resolve-DSCConfigurationData -ConfigurationData $ConfigurationData } | Should Throw
|
||||
}
|
||||
|
||||
It "validates array parameter items against AllowedValues" {
|
||||
$ConfigurationData = @{
|
||||
Parameters = @{
|
||||
ServerRoles = @{
|
||||
Type = "array"
|
||||
Value = @(
|
||||
"WebFrontEnd",
|
||||
"Application"
|
||||
)
|
||||
AllowedValues = @(
|
||||
"WebFrontEnd",
|
||||
"Application",
|
||||
"Search"
|
||||
)
|
||||
}
|
||||
}
|
||||
Resources = @{
|
||||
Roles = "[parameters('ServerRoles')]"
|
||||
}
|
||||
}
|
||||
|
||||
$Result = Resolve-DSCConfigurationData -ConfigurationData $ConfigurationData
|
||||
|
||||
$Result.Resources.Roles[0] | Should Be "WebFrontEnd"
|
||||
$Result.Resources.Roles[1] | Should Be "Application"
|
||||
}
|
||||
|
||||
It "throws when an array parameter item is not listed in AllowedValues" {
|
||||
$ConfigurationData = @{
|
||||
Parameters = @{
|
||||
ServerRoles = @{
|
||||
Type = "array"
|
||||
Value = @(
|
||||
"WebFrontEnd",
|
||||
"InvalidRole"
|
||||
)
|
||||
AllowedValues = @(
|
||||
"WebFrontEnd",
|
||||
"Application",
|
||||
"Search"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{ Resolve-DSCConfigurationData -ConfigurationData $ConfigurationData } | Should Throw
|
||||
}
|
||||
|
||||
It "validates required parameters" {
|
||||
$ConfigurationData = @{
|
||||
Parameters = @{
|
||||
@@ -124,6 +172,107 @@ Describe "Resolve-DSCConfigurationData" {
|
||||
{ Resolve-DSCConfigurationData -ConfigurationData $ConfigurationData } | Should Throw
|
||||
}
|
||||
|
||||
It "validates supported parameter types" {
|
||||
$ConfigurationData = @{
|
||||
Parameters = @{
|
||||
Name = @{
|
||||
Type = "string"
|
||||
Value = "SharePoint"
|
||||
}
|
||||
Port = @{
|
||||
Type = "int"
|
||||
Value = 1433
|
||||
}
|
||||
Enabled = @{
|
||||
Type = "bool"
|
||||
Value = $true
|
||||
}
|
||||
Roles = @{
|
||||
Type = "array"
|
||||
Value = @(
|
||||
"WebFrontEnd",
|
||||
"Application"
|
||||
)
|
||||
}
|
||||
SecretReference = @{
|
||||
Type = "secureString"
|
||||
Value = @{
|
||||
SecretName = "SharePointFarmPassphrase"
|
||||
}
|
||||
Sensitive = $true
|
||||
}
|
||||
CredentialReference = @{
|
||||
Type = "credential"
|
||||
Value = @{
|
||||
CredentialName = "SharePointSetup"
|
||||
}
|
||||
Sensitive = $true
|
||||
}
|
||||
}
|
||||
Resources = @{
|
||||
Name = "[parameters('Name')]"
|
||||
Port = "[parameters('Port')]"
|
||||
Enabled = "[parameters('Enabled')]"
|
||||
RoleCount = "[length(parameters('Roles'))]"
|
||||
}
|
||||
}
|
||||
|
||||
$Result = Resolve-DSCConfigurationData -ConfigurationData $ConfigurationData
|
||||
|
||||
$Result.Resources.Name | Should Be "SharePoint"
|
||||
$Result.Resources.Port | Should Be 1433
|
||||
$Result.Resources.Enabled | Should Be $true
|
||||
$Result.Resources.RoleCount | Should Be 2
|
||||
}
|
||||
|
||||
It "throws when parameter type validation fails" {
|
||||
$ConfigurationData = @{
|
||||
Parameters = @{
|
||||
Port = @{
|
||||
Type = "int"
|
||||
Value = "1433"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{ Resolve-DSCConfigurationData -ConfigurationData $ConfigurationData } | Should Throw
|
||||
}
|
||||
|
||||
It "validates numeric ranges" {
|
||||
$ConfigurationData = @{
|
||||
Parameters = @{
|
||||
Port = @{
|
||||
Type = "int"
|
||||
Value = 1433
|
||||
MinValue = 1
|
||||
MaxValue = 65535
|
||||
}
|
||||
}
|
||||
Resources = @{
|
||||
Port = "[parameters('Port')]"
|
||||
}
|
||||
}
|
||||
|
||||
$Result = Resolve-DSCConfigurationData -ConfigurationData $ConfigurationData
|
||||
|
||||
$Result.Resources.Port | Should Be 1433
|
||||
}
|
||||
|
||||
It "throws when numeric range validation fails" {
|
||||
$ConfigurationData = @{
|
||||
Parameters = @{
|
||||
Port = @{
|
||||
Type = "int"
|
||||
Value = 70000
|
||||
MinValue = 1
|
||||
MaxValue = 65535
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{ Resolve-DSCConfigurationData -ConfigurationData $ConfigurationData } | Should Throw
|
||||
}
|
||||
|
||||
It "supports localized deprecated parameter messages" {
|
||||
$ConfigurationData = @{
|
||||
Parameters = @{
|
||||
|
||||
Reference in New Issue
Block a user