-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
xDnsServerZoneScope: Add integration test (#188)
- xDnsServerZoneScope - Added integration tests (issue #177). - New read-only property `ZoneFile` was added to return the zone scope file name used for the zone scope. - Correctly returns the zone scope name when calling `Get-TargetResource`.
- Loading branch information
Showing
6 changed files
with
272 additions
and
4 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
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
190 changes: 190 additions & 0 deletions
190
tests/Integration/MSFT_xDnsServerZoneScope.Integration.Tests.ps1
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,190 @@ | ||
$script:dscModuleName = 'xDnsServer' | ||
$script:dscResourceFriendlyName = 'xDnsServerZoneScope' | ||
$script:dscResourceName = "MSFT_$($script:dscResourceFriendlyName)" | ||
|
||
try | ||
{ | ||
Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' | ||
} | ||
catch [System.IO.FileNotFoundException] | ||
{ | ||
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' | ||
} | ||
|
||
$script:testEnvironment = Initialize-TestEnvironment ` | ||
-DSCModuleName $script:dscModuleName ` | ||
-DSCResourceName $script:dscResourceName ` | ||
-ResourceType 'Mof' ` | ||
-TestType 'Integration' | ||
|
||
try | ||
{ | ||
$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" | ||
. $configFile | ||
|
||
Describe "$($script:dscResourceName)_Integration" { | ||
BeforeAll { | ||
$resourceId = "[$($script:dscResourceFriendlyName)]Integration_Test" | ||
} | ||
|
||
$configurationName = "$($script:dscResourceName)_Prerequisites_Config" | ||
|
||
Context ('When using configuration {0}' -f $configurationName) { | ||
It 'Should compile and apply the MOF without throwing' { | ||
{ | ||
$configurationParameters = @{ | ||
OutputPath = $TestDrive | ||
ConfigurationData = $ConfigurationData | ||
} | ||
|
||
& $configurationName @configurationParameters | ||
|
||
$startDscConfigurationParameters = @{ | ||
Path = $TestDrive | ||
ComputerName = 'localhost' | ||
Wait = $true | ||
Verbose = $true | ||
Force = $true | ||
ErrorAction = 'Stop' | ||
} | ||
|
||
Start-DscConfiguration @startDscConfigurationParameters | ||
} | Should -Not -Throw | ||
} | ||
} | ||
|
||
Wait-ForIdleLcm -Clear | ||
|
||
$configurationName = "$($script:dscResourceName)_AddZoneScope_Config" | ||
|
||
Context ('When using configuration {0}' -f $configurationName) { | ||
It 'Should compile and apply the MOF without throwing' { | ||
{ | ||
$configurationParameters = @{ | ||
OutputPath = $TestDrive | ||
ConfigurationData = $ConfigurationData | ||
} | ||
|
||
& $configurationName @configurationParameters | ||
|
||
$startDscConfigurationParameters = @{ | ||
Path = $TestDrive | ||
ComputerName = 'localhost' | ||
Wait = $true | ||
Verbose = $true | ||
Force = $true | ||
ErrorAction = 'Stop' | ||
} | ||
|
||
Start-DscConfiguration @startDscConfigurationParameters | ||
} | Should -Not -Throw | ||
} | ||
|
||
It 'Should be able to call Get-DscConfiguration without throwing' { | ||
{ | ||
$script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop | ||
} | Should -Not -Throw | ||
} | ||
|
||
It 'Should have set the resource and all the parameters should match' { | ||
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { | ||
$_.ConfigurationName -eq $configurationName ` | ||
-and $_.ResourceId -eq $resourceId | ||
} | ||
|
||
$resourceCurrentState.Ensure | Should -Be 'Present' | ||
$resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.ZoneScopeName | ||
$resourceCurrentState.ZoneName | Should -Be $ConfigurationData.AllNodes.ForwardZoneName | ||
$resourceCurrentState.ZoneFile | Should -Be ('{0}.dns' -f $ConfigurationData.AllNodes.ZoneScopeName) | ||
} | ||
|
||
It 'Should return ''True'' when Test-DscConfiguration is run' { | ||
Test-DscConfiguration -Verbose | Should -Be 'True' | ||
} | ||
} | ||
|
||
Wait-ForIdleLcm -Clear | ||
|
||
$configurationName = "$($script:dscResourceName)_RemoveZoneScope_Config" | ||
|
||
Context ('When using configuration {0}' -f $configurationName) { | ||
It 'Should compile and apply the MOF without throwing' { | ||
{ | ||
$configurationParameters = @{ | ||
OutputPath = $TestDrive | ||
ConfigurationData = $ConfigurationData | ||
} | ||
|
||
& $configurationName @configurationParameters | ||
|
||
$startDscConfigurationParameters = @{ | ||
Path = $TestDrive | ||
ComputerName = 'localhost' | ||
Wait = $true | ||
Verbose = $true | ||
Force = $true | ||
ErrorAction = 'Stop' | ||
} | ||
|
||
Start-DscConfiguration @startDscConfigurationParameters | ||
} | Should -Not -Throw | ||
} | ||
|
||
It 'Should be able to call Get-DscConfiguration without throwing' { | ||
{ | ||
$script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop | ||
} | Should -Not -Throw | ||
} | ||
|
||
It 'Should have set the resource and all the parameters should match' { | ||
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { | ||
$_.ConfigurationName -eq $configurationName ` | ||
-and $_.ResourceId -eq $resourceId | ||
} | ||
|
||
$resourceCurrentState.Ensure | Should -Be 'Absent' | ||
$resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.ZoneScopeName | ||
$resourceCurrentState.ZoneName | Should -Be $ConfigurationData.AllNodes.ForwardZoneName | ||
$resourceCurrentState.ZoneFile | Should -BeNullOrEmpty | ||
} | ||
|
||
It 'Should return ''True'' when Test-DscConfiguration is run' { | ||
Test-DscConfiguration -Verbose | Should -Be 'True' | ||
} | ||
} | ||
|
||
Wait-ForIdleLcm -Clear | ||
|
||
$configurationName = "$($script:dscResourceName)_Cleanup_Config" | ||
|
||
Context ('When using configuration {0}' -f $configurationName) { | ||
It 'Should compile and apply the MOF without throwing' { | ||
{ | ||
$configurationParameters = @{ | ||
OutputPath = $TestDrive | ||
ConfigurationData = $ConfigurationData | ||
} | ||
|
||
& $configurationName @configurationParameters | ||
|
||
$startDscConfigurationParameters = @{ | ||
Path = $TestDrive | ||
ComputerName = 'localhost' | ||
Wait = $true | ||
Verbose = $true | ||
Force = $true | ||
ErrorAction = 'Stop' | ||
} | ||
|
||
Start-DscConfiguration @startDscConfigurationParameters | ||
} | Should -Not -Throw | ||
} | ||
} | ||
|
||
Wait-ForIdleLcm -Clear | ||
} | ||
} | ||
finally | ||
{ | ||
Restore-TestEnvironment -TestEnvironment $script:testEnvironment | ||
} |
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,68 @@ | ||
$ConfigurationData = @{ | ||
AllNodes = @( | ||
@{ | ||
NodeName = 'localhost' | ||
CertificateFile = $env:DscPublicCertificatePath | ||
|
||
ForwardZoneName = 'dsc.test' | ||
ZoneScopeName = 'dsc_Europe' | ||
} | ||
) | ||
} | ||
|
||
configuration MSFT_xDnsServerZoneScope_Prerequisites_Config | ||
{ | ||
Import-DscResource -ModuleName 'xDnsServer' | ||
|
||
node $AllNodes.NodeName | ||
{ | ||
xDnsServerPrimaryZone 'ForwardZone' | ||
{ | ||
Name = $Node.ForwardZoneName | ||
} | ||
} | ||
} | ||
|
||
configuration MSFT_xDnsServerZoneScope_AddZoneScope_Config | ||
{ | ||
Import-DscResource -ModuleName 'xDnsServer' | ||
|
||
node $AllNodes.NodeName | ||
{ | ||
xDnsServerZoneScope 'Integration_Test' | ||
{ | ||
Name = $Node.ZoneScopeName | ||
ZoneName = $Node.ForwardZoneName | ||
} | ||
} | ||
} | ||
|
||
configuration MSFT_xDnsServerZoneScope_RemoveZoneScope_Config | ||
{ | ||
Import-DscResource -ModuleName 'xDnsServer' | ||
|
||
node $AllNodes.NodeName | ||
{ | ||
xDnsServerZoneScope 'Integration_Test' | ||
{ | ||
Ensure = 'Absent' | ||
Name = $Node.ZoneScopeName | ||
ZoneName = $Node.ForwardZoneName | ||
} | ||
} | ||
} | ||
|
||
|
||
configuration MSFT_xDnsServerZoneScope_Cleanup_Config | ||
{ | ||
Import-DscResource -ModuleName 'xDnsServer' | ||
|
||
node $AllNodes.NodeName | ||
{ | ||
xDnsServerPrimaryZone 'ForwardZone' | ||
{ | ||
Ensure = 'Absent' | ||
Name = $Node.ForwardZoneName | ||
} | ||
} | ||
} |
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