Skip to content

Commit

Permalink
Updated Per PR comments and Updated Pester
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffotterpohl committed Jun 24, 2020
1 parent 3609778 commit 948d3be
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ function Set-TargetResource

if ($SourceDistributionPoint)
{
if ($SourceDistributionPoint.SourceDP.Contains($SiteServerName))
{
throw ($script:localizedData.SourceDPSiteServer -f $SiteServerName)
}

if ($state.SourceDistributionPoint)
{
$comparesParam = @{
Expand Down Expand Up @@ -294,6 +299,11 @@ function Test-TargetResource

if ($SourceDistributionPoint)
{
if ($SourceDistributionPoint.SourceDP.Contains($SiteServerName))
{
Write-Warning -Message ($script:localizedData.SourceDPSiteServer -f $SiteServerName)
}

if ($state.SourceDistributionPoint)
{
$comparesParam = @{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ ConvertFrom-StringData @'
SourceDPMatch = MATCH: The settings is present {0} and {1}.
SourceDPMissing = NOTMATCH: The setting is missing {0} and {1}.
SourceDPExtra = NOTMATCH: The setting is extra {0} and {1}.
InvalidConfig = EnablePullDP is being set to false or is currently false and can not specify a SourceDistributionPoints, set to enable of remove SourceDistributionPoints from the configuration.
PullDPEnabledThrow = When enabling a Pull DP SourceDistributionPoints must be specified.
InvalidConfig = EnablePullDP is being set to false or is currently false and can not specify a SourceDistributionPoint, set to enable of remove SourceDistributionPoint from the configuration.
PullDPEnabledThrow = When enabling a Pull DP SourceDistributionPoint must be specified.
EnablePullDP = Setting EnablePullDP to true.
SourceDPMismatch = SourceDistributionPoints do not match setting to desired state.
SourceDPMismatch = SourceDistributionPoint do not match setting to desired state.
SourceDPSiteServer = You can not specify the Pull DP {0} as a SourceDistributionPoint.
'@
69 changes: 60 additions & 9 deletions tests/Unit/CMPullDistributionPoint.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,34 @@ try
SourceDistributionPoint = $getSourceDPReturn
}

$invalidConfig = 'EnablePullDP is being set to false or is currently false and can not specify a sourcedistribution point, set to enable of remove SourceDistributionPoint from the configuration.'

$invalidConfig = 'EnablePullDP is being set to false or is currently false and can not specify a SourceDistributionPoint, set to enable of remove SourceDistributionPoint from the configuration.'
$dpRoleAbsent = 'The Distribution Point role on DP01.contoso.com is not installed, run DSC_CMDistibutionPoint to install the role.'
$pullDPEnableNoSource = 'When enabling a Pull DP SourceDistributionPoint must be specified.'
$sourceDPSiteServer = 'You can not specify the Pull DP DP01.contoso.com as a SourceDistributionPoint.'

$inputInvalid = @{
SiteCode = 'Lab'
SiteServerName = 'DP01.contoso.com'
EnablePullDP = $true
}

$pullDPEnableNoSource = 'When enabling a Pull DP sourceDistribution Point must be specified.'
$inputMatchSourceAndSite = @(
(New-CimInstance -ClassName DSC_CMPullDistributionPointSourceDP `
-Namespace root/microsoft/Windows/DesiredStateConfiguration `
-Property @{
'SourceDP' = 'DP01.contoso.com'
'DPRank' = '1'
} `
-ClientOnly
)
)

$inputMatchingSourceAndSite = @{
SiteCode = 'Lab'
SiteServerName = 'DP01.contoso.com'
EnablePullDP = $true
SourceDistributionPoint = $inputMatchSourceAndSite
}
}

It 'Should throw and call expected commands when distribution point role is not installed' {
Expand Down Expand Up @@ -313,6 +330,16 @@ try
Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It
Assert-MockCalled Set-CMDistributionPoint -Exactly -Times 0 -Scope It
}

It 'Should throw and call expected commands Source Distribution Points contains SiteServerName' {
Mock -CommandName Get-TargetResource -MockWith { $getTargetReturn }

{ Set-TargetResource @inputMatchingSourceAndSite } | Should -Throw -ExpectedMessage $sourceDPSiteServer
Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It
Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It
Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It
Assert-MockCalled Set-CMDistributionPoint -Exactly -Times 0 -Scope It
}
}
}

Expand Down Expand Up @@ -405,43 +432,67 @@ try
SiteServerName = 'DP01.contoso.com'
EnablePullDP = $false
}

$inputMatchSourceAndSite = @(
(New-CimInstance -ClassName DSC_CMPullDistributionPointSourceDP `
-Namespace root/microsoft/Windows/DesiredStateConfiguration `
-Property @{
'SourceDP' = 'DP01.contoso.com'
'DPRank' = '1'
} `
-ClientOnly
)
)

$inputMatchingSourceAndSite = @{
SiteCode = 'Lab'
SiteServerName = 'DP01.contoso.com'
EnablePullDP = $false
SourceDistributionPoint = $inputMatchSourceAndSite
}
}

It 'Should return desired result true settings match' {
Mock -CommandName Get-TargetResource -MockWith { $getTargetReturn }
Mock -CommandName Get-TargetResource -MockWith { $getTargetReturn }

Test-TargetResource @inputMatch | Should -Be $true
}

It 'Should return desired result false when Source DP settings do not match' {
Mock -CommandName Get-TargetResource -MockWith { $getTargetReturn }
Mock -CommandName Get-TargetResource -MockWith { $getTargetReturn }

Test-TargetResource @inputSourceDPMisMatch | Should -Be $false
}

It 'Should return desired result false when Pull DP is disabled and expected enabled' {
Mock -CommandName Get-TargetResource -MockWith { $pullDPDisabled }
Mock -CommandName Get-TargetResource -MockWith { $pullDPDisabled }

Test-TargetResource @inputSourceDPMisMatch | Should -Be $false
}

It 'Should return desired result false when Pull DP is enabled and expected disabled' {
Mock -CommandName Get-TargetResource -MockWith { $getTargetReturn }
Mock -CommandName Get-TargetResource -MockWith { $getTargetReturn }

Test-TargetResource @inputAbsent | Should -Be $false
}

It 'Should return desired result false when Distribution Point role is not installed' {
Mock -CommandName Get-TargetResource -MockWith { $dpRoleNotInstalledReturn }
Mock -CommandName Get-TargetResource -MockWith { $dpRoleNotInstalledReturn }

Test-TargetResource @inputMatch | Should -Be $false
}

It 'Should return desired result true when Pull DP is disabled and expected disabled' {
Mock -CommandName Get-TargetResource -MockWith { $pullDPDisabled }
Mock -CommandName Get-TargetResource -MockWith { $pullDPDisabled }

Test-TargetResource @inputAbsent | Should -Be $true
}

It 'Should return desired result false when SourceDP does not match get return' {
Mock -CommandName Get-TargetResource -MockWith { $getTargetReturn }

Test-TargetResource @inputMatchingSourceAndSite | Should -Be $false
}
}
}
}
Expand Down

0 comments on commit 948d3be

Please sign in to comment.