|
| 1 | +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')] |
| 2 | +param () |
| 3 | + |
| 4 | +BeforeDiscovery { |
| 5 | + try |
| 6 | + { |
| 7 | + if (-not (Get-Module -Name 'DscResource.Test')) |
| 8 | + { |
| 9 | + # Assumes dependencies have been resolved, so if this module is not available, run 'noop' task. |
| 10 | + if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable)) |
| 11 | + { |
| 12 | + # Redirect all streams to $null, except the error stream (stream 2) |
| 13 | + & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null |
| 14 | + } |
| 15 | + |
| 16 | + # If the dependencies have not been resolved, this will throw an error. |
| 17 | + Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop' |
| 18 | + } |
| 19 | + } |
| 20 | + catch [System.IO.FileNotFoundException] |
| 21 | + { |
| 22 | + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first.' |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +BeforeAll { |
| 27 | + $script:moduleName = 'SqlServerDsc' |
| 28 | + |
| 29 | + Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop' |
| 30 | +} |
| 31 | + |
| 32 | +Describe 'Get-SqlDscRSPackage' { |
| 33 | + Context 'When getting package information for SQL Server Reporting Services' -Tag @('Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS') { |
| 34 | + It 'Should return the package information for SSRS' { |
| 35 | + $result = Get-SqlDscRSPackage -Package 'SSRS' -ErrorAction 'Stop' |
| 36 | + |
| 37 | + $result | Should -Not -BeNullOrEmpty |
| 38 | + $result.ProductName | Should -Be 'Microsoft SQL Server Reporting Services' |
| 39 | + $result.FileVersion | Should -Not -BeNullOrEmpty |
| 40 | + $result.ProductVersion | Should -Not -BeNullOrEmpty |
| 41 | + } |
| 42 | + |
| 43 | + It 'Should return the same result when using FilePath parameter' { |
| 44 | + # Get the install folder from the setup configuration |
| 45 | + $setupConfig = Get-SqlDscRSSetupConfiguration -InstanceName 'SSRS' -ErrorAction 'Stop' |
| 46 | + |
| 47 | + $executablePath = Join-Path -Path $setupConfig.InstallFolder -ChildPath 'RSHostingService/ReportingServicesService.exe' |
| 48 | + |
| 49 | + $result = Get-SqlDscRSPackage -FilePath $executablePath -ErrorAction 'Stop' |
| 50 | + |
| 51 | + $result | Should -Not -BeNullOrEmpty |
| 52 | + $result.ProductName | Should -Be 'Microsoft SQL Server Reporting Services' |
| 53 | + $result.FileVersion | Should -Not -BeNullOrEmpty |
| 54 | + $result.ProductVersion | Should -Not -BeNullOrEmpty |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + Context 'When getting package information for Power BI Report Server' -Tag @('Integration_PowerBI') { |
| 59 | + # cSpell: ignore PBIRS |
| 60 | + It 'Should return the package information for PBIRS' { |
| 61 | + $result = Get-SqlDscRSPackage -Package 'PBIRS' -ErrorAction 'Stop' |
| 62 | + |
| 63 | + $result | Should -Not -BeNullOrEmpty |
| 64 | + $result.ProductName | Should -Be 'Microsoft Power BI Report Server' |
| 65 | + $result.FileVersion | Should -Not -BeNullOrEmpty |
| 66 | + $result.ProductVersion | Should -Not -BeNullOrEmpty |
| 67 | + } |
| 68 | + |
| 69 | + It 'Should return the same result when using FilePath parameter' { |
| 70 | + # Get the install folder from the setup configuration |
| 71 | + $setupConfig = Get-SqlDscRSSetupConfiguration -InstanceName 'PBIRS' -ErrorAction 'Stop' |
| 72 | + |
| 73 | + $executablePath = Join-Path -Path $setupConfig.InstallFolder -ChildPath 'RSHostingService/ReportingServicesService.exe' |
| 74 | + |
| 75 | + $result = Get-SqlDscRSPackage -FilePath $executablePath -ErrorAction 'Stop' |
| 76 | + |
| 77 | + $result | Should -Not -BeNullOrEmpty |
| 78 | + $result.ProductName | Should -Be 'Microsoft Power BI Report Server' |
| 79 | + $result.FileVersion | Should -Not -BeNullOrEmpty |
| 80 | + $result.ProductVersion | Should -Not -BeNullOrEmpty |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + Context 'When getting package information for a non-existing package' -Tag @('Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS', 'Integration_PowerBI') { |
| 85 | + It 'Should throw an error when the package is not installed' { |
| 86 | + # PBIRS is not installed in the SSRS CI environment and vice versa |
| 87 | + # We can test this by checking which one is installed |
| 88 | + $ssrsInstalled = Test-SqlDscRSInstalled -InstanceName 'SSRS' |
| 89 | + |
| 90 | + if ($ssrsInstalled) |
| 91 | + { |
| 92 | + # SSRS is installed, so PBIRS should not be |
| 93 | + { Get-SqlDscRSPackage -Package 'PBIRS' -ErrorAction 'Stop' } | Should -Throw |
| 94 | + } |
| 95 | + else |
| 96 | + { |
| 97 | + # PBIRS is installed, so SSRS should not be |
| 98 | + { Get-SqlDscRSPackage -Package 'SSRS' -ErrorAction 'Stop' } | Should -Throw |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + Context 'When using Force parameter to bypass validation' -Tag @('Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS') { |
| 104 | + It 'Should return file version information for any executable with Force parameter' { |
| 105 | + # Get the install folder from the setup configuration |
| 106 | + $setupConfig = Get-SqlDscRSSetupConfiguration -InstanceName 'SSRS' -ErrorAction 'Stop' |
| 107 | + |
| 108 | + $executablePath = Join-Path -Path $setupConfig.InstallFolder -ChildPath 'RSHostingService/ReportingServicesService.exe' |
| 109 | + |
| 110 | + # Using Force should work and return the file version info |
| 111 | + $result = Get-SqlDscRSPackage -FilePath $executablePath -Force -ErrorAction 'Stop' |
| 112 | + |
| 113 | + $result | Should -Not -BeNullOrEmpty |
| 114 | + $result.FileVersion | Should -Not -BeNullOrEmpty |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + Context 'When using Force parameter to bypass validation' -Tag @('Integration_PowerBI') { |
| 119 | + It 'Should return file version information for any executable with Force parameter' { |
| 120 | + # Get the install folder from the setup configuration |
| 121 | + $setupConfig = Get-SqlDscRSSetupConfiguration -InstanceName 'PBIRS' -ErrorAction 'Stop' |
| 122 | + |
| 123 | + $executablePath = Join-Path -Path $setupConfig.InstallFolder -ChildPath 'RSHostingService/ReportingServicesService.exe' |
| 124 | + |
| 125 | + # Using Force should work and return the file version info |
| 126 | + $result = Get-SqlDscRSPackage -FilePath $executablePath -Force -ErrorAction 'Stop' |
| 127 | + |
| 128 | + $result | Should -Not -BeNullOrEmpty |
| 129 | + $result.FileVersion | Should -Not -BeNullOrEmpty |
| 130 | + } |
| 131 | + } |
| 132 | +} |
0 commit comments