Skip to content

Commit

Permalink
Fixed issue in required tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ykuijs committed Oct 15, 2024
1 parent d8e4681 commit 3aee19c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added SettingDefinitionId as a new value to merge items in an array, in addition to UniqueId,
NodeName, Id and Identity
- Added support for the new Azure, Azure DevOps and Defender workloads
- Corrected issue in Required test in Test-M365DSCPowershellDataFile, where array
values were not checked properly.

## [0.4.2] - 2024-10-01

Expand Down
3 changes: 3 additions & 0 deletions source/Private/Convert-M365WorkloadName.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
$DSC_Workloads = @{
'AzureAD' = 'AAD'
'AzureDevOps' = 'ADO'
'Azure' = 'Azure'
'Defender' = 'Defender'
'Exchange' = 'EXO'
'Fabric' = 'Fabric'
'Intune' = 'Intune'
Expand Down
38 changes: 23 additions & 15 deletions source/Public/Test-M365DSCPowershellDataFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ function Test-M365DSCPowershellDataFile
try
{
switch ($type) {
'SInt32' { return "should -match '^\d+$' -because 'Must be a positive Integer'" }
'SInt64' { return "should -match '^\d+$' -because 'Must be a positive Integer'" }
'UInt32' { return "should -BeOfType 'Int'" }
'UInt64' { return "should -BeOfType 'Int'" }
'Guid' { return "Test-IsGuid | should -Be 'True'" }
default { return "should -BeOfType '$type'" }
'SInt32' { return "Should -Match '^\d+$' -Because 'Must be a positive Integer'" }
'SInt64' { return "Should -Match '^\d+$' -Because 'Must be a positive Integer'" }
'UInt32' { return "Should -BeOfType 'Int'" }
'UInt64' { return "Should -BeOfType 'Int'" }
'Guid' { return "Test-IsGuid | Should -Be 'True'" }
default { return "Should -BeOfType '$type'" }
}
}
catch
Expand Down Expand Up @@ -244,11 +244,11 @@ function Test-M365DSCPowershellDataFile
$MandatoryLeafs.foreach{
if ($MandatoryAction -eq 'Absent')
{
"`$inputObject.{0} | should -BeNullOrEmpty -because 'Denied Mandatory Setting'" -f $_.Path
"`$inputObject.{0} | Should -BeNullOrEmpty -Because 'Denied Mandatory Setting'" -f $_.Path
}
else
{
"`$inputObject.{0} | should -Be {1} -Because 'Mandatory Setting'" -f $_.Path, $_.Value
"`$inputObject.{0} | Should -Be {1} -Because 'Mandatory Setting'" -f $_.Path, $_.Value
}
}
}
Expand Down Expand Up @@ -282,7 +282,7 @@ function Test-M365DSCPowershellDataFile
# No Composite Resource available
if ($null -eq $objRefNode)
{
"`$inputObject.{0} | should -BeNullOrEmpty -because 'Not available as Composite Resource'" -f $nodeObject.Path
"`$inputObject.{0} | Should -BeNullOrEmpty -Because 'Not available as Composite Resource'" -f $nodeObject.Path
return
}

Expand All @@ -294,11 +294,11 @@ function Test-M365DSCPowershellDataFile
[Bool]$isHashTable = $( $objRefNode.valueType.name -eq 'HashTable')
if ($isHashTable)
{
"`$inputObject.{0} -is [HashTable] | should -BeTrue" -f $nodeObject.Path
"`$inputObject.{0} -is [HashTable] | Should -BeTrue" -f $nodeObject.Path
}
else
{
"`$inputObject.{0} -is [Array] | should -BeTrue " -f $nodeObject.Path
"`$inputObject.{0} -is [Array] | Should -BeTrue " -f $nodeObject.Path
}
}

Expand All @@ -310,13 +310,21 @@ function Test-M365DSCPowershellDataFile
{
foreach ($objRequiredNode in $objRequiredNodes)
{
if ($objRequiredNode.name -notin $excludeRequired)
if ($objRequiredNode.Path -eq 'NonNodeData.Environment.CICD.DependsOn')
{
"`$inputObject.{0}.{1} | should -not -BeNullOrEmpty -Because 'Required setting'" -f $nodeObject.path, $objRequiredNode.name
# NonNodeData.Environment.CICD.DependsOn is required, but can be an empty value
"`$inputObject.{0}{1} | Should -Not -Be `$null -Because 'Required setting'" -f $nodeObject.Path, $(if ( $objRequiredNode.Name -ne 0 ) { ".$($objRequiredNode.Name)" })
}
else
{
"#`$inputObject.{0}.{1} | should -not -BeNullOrEmpty -Because 'Required setting'" -f $nodeObject.path, $objRequiredNode.name
if ($objRequiredNode.Name -notin $excludeRequired)
{
"`$inputObject.{0}{1} | Should -Not -BeNullOrEmpty -Because 'Required setting'" -f $nodeObject.Path, $(if ( $objRequiredNode.Name -ne 0 ) { ".$($objRequiredNode.Name)" })
}
else
{
"#`$inputObject.{0}{1} | Should -Not -BeNullOrEmpty -Because 'Required setting'" -f $nodeObject.Path, $(if ( $objRequiredNode.Name -ne 0 ) { ".$($objRequiredNode.Name)" })
}
}
}
}
Expand Down Expand Up @@ -348,7 +356,7 @@ function Test-M365DSCPowershellDataFile
# ValidationSet Validation
if ($objRefNodeValue.validateSet)
{
"`$inputObject.{0} | should -beIn {1}" -f $nodeObject.path, $objRefNodeValue.validateSet
"`$inputObject.{0} | Should -BeIn {1}" -f $nodeObject.path, $objRefNodeValue.validateSet
}
}
}
Expand Down

0 comments on commit 3aee19c

Please sign in to comment.