From b575ca0e83615cb401df6547954cab04d6d3ae5d Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sun, 28 Feb 2021 10:58:11 +0100 Subject: [PATCH] xDnsServerRootHint: Added integration test (#183) - xDnsServerRootHint - Added integration test (issue #174) - Fixed the verbose message returning the correct number of root hints. --- CHANGELOG.md | 4 + .../MSFT_xDnsServerRootHint.psm1 | 2 +- ...T_xDnsServerRootHint.Integration.Tests.ps1 | 152 ++++++++++++++++++ .../MSFT_xDnsServerRootHint.config.ps1 | 52 ++++++ 4 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 tests/Integration/MSFT_xDnsServerRootHint.Integration.Tests.ps1 create mode 100644 tests/Integration/MSFT_xDnsServerRootHint.config.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b64e175..5aaabc00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/source/DSCResources/MSFT_xDnsServerRootHint/MSFT_xDnsServerRootHint.psm1 b/source/DSCResources/MSFT_xDnsServerRootHint/MSFT_xDnsServerRootHint.psm1 index 4a892c89..440ac470 100644 --- a/source/DSCResources/MSFT_xDnsServerRootHint/MSFT_xDnsServerRootHint.psm1 +++ b/source/DSCResources/MSFT_xDnsServerRootHint/MSFT_xDnsServerRootHint.psm1 @@ -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 } diff --git a/tests/Integration/MSFT_xDnsServerRootHint.Integration.Tests.ps1 b/tests/Integration/MSFT_xDnsServerRootHint.Integration.Tests.ps1 new file mode 100644 index 00000000..6ff3ba4d --- /dev/null +++ b/tests/Integration/MSFT_xDnsServerRootHint.Integration.Tests.ps1 @@ -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 +} diff --git a/tests/Integration/MSFT_xDnsServerRootHint.config.ps1 b/tests/Integration/MSFT_xDnsServerRootHint.config.ps1 new file mode 100644 index 00000000..87e24a1b --- /dev/null +++ b/tests/Integration/MSFT_xDnsServerRootHint.config.ps1 @@ -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 + } + } +}