Skip to content

Commit

Permalink
xDnsServerRootHint: Added integration test (#183)
Browse files Browse the repository at this point in the history
- xDnsServerRootHint
  - Added integration test (issue #174)
  - Fixed the verbose message returning the correct number of root hints.
  • Loading branch information
johlju authored Feb 28, 2021
1 parent dbcdb06 commit b575ca0
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added more examples.
- xDnsRecordMx
- Added new resource to manage MX records
- xDnsServerRootHint
- Added integration test ([issue #174](https://github.com/dsccommunity/xDnsServer/issues/174)).

### Changed

Expand Down Expand Up @@ -100,6 +102,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- xDnsServerAdZone
- Now the parameter `ComputerName` can be used without throwing an exception
([issue 79](https://github.com/PowerShell/xDnsServer/issues/79)).
- xDnsServerRootHint
- Fixed the verbose message returning the correct number of root hints.

## [1.16.0.0] - 2019-10-30

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function Get-TargetResource
NameServer = Convert-RootHintsToHashtable -RootHints @(Get-DnsServerRootHint)
}

Write-Verbose -Message ($script:localizedData.FoundRootHintsMessage -f $result.Count)
Write-Verbose -Message ($script:localizedData.FoundRootHintsMessage -f $result.NameServer.Count)
$result
}

Expand Down
152 changes: 152 additions & 0 deletions tests/Integration/MSFT_xDnsServerRootHint.Integration.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
$script:dscModuleName = 'xDnsServer'
$script:dscResourceFriendlyName = 'xDnsServerRootHint'
$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)_RemoveAllRootHints_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.IsSingleInstance | Should -Be 'Yes'
$resourceCurrentState.NameServer | Should -BeNullOrEmpty
}

It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
}
}

Wait-ForIdleLcm -Clear

$configurationName = "$($script:dscResourceName)_SetRootHints_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
}

$nameServerHashtable = @{}

foreach ($nameServer in $resourceCurrentState.NameServer)
{
$nameServerHashtable.Add($nameServer.Key, $nameServer.Value)
}

$nameServerHashtable.Count | Should -Be $ConfigurationData.AllNodes.NameServer.Count

$resourceCurrentState.IsSingleInstance | Should -Be 'Yes'

$nameServerHashtable['H.ROOT-SERVERS.NET.'] | Should -Be '198.97.190.53'
$nameServerHashtable['E.ROOT-SERVERS.NET.'] | Should -Be '192.203.230.10'
$nameServerHashtable['M.ROOT-SERVERS.NET.'] | Should -Be '202.12.27.33'
$nameServerHashtable['A.ROOT-SERVERS.NET.'] | Should -Be '198.41.0.4'
$nameServerHashtable['D.ROOT-SERVERS.NET.'] | Should -Be '199.7.91.13'
$nameServerHashtable['F.ROOT-SERVERS.NET.'] | Should -Be '192.5.5.241'
$nameServerHashtable['B.ROOT-SERVERS.NET.'] | Should -Be '192.228.79.201'
$nameServerHashtable['G.ROOT-SERVERS.NET.'] | Should -Be '192.112.36.4'
$nameServerHashtable['C.ROOT-SERVERS.NET.'] | Should -Be '192.33.4.12'
$nameServerHashtable['K.ROOT-SERVERS.NET.'] | Should -Be '193.0.14.129'
$nameServerHashtable['I.ROOT-SERVERS.NET.'] | Should -Be '192.36.148.17'
$nameServerHashtable['J.ROOT-SERVERS.NET.'] | Should -Be '192.58.128.30'
$nameServerHashtable['L.ROOT-SERVERS.NET.'] | Should -Be '199.7.83.42'
}

It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
}
}

Wait-ForIdleLcm -Clear
}
}
finally
{
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}
52 changes: 52 additions & 0 deletions tests/Integration/MSFT_xDnsServerRootHint.config.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
$ConfigurationData = @{
AllNodes = @(
@{
NodeName = 'localhost'
CertificateFile = $env:DscPublicCertificatePath

NameServer = @{
'H.ROOT-SERVERS.NET.' = '198.97.190.53'
'E.ROOT-SERVERS.NET.' = '192.203.230.10'
'M.ROOT-SERVERS.NET.' = '202.12.27.33'
'A.ROOT-SERVERS.NET.' = '198.41.0.4'
'D.ROOT-SERVERS.NET.' = '199.7.91.13'
'F.ROOT-SERVERS.NET.' = '192.5.5.241'
'B.ROOT-SERVERS.NET.' = '192.228.79.201'
'G.ROOT-SERVERS.NET.' = '192.112.36.4'
'C.ROOT-SERVERS.NET.' = '192.33.4.12'
'K.ROOT-SERVERS.NET.' = '193.0.14.129'
'I.ROOT-SERVERS.NET.' = '192.36.148.17'
'J.ROOT-SERVERS.NET.' = '192.58.128.30'
'L.ROOT-SERVERS.NET.' = '199.7.83.42'
}
}
)
}

configuration MSFT_xDnsServerRootHint_RemoveAllRootHints_Config
{
Import-DscResource -ModuleName 'xDnsServer'

node $AllNodes.NodeName
{
xDnsServerRootHint 'Integration_Test'
{
IsSingleInstance = 'Yes'
NameServer = @{}
}
}
}

configuration MSFT_xDnsServerRootHint_SetRootHints_Config
{
Import-DscResource -ModuleName 'xDnsServer'

node $AllNodes.NodeName
{
xDnsServerRootHint 'Integration_Test'
{
IsSingleInstance = 'Yes'
NameServer = $Node.NameServer
}
}
}

0 comments on commit b575ca0

Please sign in to comment.