Skip to content

Commit

Permalink
Fix SqlRS and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed Aug 30, 2021
1 parent 919b3ab commit b6eb944
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 8 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- SqlSetup
- Fixed integration tests for SQL Server 2016 and SQL Server 2017.
- SqlServerDsc.Common
- Fixed so that _CredScan_ no longer reports a password false-positive ([issue #1712](https://github.com/dsccommunity/SqlServerDsc/issues/1712)).
- Fixed so that _CredScan_ no longer reports a password false-positive
([issue #1712](https://github.com/dsccommunity/SqlServerDsc/issues/1712)).
- SqlRS
- Fixed SSRS 2019 initialisation [issue #1509](https://github.com/dsccommunity/SqlServerDsc/issues/1509).
- Fixed SSRS 2019 initialization ([issue #1509](https://github.com/dsccommunity/SqlServerDsc/issues/1509)).
- Fix a problem that did not correctly evaluate the `UseSSL` property against
the current state.

## [15.1.1] - 2021-02-12

Expand Down
4 changes: 2 additions & 2 deletions source/DSCResources/DSC_SqlRS/DSC_SqlRS.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ function Set-TargetResource
#>
if ($reportingServicesData.SqlVersion -ge 15)
{
Write-Verbose -Message $script:localizedData.Restart
Write-Verbose -Message $script:localizedData.RestartToFinishInitialization

Restart-ReportingServicesService -InstanceName $InstanceName -WaitTime 30

Expand Down Expand Up @@ -503,7 +503,7 @@ function Set-TargetResource
Invoke-RsCimMethod @invokeRsCimMethodParameters
}

if ( $PSBoundParameters.ContainsKey('UseSsl') -and $UseSsl -ne $currentConfig.UseSsl )
if ( $PSBoundParameters.ContainsKey('UseSsl') -and $UseSsl -ne $reportingServicesData.Configuration.SecureConnectionLevel )
{
Write-Verbose -Message "Changing value for using SSL to '$UseSsl'."

Expand Down
1 change: 1 addition & 0 deletions source/DSCResources/DSC_SqlRS/en-US/DSC_SqlRS.strings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ ConvertFrom-StringData @'
TestFailedAfterSet = Test-TargetResource function returned false when Set-TargetResource function verified the desired state. This indicates that the Set-TargetResource did not correctly set set the desired state, or that the function Test-TargetResource does not correctly evaluate the desired state.
ReportingServicesNotFound = SQL Reporting Services instance '{0}' does not exist.
GetConfiguration = Get the current reporting services configuration for the instance '{0}'.
RestartToFinishInitialization = Restarting Reporting Services to finish initialization.
'@
125 changes: 121 additions & 4 deletions tests/Unit/DSC_SqlRS.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ try
Version = 15
}
)
foreach($sqlVersion in $sqlVersions)

foreach ($sqlVersion in $sqlVersions)
{
Context "When the system is not in the desired state ($($sqlVersion.VersionName))" {
Context "When configuring a named instance that are not initialized ($($sqlVersion.VersionName))" {
Expand Down Expand Up @@ -411,7 +412,15 @@ try

Assert-MockCalled -CommandName Get-CimInstance -Exactly -Times 1 -Scope It
Assert-MockCalled -CommandName Invoke-Sqlcmd -Exactly -Times 2 -Scope It
Assert-MockCalled -CommandName Restart-ReportingServicesService -Exactly -Times 1 -Scope It

if ($sqlVersion.Version -eq 15)
{
Assert-MockCalled -CommandName Restart-ReportingServicesService -Exactly -Times 2 -Scope It
}
else
{
Assert-MockCalled -CommandName Restart-ReportingServicesService -Exactly -Times 1 -Scope It
}
}

Context 'When there is no Reporting Services instance after Set-TargetResource has been called' {
Expand All @@ -437,6 +446,107 @@ try
}
}

if ($sqlVersion.Version -eq 15)
{
Context "When configuring a named instance of $($sqlVersion.VersionName) that are not initialized" {
BeforeAll {
$script:alreadyCalledGetReportingServicesData = $false
$script:mockDynamicIsInitialized = $false
$script:mockDynamicSecureConnectionLevel = $false

Mock -CommandName Get-ReportingServicesData -MockWith {
if ($script:alreadyCalledGetReportingServicesData)
{
$script:mockDynamicIsInitialized = $true
}
else
{
$script:alreadyCalledGetReportingServicesData = $true
}

return @{
Configuration = New-Object -TypeName Microsoft.Management.Infrastructure.CimInstance -ArgumentList @(
'MSReportServer_ConfigurationSetting'
'root/Microsoft/SQLServer/ReportServer/RS_SQL2019/v15/Admin'
) | Add-Member -MemberType NoteProperty -Name 'DatabaseServerName' -Value "$mockReportingServicesDatabaseServerName\$mockReportingServicesDatabaseNamedInstanceName" -PassThru |
Add-Member -MemberType NoteProperty -Name 'IsInitialized' -Value $script:mockDynamicIsInitialized -PassThru |
Add-Member -MemberType NoteProperty -Name 'InstanceName' -Value $mockNamedInstanceName -PassThru |
Add-Member -MemberType NoteProperty -Name 'VirtualDirectoryReportServer' -Value $mockVirtualDirectoryReportServerName -PassThru |
Add-Member -MemberType NoteProperty -Name 'VirtualDirectoryReportManager' -Value $mockVirtualDirectoryReportManagerName -PassThru |
Add-Member -MemberType NoteProperty -Name 'SecureConnectionLevel' -Value $script:mockDynamicSecureConnectionLevel -PassThru -Force
ReportsApplicationName = 'ReportServerWebApp'
SqlVersion = $sqlVersion.Version
}
}

Mock -CommandName Test-TargetResource -MockWith {
return $true
}

$defaultParameters = @{
InstanceName = $mockNamedInstanceName
DatabaseServerName = $mockReportingServicesDatabaseServerName
DatabaseInstanceName = $mockReportingServicesDatabaseNamedInstanceName
UseSsl = $false
}
}

BeforeEach {
Mock -CommandName Get-CimInstance `
-MockWith $mockGetCimInstance_Language `
-ParameterFilter $mockGetCimInstance_OperatingSystem_ParameterFilter
}

It 'Should configure Reporting Service without throwing an error' {
{ Set-TargetResource @defaultParameters } | Should -Not -Throw

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'SetSecureConnectionLevel'
} -Exactly -Times 0 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'RemoveURL'
} -Exactly -Times 0 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'InitializeReportServer'
} -Exactly -Times 0 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'SetDatabaseConnection'
} -Exactly -Times 1 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'GenerateDatabaseRightsScript'
} -Exactly -Times 1 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'GenerateDatabaseCreationScript'
} -Exactly -Times 1 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'SetVirtualDirectory' -and $Arguments.Application -eq $mockReportServerApplicationName
} -Exactly -Times 1 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'SetVirtualDirectory' -and $Arguments.Application -eq $mockReportsApplicationName
} -Exactly -Times 1 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportServerApplicationName
} -Exactly -Times 1 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportsApplicationName
} -Exactly -Times 1 -Scope It

Assert-MockCalled -CommandName Get-CimInstance -Exactly -Times 1 -Scope It
Assert-MockCalled -CommandName Invoke-Sqlcmd -Exactly -Times 2 -Scope It
Assert-MockCalled -CommandName Restart-ReportingServicesService -Exactly -Times 1 -Scope It
}
}
}

Context "When configuring a named instance that are already initialized ($($sqlVersion.VersionName))" {
BeforeAll {
$mockDynamicIsInitialized = $true
Expand Down Expand Up @@ -697,8 +807,15 @@ try

Assert-MockCalled -CommandName Get-CimInstance -Exactly -Times 1 -Scope It
Assert-MockCalled -CommandName Invoke-Sqlcmd -Exactly -Times 2 -Scope It
Assert-MockCalled -CommandName Restart-ReportingServicesService -Exactly -Times 1 -Scope It
}

if ($sqlVersion.Version -eq 15)
{
Assert-MockCalled -CommandName Restart-ReportingServicesService -Exactly -Times 2 -Scope It
}
else
{
Assert-MockCalled -CommandName Restart-ReportingServicesService -Exactly -Times 1 -Scope It
} }
}
}
}
Expand Down

0 comments on commit b6eb944

Please sign in to comment.