diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a9402fd1..efc8701ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 installation where the database engine is not installed. - `SqlRS` - Test renamed to `When Reports virtual directory is different` so it is more correct and not a duplicate + - Fixed issue of configuring reporting services ([issue #1868](https://github.com/dsccommunity/SqlServerDsc/issues/1868)). ## [16.1.0] - 2023-02-28 diff --git a/source/DSCResources/DSC_SqlRS/DSC_SqlRS.psm1 b/source/DSCResources/DSC_SqlRS/DSC_SqlRS.psm1 index c05055d9b..6022f6461 100644 --- a/source/DSCResources/DSC_SqlRS/DSC_SqlRS.psm1 +++ b/source/DSCResources/DSC_SqlRS/DSC_SqlRS.psm1 @@ -953,26 +953,48 @@ function Test-TargetResource $result = $false } - $compareParameters = @{ - ReferenceObject = $currentConfig.ReportServerReservedUrl - DifferenceObject = $ReportServerReservedUrl - } - - if (($null -ne $ReportServerReservedUrl) -and ($null -ne (Compare-Object @compareParameters))) + if ($PSBoundParameters.ContainsKey('ReportServerReservedUrl')) { - Write-Verbose -Message "Report server reserved URLs on $DatabaseServerName\$DatabaseInstanceName are $($currentConfig.ReportServerReservedUrl -join ', '), should be $($ReportServerReservedUrl -join ', ')." - $result = $false - } + if ($null -eq $currentConfig.ReportServerReservedUrl) + { + Write-Verbose -Message "Report server reserved URLs on $DatabaseServerName\$DatabaseInstanceName are missing, should be $($ReportServerReservedUrl -join ', ')." + $result = $false + } + else + { + $compareParameters = @{ + ReferenceObject = $currentConfig.ReportServerReservedUrl + DifferenceObject = $ReportServerReservedUrl + } - $compareParameters = @{ - ReferenceObject = $currentConfig.ReportsReservedUrl - DifferenceObject = $ReportsReservedUrl + if ($null -ne (Compare-Object @compareParameters)) + { + Write-Verbose -Message "Report server reserved URLs on $DatabaseServerName\$DatabaseInstanceName are $($currentConfig.ReportServerReservedUrl -join ', '), should be $($ReportServerReservedUrl -join ', ')." + $result = $false + } + } } - if (($null -ne $ReportsReservedUrl) -and ($null -ne (Compare-Object @compareParameters))) + if ($PSBoundParameters.ContainsKey('ReportsReservedUrl')) { - Write-Verbose -Message "Reports reserved URLs on $DatabaseServerName\$DatabaseInstanceName are $($currentConfig.ReportsReservedUrl -join ', ')), should be $($ReportsReservedUrl -join ', ')." - $result = $false + if ($null -eq $currentConfig.ReportsReservedUrl) + { + Write-Verbose -Message "Reports reserved URLs on $DatabaseServerName\$DatabaseInstanceName are missing, should be $($ReportsReservedUrl -join ', ')." + $result = $false + } + else + { + $compareParameters = @{ + ReferenceObject = $currentConfig.ReportsReservedUrl + DifferenceObject = $ReportsReservedUrl + } + + if ($null -ne (Compare-Object @compareParameters)) + { + Write-Verbose -Message "Reports reserved URLs on $DatabaseServerName\$DatabaseInstanceName are $($currentConfig.ReportsReservedUrl -join ', ')), should be $($ReportsReservedUrl -join ', ')." + $result = $false + } + } } if ($PSBoundParameters.ContainsKey('UseSsl') -and $UseSsl -ne $currentConfig.UseSsl) diff --git a/tests/Unit/DSC_SqlRS.Tests.ps1 b/tests/Unit/DSC_SqlRS.Tests.ps1 index 9c70eeab9..81c270cdd 100644 --- a/tests/Unit/DSC_SqlRS.Tests.ps1 +++ b/tests/Unit/DSC_SqlRS.Tests.ps1 @@ -1105,6 +1105,62 @@ Describe 'SqlRS\Test-TargetResource' -Tag 'Test' { } } + Context 'When current Report Server reserved URL is $null' { + BeforeAll { + Mock -CommandName Get-TargetResource -MockWith { + return @{ + IsInitialized = $false + ReportServerReservedUrl = $null + } + } + } + + It 'Should return state as not in desired state' { + InModuleScope -ScriptBlock { + Set-StrictMode -Version 1.0 + + $testParameters = @{ + InstanceName = 'INSTANCE' + DatabaseServerName = 'DBSERVER' + DatabaseInstanceName = 'DBINSTANCE' + ReportServerReservedUrl = 'ReportServer_SQL2016' + } + + $resultTestTargetResource = Test-TargetResource @testParameters + + $resultTestTargetResource | Should -BeFalse + } + } + } + + Context 'When current Reports reserved URL is $null' { + BeforeAll { + Mock -CommandName Get-TargetResource -MockWith { + return @{ + IsInitialized = $false + ReportsReservedUrl = $null + } + } + } + + It 'Should return state as not in desired state' { + InModuleScope -ScriptBlock { + Set-StrictMode -Version 1.0 + + $testParameters = @{ + InstanceName = 'INSTANCE' + DatabaseServerName = 'DBSERVER' + DatabaseInstanceName = 'DBINSTANCE' + ReportsReservedUrl = 'Reports_SQL2016' + } + + $resultTestTargetResource = Test-TargetResource @testParameters + + $resultTestTargetResource | Should -BeFalse + } + } + } + Context 'When Report Server virtual directory is different' { BeforeAll { Mock -CommandName Get-TargetResource -MockWith {