-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SqlServerDsc: Change type for property
Reasons
(#1858)
- SqlServerDsc - Added class `SqlReason` to be used as the type of the DSC property `Reasons` for class-based resources. - The type of the property `Reasons` was changed in the class-based resources. This resolves a problem when using two DSC resource modules that was using the same class-type for the property `Reasons`. - SqlAudit - Return the correct type for parameter `LogType` when calling method `Get()`.
- Loading branch information
Showing
5 changed files
with
113 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<# | ||
.SYNOPSIS | ||
The reason a property of a DSC resource is not in desired state. | ||
.DESCRIPTION | ||
A DSC resource can have a read-only property `Reasons` that the compliance | ||
part (audit via Azure Policy) of Azure AutoManage Machine Configuration | ||
uses. The property Reasons holds an array of SqlReason. Each SqlReason | ||
explains why a property of a DSC resource is not in desired state. | ||
#> | ||
|
||
class SqlReason | ||
{ | ||
[DscProperty()] | ||
[System.String] | ||
$Code | ||
|
||
[DscProperty()] | ||
[System.String] | ||
$Phrase | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')] | ||
param () | ||
|
||
BeforeDiscovery { | ||
try | ||
{ | ||
if (-not (Get-Module -Name 'DscResource.Test')) | ||
{ | ||
# Assumes dependencies has been resolved, so if this module is not available, run 'noop' task. | ||
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable)) | ||
{ | ||
# Redirect all streams to $null, except the error stream (stream 2) | ||
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null | ||
} | ||
|
||
# If the dependencies has not been resolved, this will throw an error. | ||
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop' | ||
} | ||
} | ||
catch [System.IO.FileNotFoundException] | ||
{ | ||
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.' | ||
} | ||
} | ||
|
||
BeforeAll { | ||
$script:dscModuleName = 'SqlServerDsc' | ||
|
||
$env:SqlServerDscCI = $true | ||
|
||
Import-Module -Name $script:dscModuleName | ||
|
||
$PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:dscModuleName | ||
$PSDefaultParameterValues['Mock:ModuleName'] = $script:dscModuleName | ||
$PSDefaultParameterValues['Should:ModuleName'] = $script:dscModuleName | ||
} | ||
|
||
AfterAll { | ||
$PSDefaultParameterValues.Remove('InModuleScope:ModuleName') | ||
$PSDefaultParameterValues.Remove('Mock:ModuleName') | ||
$PSDefaultParameterValues.Remove('Should:ModuleName') | ||
|
||
# Unload the module being tested so that it doesn't impact any other tests. | ||
Get-Module -Name $script:dscModuleName -All | Remove-Module -Force | ||
|
||
Remove-Item -Path 'env:SqlServerDscCI' | ||
} | ||
|
||
Describe 'SqlReason' -Tag 'SqlReason' { | ||
Context 'When instantiating the class' { | ||
It 'Should not throw an error' { | ||
$script:mockSqlReasonInstance = InModuleScope -ScriptBlock { | ||
[SqlReason]::new() | ||
} | ||
} | ||
|
||
It 'Should be of the correct type' { | ||
$mockSqlReasonInstance | Should -Not -BeNullOrEmpty | ||
$mockSqlReasonInstance.GetType().Name | Should -Be 'SqlReason' | ||
} | ||
} | ||
|
||
Context 'When setting an reading values' { | ||
It 'Should be able to set value in instance' { | ||
$script:mockSqlReasonInstance = InModuleScope -ScriptBlock { | ||
$sqlReasonInstance = [SqlReason]::new() | ||
|
||
$sqlReasonInstance.Code = 'SqlAudit:SqlAudit:Ensure' | ||
$sqlReasonInstance.Phrase = 'The property Ensure should be "Present", but was "Absent"' | ||
|
||
return $sqlReasonInstance | ||
} | ||
} | ||
|
||
It 'Should be able read the values from instance' { | ||
$mockSqlReasonInstance.Code | Should -Be 'SqlAudit:SqlAudit:Ensure' | ||
$mockSqlReasonInstance.Phrase = 'The property Ensure should be "Present", but was "Absent"' | ||
} | ||
} | ||
} |