From e47deef4129aca91618cead99d9bb7361997cb94 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Sep 2025 10:23:30 +0000 Subject: [PATCH 1/3] Initial plan From 15242cba36ddef84d1ddd2f8674ea23308eec15c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Sep 2025 10:37:59 +0000 Subject: [PATCH 2/3] Add integration test for ConvertTo-SqlDscEditionName command Co-authored-by: johlju <7189721+johlju@users.noreply.github.com> --- CHANGELOG.md | 3 + azure-pipelines.yml | 1 + ...To-SqlDscEditionName.Integration.Tests.ps1 | 158 ++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 tests/Integration/Commands/ConvertTo-SqlDscEditionName.Integration.Tests.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index b224ca2cbc..bfc2b6af98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,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). ### Fixed diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 103503d7d8..bb9ae8e1c7 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -298,6 +298,7 @@ stages: 'tests/Integration/Commands/Test-SqlDscConfigurationOption.Integration.Tests.ps1' 'tests/Integration/Commands/Get-SqlDscManagedComputerInstance.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..c17c6ebc7c --- /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 build" 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 + } + } +} \ No newline at end of file From 5c0ae9bca309be905c090d84a933b8af6720f567 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 19 Sep 2025 17:50:02 +0200 Subject: [PATCH 3/3] Fix dependency message in ConvertTo-SqlDscEditionName integration test and update README with command prerequisites --- .../ConvertTo-SqlDscEditionName.Integration.Tests.ps1 | 4 ++-- tests/Integration/Commands/README.md | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Integration/Commands/ConvertTo-SqlDscEditionName.Integration.Tests.ps1 b/tests/Integration/Commands/ConvertTo-SqlDscEditionName.Integration.Tests.ps1 index c17c6ebc7c..178f7180ab 100644 --- a/tests/Integration/Commands/ConvertTo-SqlDscEditionName.Integration.Tests.ps1 +++ b/tests/Integration/Commands/ConvertTo-SqlDscEditionName.Integration.Tests.ps1 @@ -19,7 +19,7 @@ BeforeDiscovery { } catch [System.IO.FileNotFoundException] { - throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.' + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first.' } } @@ -155,4 +155,4 @@ Describe 'ConvertTo-SqlDscEditionName' -Tag @('Integration_SQL2017', 'Integratio { ConvertTo-SqlDscEditionName -Id 4294967295 -ErrorAction 'Stop' } | Should -Not -Throw } } -} \ No newline at end of file +} diff --git a/tests/Integration/Commands/README.md b/tests/Integration/Commands/README.md index 768f7bfa99..9743877063 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 | - | - | - Install-SqlDscServer | 1 | 0 (Prerequisites) | - | DSCSQLTEST instance Connect-SqlDscDatabaseEngine | 1 | 0 (Prerequisites) | DSCSQLTEST | - Assert-SqlDscLogin | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | -