|
| 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 a non-existing file' -Tag @('Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS', 'Integration_PowerBI') { |
| 34 | + It 'Should throw an error when the file does not exist' { |
| 35 | + { Get-SqlDscRSPackage -FilePath 'C:\NonExistent\SQLServerReportingServices.exe' -ErrorAction 'Stop' } | Should -Throw |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + Context 'When getting package information for SQL Server Reporting Services' -Tag @('Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS') { |
| 40 | + BeforeAll { |
| 41 | + $script:temporaryFolder = Get-TemporaryFolder |
| 42 | + $script:reportingServicesExecutable = Join-Path -Path $script:temporaryFolder -ChildPath 'SQLServerReportingServices.exe' |
| 43 | + } |
| 44 | + |
| 45 | + It 'Should return the package information for SSRS' { |
| 46 | + $result = Get-SqlDscRSPackage -FilePath $script:reportingServicesExecutable -ErrorAction 'Stop' |
| 47 | + |
| 48 | + $result | Should -Not -BeNullOrEmpty |
| 49 | + $result.ProductName | Should -Be 'Microsoft SQL Server Reporting Services' |
| 50 | + $result.FileVersion | Should -Not -BeNullOrEmpty |
| 51 | + $result.ProductVersion | Should -Not -BeNullOrEmpty |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + # cSpell: ignore PBIRS |
| 56 | + Context 'When getting package information for Power BI Report Server' -Tag @('Integration_PowerBI') { |
| 57 | + BeforeAll { |
| 58 | + $script:temporaryFolder = Get-TemporaryFolder |
| 59 | + $script:powerBIReportServerExecutable = Join-Path -Path $script:temporaryFolder -ChildPath 'PowerBIReportServer.exe' |
| 60 | + } |
| 61 | + |
| 62 | + It 'Should return the package information for PBIRS' { |
| 63 | + $result = Get-SqlDscRSPackage -FilePath $script:powerBIReportServerExecutable -ErrorAction 'Stop' |
| 64 | + |
| 65 | + $result | Should -Not -BeNullOrEmpty |
| 66 | + $result.ProductName | Should -Be 'Microsoft Power BI Report Server' |
| 67 | + $result.FileVersion | Should -Not -BeNullOrEmpty |
| 68 | + $result.ProductVersion | Should -Not -BeNullOrEmpty |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + Context 'When file has an invalid product name' -Tag @('Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS', 'Integration_PowerBI') { |
| 73 | + It 'Should throw an error without Force parameter' { |
| 74 | + # Use an executable that exists but has a different product name |
| 75 | + { Get-SqlDscRSPackage -FilePath 'C:\Windows\System32\notepad.exe' -ErrorAction 'Stop' } | Should -Throw |
| 76 | + } |
| 77 | + |
| 78 | + It 'Should return version information with Force parameter' { |
| 79 | + $result = Get-SqlDscRSPackage -FilePath 'C:\Windows\System32\notepad.exe' -Force -ErrorAction 'Stop' |
| 80 | + |
| 81 | + $result | Should -Not -BeNullOrEmpty |
| 82 | + $result.FileVersion | Should -Not -BeNullOrEmpty |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + Context 'When using Force parameter to bypass validation' -Tag @('Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS') { |
| 87 | + BeforeAll { |
| 88 | + $script:temporaryFolder = Get-TemporaryFolder |
| 89 | + $script:reportingServicesExecutable = Join-Path -Path $script:temporaryFolder -ChildPath 'SQLServerReportingServices.exe' |
| 90 | + } |
| 91 | + |
| 92 | + It 'Should return file version information with Force parameter' { |
| 93 | + $result = Get-SqlDscRSPackage -FilePath $script:reportingServicesExecutable -Force -ErrorAction 'Stop' |
| 94 | + |
| 95 | + $result | Should -Not -BeNullOrEmpty |
| 96 | + $result.FileVersion | Should -Not -BeNullOrEmpty |
| 97 | + } |
| 98 | + } |
| 99 | +} |
0 commit comments