Hi,
I’m currently working on a project where I’m auditing properties of Azure settings.
for example get-azureRmSqlDatabaseThreatDetectionPolicy, ThreatDetectionState is enabled or not.
I’m trying to write my test and code correctly but I’m confused as to how to load the test cases up with the information I need, or I’m not understanding how to use the test cases correctly. I need some advice please.
Rather than just adding the servername to the testcase I would like to have the resourcegroup added also and then be able to refer to it as a param? Is this possible.
Here is my code - doesn’t work
$sqlservername = Get-azurermsqlserver |Select-Object servername, ResourceGroupName
$TestCases = @()
$sqlservername.ForEach{$TestCases += @{sqlservername = $_.Servername}}
Describe ‘Testing user databases’ {
Create a Context for each Instance.
it “Testing Threatprotectionpolicy on $($_)” -TestCases $TestCases {
Loop through the sql server on the instance
Param($sqlservername)
(Get-AzureRmSqlServerThreatDetectionPolicy -resourcegroupname $sqlservername.resourcegroupname -servername $sqlservername ).ThreatDetectionState | Should -Be “Enabled”
}
}
Below is an alternate way I have got it working but I really wanted to use the testcases if possible.
$sqlservername = Get-azurermsqlserver |Select-Object servername, ResourceGroupName
Describe ‘Testing user databases’ {
Loop through the instances
$sqlservername.ForEach{
Create a Context for each Instance.
Context “Testing Threatprotectionpolicy on $($_)” {
Loop through the sql server on the instance
(Get-AzureRmSqlServerThreatDetectionPolicy -resourcegroupname $.resourcegroupname -servername $.servername ).ForEach{
It “SQL Server ThreatDetectionState should be Enabled” {
$_.ThreatDetectionState | Should -Be “Enabled”
}
}
}
}
}
Many Thanks Russ