diff --git a/CHANGELOG.md b/CHANGELOG.md index 62928f31c6..d77d14dbcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added integration tests for `Remove-SqlDscAudit` command to ensure it functions correctly in real environments [issue #2241](https://github.com/dsccommunity/SqlServerDsc/issues/2241). +- Added integration test for `ConvertTo-SqlDscEditionName` command to ensure + command reliability in real environments + [issue #2208](https://github.com/dsccommunity/SqlServerDsc/issues/2208). - Added integration tests for `Import-SqlDscPreferredModule` command to ensure proper module import functionality in real environments [issue #2225](https://github.com/dsccommunity/SqlServerDsc/issues/2225). diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 803bf3e77d..872e1bfcda 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -303,6 +303,7 @@ stages: 'tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1' 'tests/Integration/Commands/Get-SqlDscManagedComputerService.Integration.Tests.ps1' 'tests/Integration/Commands/Get-SqlDscServerProtocolName.Integration.Tests.ps1' + 'tests/Integration/Commands/ConvertTo-SqlDscEditionName.Integration.Tests.ps1' 'tests/Integration/Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1' 'tests/Integration/Commands/Disable-SqlDscLogin.Integration.Tests.ps1' 'tests/Integration/Commands/Enable-SqlDscLogin.Integration.Tests.ps1' diff --git a/tests/Integration/Commands/ConvertTo-SqlDscEditionName.Integration.Tests.ps1 b/tests/Integration/Commands/ConvertTo-SqlDscEditionName.Integration.Tests.ps1 new file mode 100644 index 0000000000..178f7180ab --- /dev/null +++ b/tests/Integration/Commands/ConvertTo-SqlDscEditionName.Integration.Tests.ps1 @@ -0,0 +1,158 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')] +param () + +BeforeDiscovery { + try + { + if (-not (Get-Module -Name 'DscResource.Test')) + { + # Assumes dependencies have been resolved, so if this module is not available, run 'noop' task. + if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable)) + { + # Redirect all streams to $null, except the error stream (stream 2) + & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null + } + + # If the dependencies have not been resolved, this will throw an error. + Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop' + } + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first.' + } +} + +BeforeAll { + $script:moduleName = 'SqlServerDsc' + + Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop' +} + +Describe 'ConvertTo-SqlDscEditionName' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { + BeforeAll { + Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose + + # Define expected edition mappings for validation + $script:expectedEditionMappings = @{ + 2176971986 = @{ + EditionId = 2176971986 + Edition = 'Developer' + EditionName = 'SQL Server Developer' + } + 2017617798 = @{ + EditionId = 2017617798 + Edition = 'Developer' + EditionName = 'Power BI Report Server - Developer' + } + 1369084056 = @{ + EditionId = 1369084056 + Edition = 'Evaluation' + EditionName = 'Power BI Report Server - Evaluation' + } + } + } + + Context 'When converting known EditionId values' { + It 'Should return correct mapping for SQL Server Developer edition ID (2176971986)' { + $result = ConvertTo-SqlDscEditionName -Id 2176971986 -ErrorAction 'Stop' + + $result | Should -Not -BeNullOrEmpty + $result.EditionId | Should -Be $script:expectedEditionMappings[2176971986].EditionId + $result.Edition | Should -Be $script:expectedEditionMappings[2176971986].Edition + $result.EditionName | Should -Be $script:expectedEditionMappings[2176971986].EditionName + } + + It 'Should return correct mapping for Power BI Report Server Developer edition ID (2017617798)' { + $result = ConvertTo-SqlDscEditionName -Id 2017617798 -ErrorAction 'Stop' + + $result | Should -Not -BeNullOrEmpty + $result.EditionId | Should -Be $script:expectedEditionMappings[2017617798].EditionId + $result.Edition | Should -Be $script:expectedEditionMappings[2017617798].Edition + $result.EditionName | Should -Be $script:expectedEditionMappings[2017617798].EditionName + } + + It 'Should return correct mapping for Power BI Report Server Evaluation edition ID (1369084056)' { + $result = ConvertTo-SqlDscEditionName -Id 1369084056 -ErrorAction 'Stop' + + $result | Should -Not -BeNullOrEmpty + $result.EditionId | Should -Be $script:expectedEditionMappings[1369084056].EditionId + $result.Edition | Should -Be $script:expectedEditionMappings[1369084056].Edition + $result.EditionName | Should -Be $script:expectedEditionMappings[1369084056].EditionName + } + } + + Context 'When converting unknown EditionId values' { + It 'Should return Unknown for an unknown EditionId (99999)' { + $result = ConvertTo-SqlDscEditionName -Id 99999 -ErrorAction 'Stop' + + $result | Should -Not -BeNullOrEmpty + $result.EditionId | Should -Be 99999 + $result.Edition | Should -Be 'Unknown' + $result.EditionName | Should -Be 'Unknown' + } + + It 'Should return Unknown for another unknown EditionId (0)' { + $result = ConvertTo-SqlDscEditionName -Id 0 -ErrorAction 'Stop' + + $result | Should -Not -BeNullOrEmpty + $result.EditionId | Should -Be 0 + $result.Edition | Should -Be 'Unknown' + $result.EditionName | Should -Be 'Unknown' + } + + It 'Should return Unknown for a large unknown EditionId (4294967295)' { + $result = ConvertTo-SqlDscEditionName -Id 4294967295 -ErrorAction 'Stop' + + $result | Should -Not -BeNullOrEmpty + $result.EditionId | Should -Be 4294967295 + $result.Edition | Should -Be 'Unknown' + $result.EditionName | Should -Be 'Unknown' + } + } + + Context 'When validating output object properties' { + It 'Should return PSCustomObject with correct properties' { + $result = ConvertTo-SqlDscEditionName -Id 2176971986 -ErrorAction 'Stop' + + $result | Should -BeOfType ([System.Management.Automation.PSCustomObject]) + $result.PSObject.Properties.Name | Should -Contain 'EditionId' + $result.PSObject.Properties.Name | Should -Contain 'Edition' + $result.PSObject.Properties.Name | Should -Contain 'EditionName' + $result.PSObject.Properties.Name | Should -HaveCount 3 + } + + It 'Should return consistent object types for all EditionId values' { + $resultKnown = ConvertTo-SqlDscEditionName -Id 2176971986 -ErrorAction 'Stop' + $resultUnknown = ConvertTo-SqlDscEditionName -Id 99999 -ErrorAction 'Stop' + + $resultKnown.GetType() | Should -Be $resultUnknown.GetType() + + # Verify both have the same property structure + $resultKnown.PSObject.Properties.Name | Should -Be $resultUnknown.PSObject.Properties.Name + } + + It 'Should return EditionId as UInt32 type' { + $result = ConvertTo-SqlDscEditionName -Id 2176971986 -ErrorAction 'Stop' + + $result.EditionId | Should -BeOfType ([System.UInt32]) + } + + It 'Should return Edition and EditionName as String types' { + $result = ConvertTo-SqlDscEditionName -Id 2176971986 -ErrorAction 'Stop' + + $result.Edition | Should -BeOfType ([System.String]) + $result.EditionName | Should -BeOfType ([System.String]) + } + } + + Context 'When testing parameter validation' { + It 'Should accept minimum UInt32 value (0)' { + { ConvertTo-SqlDscEditionName -Id 0 -ErrorAction 'Stop' } | Should -Not -Throw + } + + It 'Should accept maximum UInt32 value (4294967295)' { + { ConvertTo-SqlDscEditionName -Id 4294967295 -ErrorAction 'Stop' } | Should -Not -Throw + } + } +} diff --git a/tests/Integration/Commands/README.md b/tests/Integration/Commands/README.md index 2e3c6a5f06..61c279aa2b 100644 --- a/tests/Integration/Commands/README.md +++ b/tests/Integration/Commands/README.md @@ -41,6 +41,7 @@ to each other. Dependencies are made to speed up the testing.** Command | Run order # | Depends on # | Use instance | Creates persistent objects --- | --- | --- | --- | --- Prerequisites | 0 | - | - | Sets up dependencies +ConvertTo-SqlDscEditionName | 0 | - | - | - Import-SqlDscPreferredModule | 0 | - | - | - Install-SqlDscServer | 1 | 0 (Prerequisites) | - | DSCSQLTEST instance Connect-SqlDscDatabaseEngine | 1 | 0 (Prerequisites) | DSCSQLTEST | -