-
Notifications
You must be signed in to change notification settings - Fork 227
Install-SqlDscServer: Move parameter sets to seperate commands
#2399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Install-SqlDscServer: Move parameter sets to seperate commands
#2399
Conversation
WalkthroughThis PR extracts multiple setup actions from Install-SqlDscServer into five new public cmdlets (Initialize-SqlDscImage, Update-SqlDscServer, Update-SqlDscServerEdition, Initialize-SqlDscFailoverCluster, Install-SqlDscFailoverCluster), removes the corresponding parameter sets from Install-SqlDscServer (BREAKING CHANGE), and adds/updates unit and integration tests plus CI entries. Each new cmdlet forwards parameters to Invoke-SetupAction. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Cmdlet as New Cmdlet
participant Invoker as Invoke-SetupAction
participant SetupProc as Start-SqlSetupProcess / setup.exe
rect rgb(240,248,255)
User->>Cmdlet: Invoke cmdlet with parameters
Cmdlet->>Cmdlet: Validate parameters (CmdletBinding, ValidateSet)
end
rect rgb(240,255,240)
Cmdlet->>Invoker: Invoke-SetupAction -<Action> `@PSBoundParameters`
Invoker->>SetupProc: Start-SqlSetupProcess (constructed args)
SetupProc-->>Invoker: Exit code / logs
Invoker-->>Cmdlet: Return result / errors
Cmdlet-->>User: Output or throw on error
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Pre-merge checks✅ Passed checks (5 passed)
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (9)**/*.[Tt]ests.ps1📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-pester.instructions.md)
Files:
⚙️ CodeRabbit configuration file
Files:
tests/Unit/Public/*.[Tt]ests.ps1📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-pester.instructions.md)
Files:
tests/Unit/**/*.Tests.ps1📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines.instructions.md)
Files:
**/*.{ps1,psm1,psd1}📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-powershell.instructions.md)
Files:
tests/[Uu]nit/**/*.[Tt]ests.ps1📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md)
Files:
⚙️ CodeRabbit configuration file
Files:
**/Public/**/*.ps1📄 CodeRabbit inference engine (.github/instructions/SqlServerDsc-guidelines.instructions.md)
Files:
**/tests/Unit/**/*.ps1📄 CodeRabbit inference engine (.github/instructions/SqlServerDsc-guidelines.instructions.md)
Files:
**⚙️ CodeRabbit configuration file
Files:
{**/*.ps1,**/*.psm1,**/*.psd1}⚙️ CodeRabbit configuration file
Files:
🧠 Learnings (39)📓 Common learnings📚 Learning: 2025-12-30T15:15:36.079ZApplied to files:
📚 Learning: 2026-01-01T11:57:15.286ZApplied to files:
📚 Learning: 2025-11-27T17:59:27.205ZApplied to files:
📚 Learning: 2025-12-30T15:15:25.261ZApplied to files:
📚 Learning: 2025-12-30T15:15:36.079ZApplied to files:
📚 Learning: 2025-11-27T17:59:27.205ZApplied to files:
📚 Learning: 2025-11-27T17:59:27.205ZApplied to files:
📚 Learning: 2026-01-01T11:57:15.286ZApplied to files:
📚 Learning: 2025-11-27T17:59:27.205ZApplied to files:
📚 Learning: 2025-12-30T15:15:36.079ZApplied to files:
📚 Learning: 2025-11-27T17:59:27.205ZApplied to files:
📚 Learning: 2025-12-30T15:15:36.079ZApplied to files:
📚 Learning: 2025-11-27T17:59:27.205ZApplied to files:
📚 Learning: 2025-11-27T17:59:27.205ZApplied to files:
📚 Learning: 2025-11-27T17:59:27.205ZApplied to files:
📚 Learning: 2025-11-27T17:59:27.205ZApplied to files:
📚 Learning: 2025-11-27T17:59:27.205ZApplied to files:
📚 Learning: 2025-11-27T17:59:27.205ZApplied to files:
📚 Learning: 2025-12-24T18:09:36.332ZApplied to files:
📚 Learning: 2025-11-27T17:59:27.205ZApplied to files:
📚 Learning: 2025-11-27T17:59:27.205ZApplied to files:
📚 Learning: 2025-11-27T17:59:27.205ZApplied to files:
📚 Learning: 2025-11-27T17:59:27.205ZApplied to files:
📚 Learning: 2025-08-17T10:13:30.079ZApplied to files:
📚 Learning: 2026-01-01T11:57:15.286ZApplied to files:
📚 Learning: 2025-10-10T14:01:42.703ZApplied to files:
📚 Learning: 2025-11-27T18:56:46.759ZApplied to files:
📚 Learning: 2025-12-30T15:15:25.261ZApplied to files:
📚 Learning: 2025-08-09T19:29:36.323ZApplied to files:
📚 Learning: 2025-12-24T18:09:36.332ZApplied to files:
📚 Learning: 2026-01-01T11:57:15.286ZApplied to files:
📚 Learning: 2025-11-27T18:00:35.078ZApplied to files:
📚 Learning: 2025-12-24T18:09:36.332ZApplied to files:
📚 Learning: 2025-12-24T18:09:36.332ZApplied to files:
📚 Learning: 2025-12-24T18:09:36.332ZApplied to files:
📚 Learning: 2025-12-24T18:09:36.332ZApplied to files:
📚 Learning: 2025-08-17T10:15:48.194ZApplied to files:
📚 Learning: 2025-10-11T08:18:26.062ZApplied to files:
🪛 Gitleaks (8.30.0)tests/Unit/Public/Update-SqlDscServer.Tests.ps1[high] 186-186: Detected a Generic API Key, potentially exposing access to various services and sensitive operations. (generic-api-key) tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1[high] 233-233: Detected a Generic API Key, potentially exposing access to various services and sensitive operations. (generic-api-key) ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
🔇 Additional comments (10)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (6)
source/Public/Update-SqlDscServerEdition.ps1 (1)
1-104: Edition-upgrade wrapper looks correct; only optional tightening of string validationThe cmdlet is well-shaped as a thin wrapper: comment-based help is complete, naming follows the
{Verb}-SqlDsc{Noun}pattern, mandatory parameters cover the expected EditionUpgrade surface, and delegating toInvoke-SetupAction -EditionUpgrade @PSBoundParameterskeeps behavior consistent with existing setup commands. TheSupportsShouldProcess+ suppression attribute approach is also aligned with the existing pattern whereInvoke-SetupActionowns the actualShouldProcesslogic. As per coding guidelines, this satisfies the state‑changing command requirements.If you want to harden it slightly, consider adding
ValidateNotNullOrEmptyon the mandatory string parameters (MediaPath,InstanceName,ProductKey) to fail fast on empty values before they reach setup, but this is purely optional givenInvoke-SetupActionand underlying setup already perform validation.CHANGELOG.md (1)
145-174: Changelog entries accurately describe the new commands and breaking changeThe new bullets under Added and the BREAKING CHANGE note under Changed clearly document the new command surface (
Initialize-SqlDscImage,Update-SqlDscServerEdition,Update-SqlDscServer,Initialize-SqlDscFailoverCluster,Install-SqlDscFailoverCluster) and the removal of the corresponding parameter sets fromInstall-SqlDscServer, with correctly formatted issue links for #2393–#2396. This aligns with the Keep a Changelog layout and the requirement to update the Unreleased section.For future changes, you might consider consolidating closely related “Added” entries into one or two bullets (e.g., one bullet listing all new setup commands) to better match the guideline of keeping each change type brief in the Unreleased section, but the current structure is still clear and consistent with existing content.
source/Public/Initialize-SqlDscFailoverCluster.ps1 (1)
1-347: Cluster‑prep cmdlet is well‑structured; optional hardening on mandatory string paramsThis wrapper around
Invoke-SetupAction -PrepareFailoverClusterlooks solid: it follows the{Verb}-SqlDsc{Noun}naming convention, has full comment-based help, uses[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]with the standard PSShouldProcess suppression, and forwards all bound parameters (including-WhatIfand-Force) via@PSBoundParametersso that centralized setup logic and ShouldProcess handling inInvoke-SetupActioncan be reused. TheFeaturesand other enum-like parameters are guarded withValidateSet, which gives good up-front validation for common mistakes. As per coding guidelines and the retrieved learnings for state-changing commands, this implementation matches the expected pattern.If you want to tighten things slightly, consider adding
ValidateNotNullOrEmptyon the key mandatory strings (MediaPath,InstanceName) to fail early on empty values before setup is invoked; this is a non-breaking, optional enhancement since downstream validation already exists in the setup pipeline.tests/Integration/Commands/Install-SqlDscFailoverCluster.Integration.Tests.ps1 (2)
44-51: Consider moving -Skip to Context or It level for consistency.Other integration tests in this PR apply
-Skipat theItblock level, not at theDescribelevel. Consider restructuring to match the pattern used in other new integration tests for consistency.Additionally, the placeholder test
$true | Should -BeTruedoesn't add value. Consider either removing it or restructuring similar to the other integration tests with a skippedItblock containing actual test logic.
78-80: AvoidShould -Not -Throwpattern in commented template.Per coding guidelines, tests should not use
Should -Not -Throw. Instead, invoke commands directly—if they throw, the test fails. When this template is uncommented for local testing, it should follow the pattern used in other tests (direct invocation with try/catch for diagnostics).source/Public/Update-SqlDscServer.ps1 (1)
62-64: Inconsistent parameter documentation pattern.The
AllowDqRemovalparameter includes a full description, while all other parameters defer to the .NOTES section. For consistency, either document all parameters fully or apply the same "See the notes section" pattern toAllowDqRemovalas well.🔎 Proposed fix for consistency
.PARAMETER AllowDqRemoval - Specifies whether to allow removal of Data Quality (DQ) Services during - upgrade to SQL Server 2025 (17.x) and later versions. + See the notes section for more information.
tests/Integration/Commands/Install-SqlDscFailoverCluster.Integration.Tests.ps1
Outdated
Show resolved
Hide resolved
tests/Integration/Commands/Install-SqlDscFailoverCluster.Integration.Tests.ps1
Outdated
Show resolved
Hide resolved
…ine setup and remove unnecessary skip flags
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2399 +/- ##
=====================================
Coverage 94% 94%
=====================================
Files 186 191 +5
Lines 10246 10251 +5
=====================================
+ Hits 9641 9646 +5
Misses 605 605
🚀 New features to boost your workflow:
|
… tests for clarity
… improved clarity
…Server tests for improved accuracy
…ServerEdition tests for improved clarity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (5)
tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1 (2)
50-74: Use consistent variable casing for ForEach properties.Line 59 uses
$mockParameterSetName(lowercase) while line 72 uses$MockParameterSetName(uppercase). For consistency and readability, use the same casing as the hashtable key throughout.🔎 Suggested consistency fix
$result = (Get-Command -Name 'Update-SqlDscServerEdition').ParameterSets | Where-Object -FilterScript { - $_.Name -eq $mockParameterSetName + $_.Name -eq $MockParameterSetName } | Select-Object -Property @(
140-179: Consider adding test coverage for the Timeout parameter.The parameter set includes a
Timeoutparameter (line 54), but it's not tested in this optional parameters section. While not critical, adding test coverage for all optional parameters improves completeness.💡 Suggested test addition
Add this test case to the
-ForEacharray starting at line 140:@{ MockParameterName = 'Timeout' MockParameterValue = 600 MockExpectedRegEx = '\/TIMEOUT=600\b' }tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1 (2)
146-146: Consider using 'mock' prefix for test data variables.For consistency with
$mockDefaultParameters(line 93), consider renaming$initializeSqlDscImageParametersto$mockInitializeSqlDscImageParametersat lines 146 and 231.🔎 Proposed refactor for consistency
- $initializeSqlDscImageParameters = @{ + $mockInitializeSqlDscImageParameters = @{ AcceptLicensingTerms = $true MediaPath = '\SqlMedia' Features = 'SQLENGINE' InstanceId = 'MSSQLSERVER' Force = $true PBStartPortRange = 16450 PBEndPortRange = 16460 }And update the call site:
- Initialize-SqlDscImage @initializeSqlDscImageParameters + Initialize-SqlDscImage @mockInitializeSqlDscImageParametersApply similar changes at line 231.
Also applies to: 231-231
49-253: Consider adding explicit parameter property tests.While the parameter set validation test (lines 50-74) implicitly validates mandatory parameters through the parameter list string, consider adding explicit parameter property tests for robustness. This would directly test attributes like the Mandatory flag using the parameter properties test template.
Example parameter property test
Context 'When validating parameter properties' { It 'Should have AcceptLicensingTerms as a mandatory parameter' { $parameterInfo = (Get-Command -Name 'Initialize-SqlDscImage').Parameters['AcceptLicensingTerms'] $parameterInfo.Attributes.Mandatory | Should -BeTrue } It 'Should have MediaPath as a mandatory parameter' { $parameterInfo = (Get-Command -Name 'Initialize-SqlDscImage').Parameters['MediaPath'] $parameterInfo.Attributes.Mandatory | Should -BeTrue } It 'Should have Features as a mandatory parameter' { $parameterInfo = (Get-Command -Name 'Initialize-SqlDscImage').Parameters['Features'] $parameterInfo.Attributes.Mandatory | Should -BeTrue } }tests/Unit/Public/Update-SqlDscServer.Tests.ps1 (1)
116-127: Redundant-Forceparameter in test invocation.The
-Forceparameter is already included in$mockDefaultParameters(line 97), so passing it again on line 118 is redundant. Either remove it from the call or from the default parameters for clarity about what this specific test is exercising.🔎 Suggested clarification
If the intent is to test the Force parameter specifically, consider removing
Force = $truefrom$mockDefaultParametersand only passing it in this specific test context. Alternatively, keep the current approach but add a comment explaining the test setup.Context 'When using parameter Force' { It 'Should call the mock with the correct argument string' { - Update-SqlDscServer -Force @mockDefaultParameters + # Force is already in mockDefaultParameters; this validates Force behavior + Update-SqlDscServer @mockDefaultParameters
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
tests/Unit/Public/Initialize-SqlDscFailoverCluster.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/Unit/Public/Initialize-SqlDscFailoverCluster.Tests.ps1
🧰 Additional context used
📓 Path-based instructions (9)
**/*.[Tt]ests.ps1
📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-pester.instructions.md)
**/*.[Tt]ests.ps1: All public commands, private functions and classes must have unit tests
All public commands and class-based resources must have integration tests
Use Pester v5 syntax only
Test code only insideDescribeblocks
Assertions only inItblocks
Never test verbose messages, debug messages or parameter binding behavior
Pass all mandatory parameters to avoid prompts
InsideItblocks, assign unused return objects to$null(unless part of pipeline)
Tested entity must be called from within theItblocks
Keep results and assertions in sameItblock
Avoid try-catch-finally for cleanup, useAfterAllorAfterEach
Avoid unnecessary remove/recreate cycles
OneDescribeblock per file matching the tested entity name
Contextdescriptions start with 'When'
Itdescriptions start with 'Should', must not contain 'when'
Mock variables prefix: 'mock'
Public commands: Never useInModuleScope(unless retrieving localized strings or creating an object using an internal class)
Private functions/class resources: Always useInModuleScope
Each class method = separateContextblock
Each scenario = separateContextblock
Use nestedContextblocks for complex scenarios
Mocking inBeforeAll(BeforeEachonly when required)
Setup/teardown inBeforeAll,BeforeEach/AfterAll,AfterEachclose to usage
Spacing between blocks, arrange, act, and assert for readability
PascalCase:Describe,Context,It,Should,BeforeAll,BeforeEach,AfterAll,AfterEach
Use-BeTrue/-BeFalsenever-Be $true/-Be $false
Never useAssert-MockCalled, useShould -Invokeinstead
NoShould -Not -Throw- invoke commands directly
Never add an empty-MockWithblock
Omit-MockWithwhen returning$null
Set$PSDefaultParameterValuesforMock:ModuleName,Should:ModuleName,InModuleScope:ModuleName
Omit-ModuleNameparameter on Pester commands
Never useMockinsideInModuleScope-block
Never useparam()inside-MockWithscriptblock...
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
⚙️ CodeRabbit configuration file
**/*.[Tt]ests.ps1: # Tests GuidelinesCore Requirements
- All public commands, private functions and classes must have unit tests
- All public commands and class-based resources must have integration tests
- Use Pester v5 syntax only
- Test code only inside
Describeblocks- Assertions only in
Itblocks- Never test verbose messages, debug messages or parameter binding behavior
- Pass all mandatory parameters to avoid prompts
Requirements
- Inside
Itblocks, assign unused return objects to$null(unless part of pipeline)- Tested entity must be called from within the
Itblocks- Keep results and assertions in same
Itblock- Avoid try-catch-finally for cleanup, use
AfterAllorAfterEach- Avoid unnecessary remove/recreate cycles
Naming
- One
Describeblock per file matching the tested entity nameContextdescriptions start with 'When'Itdescriptions start with 'Should', must not contain 'when'- Mock variables prefix: 'mock'
Structure & Scope
- Public commands: Never use
InModuleScope(unless retrieving localized strings or creating an object using an internal class)- Private functions/class resources: Always use
InModuleScope- Each class method = separate
Contextblock- Each scenario = separate
Contextblock- Use nested
Contextblocks for complex scenarios- Mocking in
BeforeAll(BeforeEachonly when required)- Setup/teardown in
BeforeAll,BeforeEach/AfterAll,AfterEachclose to usage- Spacing between blocks, arrange, act, and assert for readability
Syntax Rules
- PascalCase:
Describe,Context,It,Should,BeforeAll,BeforeEach,AfterAll,AfterEach- Use
-BeTrue/-BeFalsenever-Be $true/-Be $false- Never use
Assert-MockCalled, useShould -Invokeinstead- No
Should -Not -Throw- invoke commands directly- Never add an empty
-MockWithblock- Omit
-MockWithwhen returning$null- Set
$PSDefaultParameterValuesforMock:ModuleName,Should:ModuleName, `...
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
tests/Unit/Public/*.[Tt]ests.ps1
📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-pester.instructions.md)
Public commands:
tests/Unit/Public/{Name}.Tests.ps1
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
tests/Unit/**/*.Tests.ps1
📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines.instructions.md)
Unit tests should be located in
tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
**/*.{ps1,psm1,psd1}
📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-powershell.instructions.md)
**/*.{ps1,psm1,psd1}: Use descriptive names (3+ characters, no abbreviations) for functions, parameters, variables, and classes
Functions: Use PascalCase with Verb-Noun format using approved verbs
Parameters: Use PascalCase naming
Variables: Use camelCase naming
Keywords: Use lower-case
Classes: Use PascalCase naming
Include scope for script/global/environment variables:$script:,$global:,$env:
Use 4 spaces for indentation (no tabs)
Use one space around operators:$a = 1 + 2
Use one space between type and variable:[String] $name
Use one space between keyword and parenthesis:if ($condition)
No spaces on empty lines
Limit lines to 120 characters
Place newline before opening brace (except variable assignments)
Place one newline after opening brace
Place two newlines after closing brace (one if followed by another brace or continuation)
Use single quotes unless variable expansion is needed:'text'vs"text $variable"
For single-line arrays use:@('one', 'two', 'three')
For multi-line arrays: place each element on separate line with proper indentation
Do not use the unary comma operator (,) in return statements to force an array
For empty hashtables use:@{}
For hashtables: place each property on separate line with proper indentation and use PascalCase for property names
Single-line comments: use# Commentformat (capitalized, on own line)
Multi-line comments: use<# Comment #>format (opening and closing brackets on own line with indented text)
No commented-out code
Always add comment-based help to all functions and scripts with SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, and EXAMPLE sections before function/class
Comment-based help indentation: keywords 4 spaces, text 8 spaces
Include examples in comment-based help for all parameter sets and combinations
INPUTS section in comment-based help: List each pipeline-accepted type as inline code with a 1-line description, repeat keyword for each input type, specifyNone.if there are no inp...
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
tests/[Uu]nit/**/*.[Tt]ests.ps1
📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md)
tests/[Uu]nit/**/*.[Tt]ests.ps1: Test with localized strings usingInModuleScope -ScriptBlock { $script:localizedData.Key }in Pester unit tests
Mock files using the$TestDrivevariable (path to the test drive) in Pester unit tests
All public commands require parameter set validation tests in unit tests
Use the exact Pester test setup block withBeforeDiscovery,BeforeAll, andAfterAllblocks beforeDescribein unit tests, includingDscResource.Testmodule import and PSDefaultParameterValues configuration
Use parameter set validation test template withGet-CommandandParameterSetsproperty, supporting both single and multiple parameter sets via-ForEacharray in Pester unit tests
Use parameter properties test template withGet-Commandto validate individual parameter attributes (e.g., Mandatory flag) in Pester unit tests
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
⚙️ CodeRabbit configuration file
tests/[Uu]nit/**/*.[Tt]ests.ps1: # Unit Tests Guidelines
- Test with localized strings: Use
InModuleScope -ScriptBlock { $script:localizedData.Key }- Mock files: Use
$TestDrivevariable (path to the test drive)- All public commands require parameter set validation tests
- After modifying classes, always run tests in new session (for changes to take effect)
Test Setup Requirements
Use this exact setup block before
Describe:[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 = '{MyModuleName}' Import-Module -Name $script:moduleName -ErrorAction 'Stop' $PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName $PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName $PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName } AfterAll { $PSDefaultParameterValues.Remove('InModuleScope:ModuleName') $PSDefaultParameterValues.Remove('Mock:ModuleName') ...
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
**/Public/**/*.ps1
📄 CodeRabbit inference engine (.github/instructions/SqlServerDsc-guidelines.instructions.md)
Public commands must follow the naming format
{Verb}-SqlDsc{Noun}
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
**/tests/Unit/**/*.ps1
📄 CodeRabbit inference engine (.github/instructions/SqlServerDsc-guidelines.instructions.md)
**/tests/Unit/**/*.ps1: Unit tests must use SMO stub types from SMO.cs, never mock SMO types
Unit tests must add$env:SqlServerDscCI = $trueinBeforeAllblock and remove inAfterAllblock
Load SMO stub types from SMO.cs in unit test files usingAdd-Type -Path "$PSScriptRoot/../Stubs/SMO.cs"
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
**
⚙️ CodeRabbit configuration file
**: # DSC Community GuidelinesTerminology
- Command: Public command
- Function: Private function
- Resource: DSC class-based resource
Build & Test Workflow Requirements
- Run PowerShell script files from repository root
- Setup build and test environment (once per
pwshsession):./build.ps1 -Tasks noop- Build project before running tests:
./build.ps1 -Tasks build- Always run tests in new
pwshsession:Invoke-Pester -Path @({test paths}) -Output DetailedFile Organization
- Public commands:
source/Public/{CommandName}.ps1- Private functions:
source/Private/{FunctionName}.ps1- Classes:
source/Classes/{DependencyGroupNumber}.{ClassName}.ps1- Enums:
source/Enum/{DependencyGroupNumber}.{EnumName}.ps1- Unit tests:
tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1- Integration tests:
tests/Integration/Commands/{CommandName}.Integration.Tests.ps1Requirements
- Follow instructions over existing code patterns
- Follow PowerShell style and test guideline instructions strictly
- Always update CHANGELOG.md Unreleased section
- Localize all strings using string keys; remove any orphaned string keys
- Check DscResource.Common before creating private functions
- Separate reusable logic into private functions
- DSC resources should always be created as class-based resources
- Add unit tests for all commands/functions/resources
- Add integration tests for all public commands and resources
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
{**/*.ps1,**/*.psm1,**/*.psd1}
⚙️ CodeRabbit configuration file
{**/*.ps1,**/*.psm1,**/*.psd1}: # PowerShell GuidelinesNaming
- Use descriptive names (3+ characters, no abbreviations)
- Functions: PascalCase with Verb-Noun format using approved verbs
- Parameters: PascalCase
- Variables: camelCase
- Keywords: lower-case
- Classes: PascalCase
- Include scope for script/global/environment variables:
$script:,$global:,$env:File naming
- Class files:
###.ClassName.ps1format (e.g.001.SqlReason.ps1,004.StartupParameters.ps1)Formatting
Indentation & Spacing
- Use 4 spaces (no tabs)
- One space around operators:
$a = 1 + 2- One space between type and variable:
[String] $name- One space between keyword and parenthesis:
if ($condition)- No spaces on empty lines
- Try to limit lines to 120 characters
Braces
- Newline before opening brace (except variable assignments)
- One newline after opening brace
- Two newlines after closing brace (one if followed by another brace or continuation)
Quotes
- Use single quotes unless variable expansion is needed:
'text'vs"text $variable"Arrays
- Single line:
@('one', 'two', 'three')- Multi-line: each element on separate line with proper indentation
- Do not use the unary comma operator (
,) in return statements to force
an arrayHashtables
- Empty:
@{}- Each property on separate line with proper indentation
- Properties: Use PascalCase
Comments
- Single line:
# Comment(capitalized, on own line)- Multi-line:
<# Comment #>format (opening and closing brackets on own line), and indent text- No commented-out code
Comment-based help
- Always add comment-based help to all functions and scripts
- Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
- Comment-based help indentation: keywords 4 spaces, text 8 spaces
- Include examples for all parameter sets and combinations
- INPUTS: List each pipeline‑accepted type as inline code with a 1‑line description...
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
🧠 Learnings (22)
📓 Common learnings
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2026-01-01T11:57:15.286Z
Learning: Applies to **/tests/Integration/**/*.ps1 : Integration tests must use `Connect-SqlDscDatabaseEngine` for SQL Server DB session with correct CI credentials
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2026-01-01T11:57:15.286Z
Learning: Applies to **/tests/Integration/**/*.ps1 : Integration tests must use `Disconnect-SqlDscDatabaseEngine` after `Connect-SqlDscDatabaseEngine`
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2026-01-01T11:57:15.286Z
Learning: Applies to **/tests/Unit/**/*.ps1 : Unit tests must add `$env:SqlServerDscCI = $true` in `BeforeAll` block and remove in `AfterAll` block
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-12-30T15:15:25.261Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : Integration test files must include the required setup block with SuppressMessageAttribute, BeforeDiscovery block for DscResource.Test module import, and BeforeAll block for module initialization
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-12-30T15:15:36.079Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Use the exact Pester test setup block with `BeforeDiscovery`, `BeforeAll`, and `AfterAll` blocks before `Describe` in unit tests, including `DscResource.Test` module import and PSDefaultParameterValues configuration
📚 Learning: 2026-01-01T11:57:15.286Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2026-01-01T11:57:15.286Z
Learning: Applies to **/tests/Unit/**/*.ps1 : Unit tests must add `$env:SqlServerDscCI = $true` in `BeforeAll` block and remove in `AfterAll` block
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
📚 Learning: 2025-12-30T15:15:36.079Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-12-30T15:15:36.079Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Use the exact Pester test setup block with `BeforeDiscovery`, `BeforeAll`, and `AfterAll` blocks before `Describe` in unit tests, including `DscResource.Test` module import and PSDefaultParameterValues configuration
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
📚 Learning: 2026-01-01T11:57:15.286Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2026-01-01T11:57:15.286Z
Learning: Applies to **/tests/Integration/**/*.ps1 : Integration tests must use `Connect-SqlDscDatabaseEngine` for SQL Server DB session with correct CI credentials
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
📚 Learning: 2025-12-30T15:15:36.079Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-12-30T15:15:36.079Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : All public commands require parameter set validation tests in unit tests
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : All public commands and class-based resources must have integration tests
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
📚 Learning: 2025-12-30T15:15:25.261Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-12-30T15:15:25.261Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : Integration test files must include the required setup block with SuppressMessageAttribute, BeforeDiscovery block for DscResource.Test module import, and BeforeAll block for module initialization
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : All public commands, private functions and classes must have unit tests
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
📚 Learning: 2026-01-01T11:57:15.286Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2026-01-01T11:57:15.286Z
Learning: Applies to **/tests/Integration/**/*.ps1 : Integration tests must use `Disconnect-SqlDscDatabaseEngine` after `Connect-SqlDscDatabaseEngine`
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
📚 Learning: 2025-12-30T15:15:36.079Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-12-30T15:15:36.079Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Use parameter properties test template with `Get-Command` to validate individual parameter attributes (e.g., Mandatory flag) in Pester unit tests
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Cover all scenarios and code paths
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1
📚 Learning: 2025-10-10T14:01:42.703Z
Learnt from: dan-hughes
Repo: dsccommunity/UpdateServicesDsc PR: 86
File: tests/Unit/MSFT_UpdateServicesServer.Tests.ps1:6-45
Timestamp: 2025-10-10T14:01:42.703Z
Learning: For script-based (MOF) DSC resources in UpdateServicesDsc, unit tests should use Initialize-TestEnvironment with variables $script:dscModuleName and $script:dscResourceName, and set -ResourceType 'Mof'. This differs from class-based resource tests which use the simpler $script:moduleName template without Initialize-TestEnvironment.
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Mocking in `BeforeAll` (`BeforeEach` only when required)
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
📚 Learning: 2025-11-27T18:56:46.759Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 1622
File: tests/Integration/DSC_SqlDatabase.Integration.Tests.ps1:1-30
Timestamp: 2025-11-27T18:56:46.759Z
Learning: Integration tests for MOF-based DSC resources (located in source/DSCResources/**) should use the Initialize-TestEnvironment pattern with -ResourceType 'Mof', not the BeforeDiscovery/BeforeAll pattern. The BeforeDiscovery/BeforeAll pattern is for class-based resources only.
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
📚 Learning: 2025-08-17T10:15:48.194Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 2136
File: tests/Unit/Public/Remove-SqlDscLogin.Tests.ps1:36-39
Timestamp: 2025-08-17T10:15:48.194Z
Learning: Public command unit tests guideline: Never use InModuleScope unless accessing localized strings from $script:localizedData. PSDefaultParameterValues for InModuleScope should be kept in public command tests to support localized string retrieval when necessary.
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Set `$PSDefaultParameterValues` for `Mock:ModuleName`, `Should:ModuleName`, `InModuleScope:ModuleName`
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1
📚 Learning: 2025-08-28T15:44:12.628Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 2150
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:35-35
Timestamp: 2025-08-28T15:44:12.628Z
Learning: The SqlServerDsc repository uses RequiredModules.psd1 to specify Pester with Version = 'latest' and AllowPrerelease = $true, ensuring the latest Pester version (well beyond 5.4) is available, which supports Should -Invoke syntax and other modern Pester features.
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
📚 Learning: 2025-12-30T15:15:25.261Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-12-30T15:15:25.261Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : Integration tests must cover all scenarios and code paths
Applied to files:
tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
📚 Learning: 2025-12-30T15:15:36.079Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-12-30T15:15:36.079Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Use parameter set validation test template with `Get-Command` and `ParameterSets` property, supporting both single and multiple parameter sets via `-ForEach` array in Pester unit tests
Applied to files:
tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
📚 Learning: 2025-10-11T08:18:26.062Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 2300
File: tests/Unit/DSC_SqlAGDatabase.Tests.ps1:22-22
Timestamp: 2025-10-11T08:18:26.062Z
Learning: In unit test files (tests/[Uu]nit/**/*.[Tt]ests.ps1), when DscResource.Test module dependency is not found during BeforeDiscovery setup, the error message should instruct users to run ".\build.ps1 -Tasks noop" (not "build") because the noop task is designed for quick test environment setup. The build task is more extensive and unnecessary when tests run in a separate process, as the module should already be built before running tests.
Applied to files:
tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to tests/Unit/Public/*.[Tt]ests.ps1 : Public commands: `tests/Unit/Public/{Name}.Tests.ps1`
Applied to files:
tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Use Pester v5 syntax only
Applied to files:
tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
- GitHub Check: PSScriptAnalyzer
- GitHub Check: PSScriptAnalyzer
🔇 Additional comments (7)
tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1 (2)
1-47: LGTM! Setup block follows required template.The test setup block correctly implements all required elements per coding guidelines, including the
$env:SqlServerDscCIenvironment variable setup and cleanup.
76-138: LGTM! ShouldProcess behavior tested correctly.The tests properly validate
-WhatIf,-Confirm:$false, and-Forceparameter behavior, ensuringStart-SqlSetupProcessis called only when appropriate.tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1 (3)
1-47: LGTM! Exemplary test setup.The test setup block correctly implements all required patterns: BeforeDiscovery with DscResource.Test import, BeforeAll with
$env:SqlServerDscCI = $trueand PSDefaultParameterValues configuration, and AfterAll with proper cleanup.
49-74: LGTM! Parameter set validation follows the correct template.The test correctly validates the parameter set structure using Get-Command and the ParameterSets property, matching the required test template.
76-138: LGTM! Well-structured test scenarios.The tests correctly validate behavior with Confirm, Force, and WhatIf parameters, using proper Should -Invoke patterns with ParameterFilter and appropriate mock invocation counts.
tests/Unit/Public/Update-SqlDscServer.Tests.ps1 (2)
1-48: LGTM!The test setup blocks correctly follow the required template with proper
BeforeDiscovery,BeforeAll, andAfterAllblocks. The$env:SqlServerDscCIenvironment variable is correctly set and removed per the SqlServerDsc guidelines.
76-85: LGTM!The context block follows naming conventions and the mocks are properly structured in
BeforeAllwith appropriate parameter filters.
…out parameter in Update-SqlDscServerEdition tests
…rameters in Initialize-SqlDscImage
… argument handling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Fix all issues with AI Agents 🤖
In @tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1:
- Around line 177-186: The test's ParameterFilter for Start-SqlSetupProcess uses
the literal 'PBPORTRANGE=16450-16460' missing the leading slash unlike other
patterns; update the assertion in the Should -Invoke block for
Initialize-SqlDscImage so the ParameterFilter checks for
'\/PBPORTRANGE=16450-16460' (i.e., include the leading '/' in the regex/string
match) to match the same argument format as other parameters and ensure
consistency with Start-SqlSetupProcess invocation.
🧹 Nitpick comments (2)
tests/Unit/Public/Update-SqlDscServer.Tests.ps1 (1)
137-213: Consider adding test coverage for the Timeout parameter.The parameter set validation at line 54 includes the
Timeoutparameter, but no test case in the-ForEacharray verifies its behavior. For comprehensive coverage, consider adding a test case following the existing pattern.🔎 Suggested test case to add
Add this test case to the
-ForEacharray:@{ MockParameterName = 'Timeout' MockParameterValue = 600 MockExpectedRegEx = '\/TIMEOUT=600' }tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1 (1)
189-274: Consider adding test coverage forTimeoutandIAcknowledgeEntCalLimitsparameters.The ForEach data structure covers most optional parameters, but
TimeoutandIAcknowledgeEntCalLimits(both listed in the expected parameter set on line 54) are not included. Adding these would complete the optional parameter coverage.🔎 Suggested additions to the ForEach array
@{ MockParameterName = 'PBScaleOut' MockParameterValue = $true MockExpectedRegEx = '\/PBSCALEOUT=True' # cspell: disable-line } + @{ + MockParameterName = 'IAcknowledgeEntCalLimits' + MockParameterValue = $true + MockExpectedRegEx = '\/IACABORTTENTCALLIMITS' # cspell: disable-line (verify actual argument name) + } + @{ + MockParameterName = 'Timeout' + MockParameterValue = [System.UInt32] 7200 + MockExpectedRegEx = '\/WAIT' # Note: Timeout may affect process wait behavior rather than argument list + }Note: The
Timeoutparameter may not produce a command-line argument but instead affect howStart-SqlSetupProcesswaits. Verify the expected behavior before adding this test case.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/Unit/Public/Update-SqlDscServerEdition.Tests.ps1
🧰 Additional context used
📓 Path-based instructions (9)
**/*.[Tt]ests.ps1
📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-pester.instructions.md)
**/*.[Tt]ests.ps1: All public commands, private functions and classes must have unit tests
All public commands and class-based resources must have integration tests
Use Pester v5 syntax only
Test code only insideDescribeblocks
Assertions only inItblocks
Never test verbose messages, debug messages or parameter binding behavior
Pass all mandatory parameters to avoid prompts
InsideItblocks, assign unused return objects to$null(unless part of pipeline)
Tested entity must be called from within theItblocks
Keep results and assertions in sameItblock
Avoid try-catch-finally for cleanup, useAfterAllorAfterEach
Avoid unnecessary remove/recreate cycles
OneDescribeblock per file matching the tested entity name
Contextdescriptions start with 'When'
Itdescriptions start with 'Should', must not contain 'when'
Mock variables prefix: 'mock'
Public commands: Never useInModuleScope(unless retrieving localized strings or creating an object using an internal class)
Private functions/class resources: Always useInModuleScope
Each class method = separateContextblock
Each scenario = separateContextblock
Use nestedContextblocks for complex scenarios
Mocking inBeforeAll(BeforeEachonly when required)
Setup/teardown inBeforeAll,BeforeEach/AfterAll,AfterEachclose to usage
Spacing between blocks, arrange, act, and assert for readability
PascalCase:Describe,Context,It,Should,BeforeAll,BeforeEach,AfterAll,AfterEach
Use-BeTrue/-BeFalsenever-Be $true/-Be $false
Never useAssert-MockCalled, useShould -Invokeinstead
NoShould -Not -Throw- invoke commands directly
Never add an empty-MockWithblock
Omit-MockWithwhen returning$null
Set$PSDefaultParameterValuesforMock:ModuleName,Should:ModuleName,InModuleScope:ModuleName
Omit-ModuleNameparameter on Pester commands
Never useMockinsideInModuleScope-block
Never useparam()inside-MockWithscriptblock...
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
⚙️ CodeRabbit configuration file
**/*.[Tt]ests.ps1: # Tests GuidelinesCore Requirements
- All public commands, private functions and classes must have unit tests
- All public commands and class-based resources must have integration tests
- Use Pester v5 syntax only
- Test code only inside
Describeblocks- Assertions only in
Itblocks- Never test verbose messages, debug messages or parameter binding behavior
- Pass all mandatory parameters to avoid prompts
Requirements
- Inside
Itblocks, assign unused return objects to$null(unless part of pipeline)- Tested entity must be called from within the
Itblocks- Keep results and assertions in same
Itblock- Avoid try-catch-finally for cleanup, use
AfterAllorAfterEach- Avoid unnecessary remove/recreate cycles
Naming
- One
Describeblock per file matching the tested entity nameContextdescriptions start with 'When'Itdescriptions start with 'Should', must not contain 'when'- Mock variables prefix: 'mock'
Structure & Scope
- Public commands: Never use
InModuleScope(unless retrieving localized strings or creating an object using an internal class)- Private functions/class resources: Always use
InModuleScope- Each class method = separate
Contextblock- Each scenario = separate
Contextblock- Use nested
Contextblocks for complex scenarios- Mocking in
BeforeAll(BeforeEachonly when required)- Setup/teardown in
BeforeAll,BeforeEach/AfterAll,AfterEachclose to usage- Spacing between blocks, arrange, act, and assert for readability
Syntax Rules
- PascalCase:
Describe,Context,It,Should,BeforeAll,BeforeEach,AfterAll,AfterEach- Use
-BeTrue/-BeFalsenever-Be $true/-Be $false- Never use
Assert-MockCalled, useShould -Invokeinstead- No
Should -Not -Throw- invoke commands directly- Never add an empty
-MockWithblock- Omit
-MockWithwhen returning$null- Set
$PSDefaultParameterValuesforMock:ModuleName,Should:ModuleName, `...
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
tests/Unit/Public/*.[Tt]ests.ps1
📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-pester.instructions.md)
Public commands:
tests/Unit/Public/{Name}.Tests.ps1
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
tests/Unit/**/*.Tests.ps1
📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines.instructions.md)
Unit tests should be located in
tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
**/*.{ps1,psm1,psd1}
📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-powershell.instructions.md)
**/*.{ps1,psm1,psd1}: Use descriptive names (3+ characters, no abbreviations) for functions, parameters, variables, and classes
Functions: Use PascalCase with Verb-Noun format using approved verbs
Parameters: Use PascalCase naming
Variables: Use camelCase naming
Keywords: Use lower-case
Classes: Use PascalCase naming
Include scope for script/global/environment variables:$script:,$global:,$env:
Use 4 spaces for indentation (no tabs)
Use one space around operators:$a = 1 + 2
Use one space between type and variable:[String] $name
Use one space between keyword and parenthesis:if ($condition)
No spaces on empty lines
Limit lines to 120 characters
Place newline before opening brace (except variable assignments)
Place one newline after opening brace
Place two newlines after closing brace (one if followed by another brace or continuation)
Use single quotes unless variable expansion is needed:'text'vs"text $variable"
For single-line arrays use:@('one', 'two', 'three')
For multi-line arrays: place each element on separate line with proper indentation
Do not use the unary comma operator (,) in return statements to force an array
For empty hashtables use:@{}
For hashtables: place each property on separate line with proper indentation and use PascalCase for property names
Single-line comments: use# Commentformat (capitalized, on own line)
Multi-line comments: use<# Comment #>format (opening and closing brackets on own line with indented text)
No commented-out code
Always add comment-based help to all functions and scripts with SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, and EXAMPLE sections before function/class
Comment-based help indentation: keywords 4 spaces, text 8 spaces
Include examples in comment-based help for all parameter sets and combinations
INPUTS section in comment-based help: List each pipeline-accepted type as inline code with a 1-line description, repeat keyword for each input type, specifyNone.if there are no inp...
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
tests/[Uu]nit/**/*.[Tt]ests.ps1
📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md)
tests/[Uu]nit/**/*.[Tt]ests.ps1: Test with localized strings usingInModuleScope -ScriptBlock { $script:localizedData.Key }in Pester unit tests
Mock files using the$TestDrivevariable (path to the test drive) in Pester unit tests
All public commands require parameter set validation tests in unit tests
Use the exact Pester test setup block withBeforeDiscovery,BeforeAll, andAfterAllblocks beforeDescribein unit tests, includingDscResource.Testmodule import and PSDefaultParameterValues configuration
Use parameter set validation test template withGet-CommandandParameterSetsproperty, supporting both single and multiple parameter sets via-ForEacharray in Pester unit tests
Use parameter properties test template withGet-Commandto validate individual parameter attributes (e.g., Mandatory flag) in Pester unit tests
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
⚙️ CodeRabbit configuration file
tests/[Uu]nit/**/*.[Tt]ests.ps1: # Unit Tests Guidelines
- Test with localized strings: Use
InModuleScope -ScriptBlock { $script:localizedData.Key }- Mock files: Use
$TestDrivevariable (path to the test drive)- All public commands require parameter set validation tests
- After modifying classes, always run tests in new session (for changes to take effect)
Test Setup Requirements
Use this exact setup block before
Describe:[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 = '{MyModuleName}' Import-Module -Name $script:moduleName -ErrorAction 'Stop' $PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName $PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName $PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName } AfterAll { $PSDefaultParameterValues.Remove('InModuleScope:ModuleName') $PSDefaultParameterValues.Remove('Mock:ModuleName') ...
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
**/Public/**/*.ps1
📄 CodeRabbit inference engine (.github/instructions/SqlServerDsc-guidelines.instructions.md)
Public commands must follow the naming format
{Verb}-SqlDsc{Noun}
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
**/tests/Unit/**/*.ps1
📄 CodeRabbit inference engine (.github/instructions/SqlServerDsc-guidelines.instructions.md)
**/tests/Unit/**/*.ps1: Unit tests must use SMO stub types from SMO.cs, never mock SMO types
Unit tests must add$env:SqlServerDscCI = $trueinBeforeAllblock and remove inAfterAllblock
Load SMO stub types from SMO.cs in unit test files usingAdd-Type -Path "$PSScriptRoot/../Stubs/SMO.cs"
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
**
⚙️ CodeRabbit configuration file
**: # DSC Community GuidelinesTerminology
- Command: Public command
- Function: Private function
- Resource: DSC class-based resource
Build & Test Workflow Requirements
- Run PowerShell script files from repository root
- Setup build and test environment (once per
pwshsession):./build.ps1 -Tasks noop- Build project before running tests:
./build.ps1 -Tasks build- Always run tests in new
pwshsession:Invoke-Pester -Path @({test paths}) -Output DetailedFile Organization
- Public commands:
source/Public/{CommandName}.ps1- Private functions:
source/Private/{FunctionName}.ps1- Classes:
source/Classes/{DependencyGroupNumber}.{ClassName}.ps1- Enums:
source/Enum/{DependencyGroupNumber}.{EnumName}.ps1- Unit tests:
tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1- Integration tests:
tests/Integration/Commands/{CommandName}.Integration.Tests.ps1Requirements
- Follow instructions over existing code patterns
- Follow PowerShell style and test guideline instructions strictly
- Always update CHANGELOG.md Unreleased section
- Localize all strings using string keys; remove any orphaned string keys
- Check DscResource.Common before creating private functions
- Separate reusable logic into private functions
- DSC resources should always be created as class-based resources
- Add unit tests for all commands/functions/resources
- Add integration tests for all public commands and resources
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
{**/*.ps1,**/*.psm1,**/*.psd1}
⚙️ CodeRabbit configuration file
{**/*.ps1,**/*.psm1,**/*.psd1}: # PowerShell GuidelinesNaming
- Use descriptive names (3+ characters, no abbreviations)
- Functions: PascalCase with Verb-Noun format using approved verbs
- Parameters: PascalCase
- Variables: camelCase
- Keywords: lower-case
- Classes: PascalCase
- Include scope for script/global/environment variables:
$script:,$global:,$env:File naming
- Class files:
###.ClassName.ps1format (e.g.001.SqlReason.ps1,004.StartupParameters.ps1)Formatting
Indentation & Spacing
- Use 4 spaces (no tabs)
- One space around operators:
$a = 1 + 2- One space between type and variable:
[String] $name- One space between keyword and parenthesis:
if ($condition)- No spaces on empty lines
- Try to limit lines to 120 characters
Braces
- Newline before opening brace (except variable assignments)
- One newline after opening brace
- Two newlines after closing brace (one if followed by another brace or continuation)
Quotes
- Use single quotes unless variable expansion is needed:
'text'vs"text $variable"Arrays
- Single line:
@('one', 'two', 'three')- Multi-line: each element on separate line with proper indentation
- Do not use the unary comma operator (
,) in return statements to force
an arrayHashtables
- Empty:
@{}- Each property on separate line with proper indentation
- Properties: Use PascalCase
Comments
- Single line:
# Comment(capitalized, on own line)- Multi-line:
<# Comment #>format (opening and closing brackets on own line), and indent text- No commented-out code
Comment-based help
- Always add comment-based help to all functions and scripts
- Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
- Comment-based help indentation: keywords 4 spaces, text 8 spaces
- Include examples for all parameter sets and combinations
- INPUTS: List each pipeline‑accepted type as inline code with a 1‑line description...
Files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
🧠 Learnings (30)
📓 Common learnings
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2026-01-01T11:57:15.286Z
Learning: Applies to **/tests/Integration/**/*.ps1 : Integration tests must use `Connect-SqlDscDatabaseEngine` for SQL Server DB session with correct CI credentials
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2026-01-01T11:57:15.286Z
Learning: Applies to **/tests/Integration/**/*.ps1 : Integration tests must use `Disconnect-SqlDscDatabaseEngine` after `Connect-SqlDscDatabaseEngine`
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2026-01-01T11:57:15.286Z
Learning: Applies to **/tests/Unit/**/*.ps1 : Unit tests must add `$env:SqlServerDscCI = $true` in `BeforeAll` block and remove in `AfterAll` block
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-12-30T15:15:36.079Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Use the exact Pester test setup block with `BeforeDiscovery`, `BeforeAll`, and `AfterAll` blocks before `Describe` in unit tests, including `DscResource.Test` module import and PSDefaultParameterValues configuration
📚 Learning: 2025-12-30T15:15:36.079Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-12-30T15:15:36.079Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Use the exact Pester test setup block with `BeforeDiscovery`, `BeforeAll`, and `AfterAll` blocks before `Describe` in unit tests, including `DscResource.Test` module import and PSDefaultParameterValues configuration
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
📚 Learning: 2026-01-01T11:57:15.286Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2026-01-01T11:57:15.286Z
Learning: Applies to **/tests/Unit/**/*.ps1 : Unit tests must add `$env:SqlServerDscCI = $true` in `BeforeAll` block and remove in `AfterAll` block
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : All public commands and class-based resources must have integration tests
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
📚 Learning: 2025-12-30T15:15:36.079Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-12-30T15:15:36.079Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : All public commands require parameter set validation tests in unit tests
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
📚 Learning: 2025-12-30T15:15:25.261Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-12-30T15:15:25.261Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : Integration test files must include the required setup block with SuppressMessageAttribute, BeforeDiscovery block for DscResource.Test module import, and BeforeAll block for module initialization
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
📚 Learning: 2026-01-01T11:57:15.286Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2026-01-01T11:57:15.286Z
Learning: Applies to **/tests/Integration/**/*.ps1 : Integration tests must use `Connect-SqlDscDatabaseEngine` for SQL Server DB session with correct CI credentials
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to tests/Unit/Public/*.[Tt]ests.ps1 : Public commands: `tests/Unit/Public/{Name}.Tests.ps1`
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : All public commands, private functions and classes must have unit tests
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
📚 Learning: 2025-12-30T15:15:36.079Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-12-30T15:15:36.079Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Use parameter properties test template with `Get-Command` to validate individual parameter attributes (e.g., Mandatory flag) in Pester unit tests
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Cover all scenarios and code paths
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Mock variables prefix: 'mock'
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1
📚 Learning: 2025-12-30T15:15:36.079Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-12-30T15:15:36.079Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Use parameter set validation test template with `Get-Command` and `ParameterSets` property, supporting both single and multiple parameter sets via `-ForEach` array in Pester unit tests
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Mocking in `BeforeAll` (`BeforeEach` only when required)
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Never use `param()` inside `-MockWith` scriptblocks, parameters are auto-bound
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Set `$PSDefaultParameterValues` for `Mock:ModuleName`, `Should:ModuleName`, `InModuleScope:ModuleName`
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Define `-ForEach` variables in `BeforeDiscovery` (close to usage)
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Use `$PSDefaultParameterValues` only for Pester commands (`Describe`, `Context`, `It`, `Mock`, `Should`, `InModuleScope`)
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : PascalCase: `Describe`, `Context`, `It`, `Should`, `BeforeAll`, `BeforeEach`, `AfterAll`, `AfterEach`
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1
📚 Learning: 2025-12-24T18:09:36.332Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-12-24T18:09:36.332Z
Learning: Applies to **/*.{ps1,psm1,psd1} : Variables: Use camelCase naming
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Never add `param()` inside Pester blocks when using `-ForEach`
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Use `BeforeEach` and `AfterEach` sparingly
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Avoid unnecessary remove/recreate cycles
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Setup/teardown in `BeforeAll`,`BeforeEach`/`AfterAll`,`AfterEach` close to usage
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1
📚 Learning: 2025-08-17T10:13:30.079Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 2136
File: source/Public/Remove-SqlDscLogin.ps1:104-108
Timestamp: 2025-08-17T10:13:30.079Z
Learning: In SqlServerDsc unit tests, SMO object stubs (like Login objects) should have properly mocked Parent properties with correct Server stub types and valid InstanceName values, rather than handling null Parent scenarios in production code.
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1
📚 Learning: 2026-01-01T11:57:15.286Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2026-01-01T11:57:15.286Z
Learning: Applies to **/tests/Integration/**/*.ps1 : Integration tests must use `Disconnect-SqlDscDatabaseEngine` after `Connect-SqlDscDatabaseEngine`
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
📚 Learning: 2025-10-10T14:01:42.703Z
Learnt from: dan-hughes
Repo: dsccommunity/UpdateServicesDsc PR: 86
File: tests/Unit/MSFT_UpdateServicesServer.Tests.ps1:6-45
Timestamp: 2025-10-10T14:01:42.703Z
Learning: For script-based (MOF) DSC resources in UpdateServicesDsc, unit tests should use Initialize-TestEnvironment with variables $script:dscModuleName and $script:dscResourceName, and set -ResourceType 'Mof'. This differs from class-based resource tests which use the simpler $script:moduleName template without Initialize-TestEnvironment.
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
📚 Learning: 2025-11-27T18:56:46.759Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 1622
File: tests/Integration/DSC_SqlDatabase.Integration.Tests.ps1:1-30
Timestamp: 2025-11-27T18:56:46.759Z
Learning: Integration tests for MOF-based DSC resources (located in source/DSCResources/**) should use the Initialize-TestEnvironment pattern with -ResourceType 'Mof', not the BeforeDiscovery/BeforeAll pattern. The BeforeDiscovery/BeforeAll pattern is for class-based resources only.
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
📚 Learning: 2025-08-17T10:15:48.194Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 2136
File: tests/Unit/Public/Remove-SqlDscLogin.Tests.ps1:36-39
Timestamp: 2025-08-17T10:15:48.194Z
Learning: Public command unit tests guideline: Never use InModuleScope unless accessing localized strings from $script:localizedData. PSDefaultParameterValues for InModuleScope should be kept in public command tests to support localized string retrieval when necessary.
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1
📚 Learning: 2025-08-28T15:44:12.628Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 2150
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:35-35
Timestamp: 2025-08-28T15:44:12.628Z
Learning: The SqlServerDsc repository uses RequiredModules.psd1 to specify Pester with Version = 'latest' and AllowPrerelease = $true, ensuring the latest Pester version (well beyond 5.4) is available, which supports Should -Invoke syntax and other modern Pester features.
Applied to files:
tests/Unit/Public/Update-SqlDscServer.Tests.ps1
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
- GitHub Check: PSScriptAnalyzer
- GitHub Check: PSScriptAnalyzer
🔇 Additional comments (4)
tests/Unit/Public/Update-SqlDscServer.Tests.ps1 (1)
1-74: Past review feedback has been addressed.The variable casing issue at line 59 (now correctly uses
$MockParameterSetNamein PascalCase) and the test pollution concern (hashtable now created inBeforeEachat lines 220-227 instead ofBeforeAll) have both been resolved.Also applies to: 220-227
tests/Unit/Public/Initialize-SqlDscImage.Tests.ps1 (3)
1-47: LGTM! Test setup follows the required template correctly.The file correctly:
- Includes the SuppressMessageAttribute for Pester syntax compatibility
- Uses the exact BeforeDiscovery template for DscResource.Test module import
- Sets
$env:SqlServerDscCI = $truein BeforeAll and removes it in AfterAll per SqlServerDsc guidelines- Configures PSDefaultParameterValues for Mock, Should, and InModuleScope
49-94: LGTM! Parameter validation tests follow the required templates.The parameter set validation test and mandatory parameter property tests correctly use the guideline-prescribed patterns with
Get-CommandandParameterSets/Parametersproperties.
107-158: LGTM! Tests for mandatory parameters with Confirm, Force, and WhatIf are well-structured.The nested Context blocks properly test different invocation scenarios, and the WhatIf test correctly verifies that
Start-SqlSetupProcessis not invoked.
…nd in Initialize-SqlDscImage tests
… value in Initialize-SqlDscImage
johlju
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johlju partially reviewed 19 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @johlju).
Pull Request (PR) description
Initialize-SqlDscImageto prepare a SQL Server imagefor later configuration with
Complete-SqlDscImage. Extracted fromInstall-SqlDscServerPrepareImage parameter set(issue #2396).
Update-SqlDscServerEditionto upgrade the edition of anexisting SQL Server instance using the EditionUpgrade setup action
(issue #2393).
Update-SqlDscServerto upgrade an existing SQL Serverinstance to a newer version using the Upgrade setup action
(issue #2394).
Initialize-SqlDscFailoverClusterto prepare a failovercluster node for later completion with
Complete-SqlDscFailoverCluster.Extracted from
Install-SqlDscServerPrepareFailoverCluster parameter set(issue #2395).
Install-SqlDscFailoverClusterto install SQL Server ina failover cluster configuration. Extracted from
Install-SqlDscServerInstallFailoverCluster parameter set.
Install-SqlDscServerPrepareImage,Upgrade,EditionUpgrade,PrepareFailoverCluster, andInstallFailoverClusterparameter sets. Usethe new dedicated commands
Initialize-SqlDscImage,Update-SqlDscServer,Update-SqlDscServerEdition,Initialize-SqlDscFailoverCluster, andInstall-SqlDscFailoverClusterinstead(issue #2393)
(issue #2394)
(issue #2395)
(issue #2396).
This Pull Request (PR) fixes the following issues
Task list
file CHANGELOG.md. Entry should say what was changed and how that
affects users (if applicable), and reference the issue being resolved
(if applicable).
This change is