Skip to content

Commit

Permalink
Changes to xADDomainTrust
Browse files Browse the repository at this point in the history
- Added integration tests (issue dsccommunity#348).
  • Loading branch information
johlju committed Jul 12, 2019
1 parent e3eff0b commit e0bc9ec
Show file tree
Hide file tree
Showing 3 changed files with 543 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
it to use the same code pattern as the resource xADObjectEnabledState.
- Added unit tests ([issue #324](https://github.com/PowerShell/xActiveDirectory/issues/324)).
- Added comment-based help ([issue #337](https://github.com/PowerShell/xActiveDirectory/issues/337)).
- Added integration tests ([issue #348](https://github.com/PowerShell/xActiveDirectory/issues/348)).

## 3.0.0.0

Expand Down
349 changes: 349 additions & 0 deletions Tests/Integration/MSFT_xADDomainTrust.Integration.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,349 @@
if ($env:APPVEYOR -eq $true)
{
Write-Warning -Message 'Integration test is not supported in AppVeyor.'
return
}

$script:dscModuleName = 'xActiveDirectory'
$script:dscResourceFriendlyName = 'xADDomainTrust'
$script:dscResourceName = "MSFT_$($script:dscResourceFriendlyName)"

#region HEADER
# Integration Test Template Version: 1.3.3
[System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
{
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests'))
}

Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force
$TestEnvironment = Initialize-TestEnvironment `
-DSCModuleName $script:dscModuleName `
-DSCResourceName $script:dscResourceName `
-TestType Integration
#endregion

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)_CreateDomainTrust_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
{
$configurationParameters = @{
OutputPath = $TestDrive
# The variable $ConfigurationData was dot-sourced above.
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.SourceDomainName | Should -Be $configurationData.AllNodes.SourceDomain
$resourceCurrentState.TargetDomainName | Should -Be $configurationData.AllNodes.TargetDomain
$resourceCurrentState.TargetDomainAdministratorCredential.UserName | Should -Be $configurationData.AllNodes.TargetUserName
$resourceCurrentState.TrustType | Should -Be 'External'
$resourceCurrentState.TrustDirection | Should -Be 'Outbound'
}

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

$configurationName = "$($script:dscResourceName)_ChangeDomainTrustDirection_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
{
$configurationParameters = @{
OutputPath = $TestDrive
# The variable $ConfigurationData was dot-sourced above.
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.SourceDomainName | Should -Be $configurationData.AllNodes.SourceDomain
$resourceCurrentState.TargetDomainName | Should -Be $configurationData.AllNodes.TargetDomain
$resourceCurrentState.TargetDomainAdministratorCredential.UserName | Should -Be $configurationData.AllNodes.TargetUserName
$resourceCurrentState.TrustType | Should -Be 'External'
$resourceCurrentState.TrustDirection | Should -Be 'Inbound'
}

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

$configurationName = "$($script:dscResourceName)_RemoveDomainTrust_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
{
$configurationParameters = @{
OutputPath = $TestDrive
# The variable $ConfigurationData was dot-sourced above.
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.SourceDomainName | Should -Be $configurationData.AllNodes.SourceDomain
$resourceCurrentState.TargetDomainName | Should -Be $configurationData.AllNodes.TargetDomain
$resourceCurrentState.TargetDomainAdministratorCredential.UserName | Should -Be $configurationData.AllNodes.TargetUserName
$resourceCurrentState.TrustType | Should -BeNullOrEmpty
$resourceCurrentState.TrustDirection | Should -BeNullOrEmpty
}

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

$configurationName = "$($script:dscResourceName)_CreateForestTrust_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
{
$configurationParameters = @{
OutputPath = $TestDrive
# The variable $ConfigurationData was dot-sourced above.
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.SourceDomainName | Should -Be $configurationData.AllNodes.SourceForest
$resourceCurrentState.TargetDomainName | Should -Be $configurationData.AllNodes.TargetForest
$resourceCurrentState.TargetDomainAdministratorCredential.UserName | Should -Be $configurationData.AllNodes.TargetUserName
$resourceCurrentState.TrustType | Should -Be 'Forest'
$resourceCurrentState.TrustDirection | Should -Be 'Outbound'
}

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

$configurationName = "$($script:dscResourceName)_ChangeForestTrustDirection_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
{
$configurationParameters = @{
OutputPath = $TestDrive
# The variable $ConfigurationData was dot-sourced above.
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.SourceDomainName | Should -Be $configurationData.AllNodes.SourceForest
$resourceCurrentState.TargetDomainName | Should -Be $configurationData.AllNodes.TargetForest
$resourceCurrentState.TargetDomainAdministratorCredential.UserName | Should -Be $configurationData.AllNodes.TargetUserName
$resourceCurrentState.TrustType | Should -Be 'Forest'
$resourceCurrentState.TrustDirection | Should -Be 'Inbound'
}

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

$configurationName = "$($script:dscResourceName)_RemoveForestTrust_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
{
$configurationParameters = @{
OutputPath = $TestDrive
# The variable $ConfigurationData was dot-sourced above.
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.SourceDomainName | Should -Be $configurationData.AllNodes.SourceForest
$resourceCurrentState.TargetDomainName | Should -Be $configurationData.AllNodes.TargetForest
$resourceCurrentState.TargetDomainAdministratorCredential.UserName | Should -Be $configurationData.AllNodes.TargetUserName
$resourceCurrentState.TrustType | Should -BeNullOrEmpty
$resourceCurrentState.TrustDirection | Should -BeNullOrEmpty
}

It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
}
}
}
}
finally
{
#region FOOTER
Restore-TestEnvironment -TestEnvironment $TestEnvironment
#endregion
}

0 comments on commit e0bc9ec

Please sign in to comment.