Skip to content

Conversation

@johlju
Copy link
Member

@johlju johlju commented Oct 11, 2025

Pull Request (PR) description

This Pull Request (PR) fixes the following issues

Task list

  • Added an entry to the change log under the Unreleased section of the
    file CHANGELOG.md. Entry should say what was changed and how that
    affects users (if applicable), and reference the issue being resolved
    (if applicable).
  • Resource documentation updated in the resource's README.md.
  • Resource parameter descriptions updated in schema.mof.
  • Comment-based help updated, including parameter descriptions.
  • Localization strings updated.
  • Examples updated.
  • Unit tests updated. See DSC Community Testing Guidelines.
  • Integration tests updated (where possible). See DSC Community Testing Guidelines.
  • Code changes adheres to DSC Community Style Guidelines.

This change is Reviewable

…ults to $null

- Updated multiple test files to replace the pattern of using `{ command } | Should -Not -Throw` with `$null = command` for better readability and to suppress unnecessary error output.
- This change was applied across various test files including DSC_SqlRS.Tests.ps1, DSC_SqlScript.Tests.ps1, DSC_SqlSecureConnection.Tests.ps1, and others.
- Updated multiple test files to assign command results to `$null` instead of using a block with `Should -Not -Throw` to improve readability and maintainability.
- This change applies to integration tests for `DSC_SqlTraceFlag` and `DSC_SqlWindowsFirewall`, as well as unit tests for `SqlDatabasePermission`, `SqlPermission`, `Remove-SqlDscRole`, `Set-SqlDscDatabasePermission`, `Set-SqlDscServerPermission`, and `SqlServerDsc.Common`.
- Simplified the structure of the integration tests by removing redundant script blocks that encapsulated the configuration parameters and DSC configuration calls.
- Ensured that the tests still compile and apply the MOF without throwing exceptions.
- Updated the tests across multiple files: DSC_SqlRS_Default, DSC_SqlServiceAccount, DSC_SqlSetup, DSC_SqlWindowsFirewall to maintain consistency and improve readability.
@johlju johlju requested a review from a team as a code owner October 11, 2025 18:38
@coderabbitai
Copy link

coderabbitai bot commented Oct 11, 2025

Walkthrough

Replaces many test occurrences of Pester’s { ... } | Should -Not -Throw with direct invocations that assign results to $null (often adding -ErrorAction 'Stop'), removes redundant script-block braces, and normalizes -ErrorAction Stop to -ErrorAction 'Stop' across tests, CI workflows, and a few module literals. No public API changes.

Changes

Cohort / File(s) Summary
Integration — Commands
tests/Integration/Commands/*, tests/Integration/Commands/.../*.Integration.Tests.ps1
Replaced `{ ... }
Integration — Resources (DSC_*)
tests/Integration/Resources/DSC_*
Flattened script-block wrappers; invoke configurations and Start-DscConfiguration directly with $null captures; standardized Get-DscConfiguration -ErrorAction 'Stop'.
Unit — DSC resources & tests
tests/Unit/DSC_*, tests/Unit/Private/*
Replaced Should -Not -Throw wrappers for Get-TargetResource/Set-TargetResource and helper calls with direct invocations assigned to $null, adding -ErrorAction 'Stop' when appropriate.
Unit — Public cmdlet tests
tests/Unit/Public/*
Converted public-cmdlet tests to $null = <cmdlet> ... style (many with -ErrorAction 'Stop'); preserved existing verifications and mocks.
Unit — Classes & general unit tests
tests/Unit/Classes/*, tests/Unit/*
Replaced constructor/method Should -Not -Throw assertions with direct instantiation/calls assigned to $null; no API changes.
QA & CI
tests/QA/module.tests.ps1, .github/workflows/*
Normalized -ErrorAction Stop-ErrorAction 'Stop'; replaced some Should -Not -Throw wrappers with $null assignments.
Production modules (small literal fixes)
source/DSCResources/**/DSC_*.psm1, source/Modules/SqlServerDsc.Common/*.psm1
Minor edits changing -ErrorAction Stop to -ErrorAction 'Stop' in a few calls; no behavioral changes.
Changelog & docs
CHANGELOG.md, .github/instructions/...
Documents the testing-style change and standardizes -ErrorAction 'Stop' usage.

Sequence Diagram(s)

(No sequence diagram provided — changes are test-style refactors without new runtime control flow to diagram.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The pull request also includes changes to production module files where -ErrorAction Stop is quoted as 'Stop', which falls outside the stated scope of test-only updates defined in the linked issues focused on tests. Limit changes strictly to test files or update the linked issue scope to include production module style adjustments to prevent unintended scope expansion.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title “Remove Should -Not -Throw” succinctly captures the primary change of eliminating the Should -Not -Throw test assertions across the codebase and directly reflects the main objective of the pull request.
Linked Issues Check ✅ Passed The changes comprehensively address issue #2275 by replacing Should -Not -Throw wrappers with direct invocations assigning to $null and meet issue #2276 by updating cleanup operations to use -ErrorAction 'Stop' and $null assignments across all unit and integration tests.
Description Check ✅ Passed The pull request description references the relevant issue numbers and anchors the changes to issues #2275 and #2276, making it related to the changeset even though it lacks detailed change summaries.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 14

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
tests/Unit/DSC_SqlScript.Tests.ps1 (2)

194-200: LGTM! Direct invocation pattern correctly applied.

The change from Should -Not -Throw to direct invocation with $null assignment aligns with the project test guidelines. However, the test description "Should return the expected results" is misleading since Set-TargetResource is void and returns nothing.

Consider revising the test description to accurately reflect the test's purpose:

-        It 'Should return the expected results' {
+        It 'Should complete without error' {

Based on learnings


210-219: LGTM! Direct invocation pattern correctly applied.

The change from Should -Not -Throw to direct invocation with $null assignment aligns with the project test guidelines. However, the test description "Should return the expected results" is misleading since Set-TargetResource is void and returns nothing.

Consider revising the test description to accurately reflect the test's purpose:

-        It 'Should return the expected results' {
+        It 'Should complete without error with query timeout' {

Based on learnings

tests/Unit/DSC_SqlAgentOperator.Tests.ps1 (1)

538-549: Correct the It block description.

The description "Should return the state as true" is incorrect. Based on learnings, Set-TargetResource must not return anything (void). Consider updating the description to reflect what the test actually verifies, such as "Should create the sql agent operator with email address".

Apply this diff:

-            It 'Should return the state as true' {
+            It 'Should create the sql agent operator with email address' {
tests/Unit/SqlServerDsc.Common.Tests.ps1 (1)

507-514: Remove leftover braces from the refactored test.

The inner braces on lines 507 and 514 are artifacts from the original Should -Not -Throw pattern and should be removed. This test block should match the pattern used in similar tests at lines 433-438 and 470-475.

Apply this diff to remove the unnecessary braces:

         It 'Should call the correct mocks' {
-            {
-                $invokeInstallationMediaCopyParameters = @{
-                    SourcePath = $mockSourcePathUNC
-                    SourceCredential = $mockShareCredential
-                }
-
-                $null = Invoke-InstallationMediaCopy @invokeInstallationMediaCopyParameters -ErrorAction 'Stop'
-            }
+            $invokeInstallationMediaCopyParameters = @{
+                SourcePath = $mockSourcePathUNC
+                SourceCredential = $mockShareCredential
+            }
+
+            $null = Invoke-InstallationMediaCopy @invokeInstallationMediaCopyParameters -ErrorAction 'Stop'
🧹 Nitpick comments (3)
tests/Unit/DSC_SqlAgentOperator.Tests.ps1 (3)

505-515: Update the It block description.

The description "Should not throw" is now misleading since the Should -Not -Throw assertion was removed. Consider updating it to describe what the test actually verifies, such as "Should create the sql agent operator" or "Should call Set-TargetResource successfully".

Apply this diff:

-            It 'Should not throw' {
+            It 'Should create the sql agent operator' {

555-566: Update the It block description.

The description "Should not throw" is now misleading since the Should -Not -Throw assertion was removed. Consider updating it to describe what the test actually verifies, such as "Should update the email address".

Apply this diff:

-            It 'Should not throw' {
+            It 'Should update the email address' {

578-588: Update the It block description.

The description "Should not throw" is now misleading since the Should -Not -Throw assertion was removed. Consider updating it to describe what the test actually verifies, such as "Should drop the sql agent operator".

Apply this diff:

-            It 'Should not throw' {
+            It 'Should drop the sql agent operator' {

@codecov
Copy link

codecov bot commented Oct 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94%. Comparing base (a2d3b29) to head (81bbdbf).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@         Coverage Diff          @@
##           main   #2302   +/-   ##
====================================
  Coverage    94%     94%           
====================================
  Files       150     150           
  Lines      9239    9239           
====================================
  Hits       8751    8751           
  Misses      488     488           
Flag Coverage Δ
unit 94% <100%> (ø)
Files with missing lines Coverage Δ
source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1 96% <100%> (ø)
...Resources/DSC_SqlAGListener/DSC_SqlAGListener.psm1 98% <100%> (ø)
...SCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1 99% <100%> (ø)
source/DSCResources/DSC_SqlLogin/DSC_SqlLogin.psm1 100% <100%> (ø)
...dules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 96% <100%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

johlju added 14 commits October 12, 2025 08:19
…operator creation, email update, and deletion scenarios
…iterals for ErrorAction parameter

- Updated multiple test files to replace `-ErrorAction Stop` with `-ErrorAction 'Stop'` for consistency.
- Ensured that all instances of the ErrorAction parameter across various test scripts are uniformly formatted.
- This change enhances readability and maintains a consistent coding style throughout the test suite.
Copy link

@coderabbitai coderabbitai bot left a 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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 (1)

38-38: Update cleanup commands per PR objectives.

Lines 38 and 59 still use -ErrorAction 'SilentlyContinue' for cleanup operations. According to Issue #2276 objectives, cleanup commands should be changed to use -ErrorAction 'Stop' with $null = assignment instead.

Apply these changes:

-    Remove-Item -Path 'Env:\SqlServerDscCI' -ErrorAction 'SilentlyContinue'
+    $null = Remove-Item -Path 'Env:\SqlServerDscCI' -ErrorAction 'Stop'
-        $script:sqlServerObject | Remove-SqlDscAgentOperator -Name 'IntegrationTest_AssertOperator' -Force -ErrorAction 'SilentlyContinue'
+        $null = $script:sqlServerObject | Remove-SqlDscAgentOperator -Name 'IntegrationTest_AssertOperator' -Force -ErrorAction 'Stop'

Also applies to: 59-59

tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 (1)

110-110: Add missing -ErrorAction 'Stop' for consistency.

The cleanup at line 59 uses -ErrorAction 'Stop' on Remove-SqlDscDatabase, but line 110 omits this parameter. For consistent error handling and to ensure cleanup failures surface immediately, add -ErrorAction 'Stop' here as well.

Apply this diff to add the missing parameter:

-                    $null = Remove-SqlDscDatabase -DatabaseObject $dbToRemove -Force
+                    $null = Remove-SqlDscDatabase -DatabaseObject $dbToRemove -Force -ErrorAction 'Stop'

Based on learnings.

♻️ Duplicate comments (6)
tests/Unit/Classes/SqlDatabasePermission.Tests.ps1 (4)

1181-1196: Past review comment addressed.

The Modify() call now correctly assigns the result to $null, addressing the previous review feedback and following the PR objective to replace Should -Not -Throw patterns with direct invocation.

Based on learnings.


1269-1284: Past review comment addressed.

The Modify() call now correctly assigns the result to $null, addressing the previous review feedback and maintaining consistency with the pattern established throughout the file.

Based on learnings.


1369-1384: Past review comment addressed.

The Modify() call now correctly assigns the result to $null, addressing the previous review feedback for PermissionToInclude scenario and aligning with the PR objectives.

Based on learnings.


1459-1474: Past review comment addressed.

The Modify() call now correctly assigns the result to $null, addressing the previous review feedback for PermissionToExclude scenario and completing the pattern across all permission property variations.

Based on learnings.

tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 (2)

74-148: Remove commented-out code.

This large commented-out block violates the coding guideline "No commented-out code." The historical implementation attempt and error messages should be removed to improve maintainability.

Based on coding guidelines.


214-290: Remove commented-out code.

This large commented-out block violates the coding guideline "No commented-out code." The historical implementation attempt should be removed to improve maintainability.

Based on coding guidelines.

🧹 Nitpick comments (6)
tests/Unit/DSC_SqlAGListener.Tests.ps1 (1)

157-157: Consider adding -ErrorAction 'Stop' for consistency.

While the direct invocation correctly follows the guideline to remove Should -Not -Throw, consider adding -ErrorAction 'Stop' to these Get-TargetResource calls for consistency with the Set-TargetResource invocations throughout this file (lines 747, 794, 871, etc.). This ensures failures surface immediately and error handling is uniform across all test commands.

Based on learnings

Apply this pattern:

-$null = Get-TargetResource @mockGetTargetResourceParameters
+$null = Get-TargetResource @mockGetTargetResourceParameters -ErrorAction 'Stop'

Also applies to: 244-244, 318-318, 392-392

tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 (1)

59-67: Simplify redundant error handling.

The try-catch block wrapping Remove-SqlDscAudit with -ErrorAction 'SilentlyContinue' is redundant. Since SilentlyContinue already suppresses errors, the try-catch serves no purpose.

Apply this diff to simplify:

-        foreach ($audit in $testAudits)
-        {
-            try
-            {
-                Remove-SqlDscAudit -AuditObject $audit -Force -ErrorAction 'SilentlyContinue'
-            }
-            catch
-            {
-                # Ignore cleanup errors
-            }
-        }
+        foreach ($audit in $testAudits)
+        {
+            Remove-SqlDscAudit -AuditObject $audit -Force -ErrorAction 'SilentlyContinue'
+        }
tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 (4)

46-46: Approve style consistency change; consider assigning output to $null.

The change from unquoted Stop to quoted 'Stop' aligns with the consistent error handling pattern across integration tests.

Additionally, New-SqlDscAgentAlert likely returns the created alert object. Since the return value is unused, assign it to $null to follow best practices.

Apply this diff:

-        $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_UpdateAlert' -Severity 14 -ErrorAction 'Stop'
+        $null = $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_UpdateAlert' -Severity 14 -ErrorAction 'Stop'

50-50: Consider using -ErrorAction 'Stop' in cleanup per PR objectives.

Issue #2276 recommends changing cleanup commands to use -ErrorAction 'Stop' instead of 'SilentlyContinue' to ensure failures surface immediately. This helps catch unexpected cleanup failures.

If the alert might not exist (e.g., if BeforeAll fails), consider using a conditional check or accepting that the cleanup will throw an error in that scenario.

Based on PR objectives.

Apply this diff if the alert is expected to exist:

-        $null = $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_UpdateAlert' -Force -ErrorAction 'SilentlyContinue'
+        $null = $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_UpdateAlert' -Force -ErrorAction 'Stop'

75-75: Assign unused query output to $null.

Inside It blocks, assign unused return objects to $null unless they're part of a pipeline. Invoke-SqlDscQuery likely returns query results that are not used here.

As per coding guidelines.

Apply this diff:

-        $script:sqlServerObject | Invoke-SqlDscQuery -DatabaseName 'master' -Query $addMessageQuery -Verbose -Force -ErrorAction 'Stop'
+        $null = $script:sqlServerObject | Invoke-SqlDscQuery -DatabaseName 'master' -Query $addMessageQuery -Verbose -Force -ErrorAction 'Stop'

87-87: Assign unused command output to $null.

Inside It blocks, assign unused return objects to $null unless they're part of a pipeline. Set-SqlDscAgentAlert may return an object that is not used here.

As per coding guidelines.

Apply this diff:

-        $script:sqlServerObject | Set-SqlDscAgentAlert -Name 'IntegrationTest_UpdateAlert' -Severity 14 -ErrorAction 'Stop' -Force
+        $null = $script:sqlServerObject | Set-SqlDscAgentAlert -Name 'IntegrationTest_UpdateAlert' -Severity 14 -ErrorAction 'Stop' -Force

Copy link

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (1)
tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 (1)

55-55: Consider suppressing output for consistency.

While not strictly required by the PR objectives (which focus on test assertions and cleanup), assigning the result to $null would maintain consistency with the cleanup patterns being applied throughout this PR and prevent unwanted output.

Apply this diff if you'd like to maintain consistency:

-        $script:sqlServerObject | New-SqlDscAgentOperator -Name 'IntegrationTest_AssertOperator' -EmailAddress '[email protected]' -ErrorAction 'Stop'
+        $null = $script:sqlServerObject | New-SqlDscAgentOperator -Name 'IntegrationTest_AssertOperator' -EmailAddress '[email protected]' -ErrorAction 'Stop'
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ac5eaec and f68b64b.

📒 Files selected for processing (6)
  • tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 (2 hunks)
  • tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 (9 hunks)
  • tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 (3 hunks)
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 (3 hunks)
  • tests/Unit/DSC_SqlAGListener.Tests.ps1 (14 hunks)
  • tests/Unit/DSC_SqlEndpointPermission.Tests.ps1 (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/Unit/DSC_SqlAGListener.Tests.ps1
🧰 Additional context used
📓 Path-based instructions (10)
**/*.[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 inside Describe blocks
Assertions only in It blocks
Never test verbose messages, debug messages, or parameter binding behavior
Pass all mandatory parameters to avoid prompts
Inside It blocks, assign unused return objects to $null (unless part of a pipeline)
Call the tested entity from within the It blocks
Keep results and assertions in the same It block
Avoid try/catch/finally for cleanup; use AfterAll or AfterEach
Avoid unnecessary remove/recreate cycles
One Describe block per file matching the tested entity name
Context descriptions start with 'When'
It descriptions start with 'Should' and must not contain 'when'
Mock variables must be prefixed with 'mock'
Public commands: never use InModuleScope (except for retrieving localized strings)
Private functions and class resources: always use InModuleScope
Each class method gets a separate Context block
Each scenario gets a separate Context block
Use nested Context blocks for complex scenarios
Perform mocking in BeforeAll (use BeforeEach only when required)
Place setup/teardown (BeforeAll/BeforeEach/AfterAll/AfterEach) close to usage
Use PascalCase for Pester keywords: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
Use -BeTrue/-BeFalse; never use -Be $true/-Be $false
Never use Assert-MockCalled; use Should -Invoke instead
Do not use Should -Not -Throw; invoke commands directly
Never add an empty -MockWith block
Omit -MockWith when returning $null
Set $PSDefaultParameterValues for Mock:ModuleName, Should:ModuleName, and InModuleScope:ModuleName
Omit the -ModuleName parameter on Pester commands
Never use Mock inside an InModuleScope block
Define variables for -ForEach in a separate BeforeDiscovery near usage
Use -ForEach only on Context and It blocks
Keep variable scope close to the usage c...

Files:

  • tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1
  • tests/Unit/DSC_SqlEndpointPermission.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1

⚙️ CodeRabbit configuration file

**/*.[Tt]ests.ps1: # Tests Guidelines

Core 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 Describe blocks
  • Assertions only in It blocks
  • Never test verbose messages, debug messages or parameter binding behavior
  • Pass all mandatory parameters to avoid prompts

Requirements

  • Inside It blocks, assign unused return objects to $null (unless part of pipeline)
  • Tested entity must be called from within the It blocks
  • Keep results and assertions in same It block
  • Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
  • Avoid unnecessary remove/recreate cycles

Naming

  • One Describe block per file matching the tested entity name
  • Context descriptions start with 'When'
  • It descriptions start with 'Should', must not contain 'when'
  • Mock variables prefix: 'mock'

Structure & Scope

  • Public commands: Never use InModuleScope (unless retrieving localized strings)
  • Private functions/class resources: Always use InModuleScope
  • Each class method = separate Context block
  • Each scenario = separate Context block
  • Use nested Context blocks for complex scenarios
  • Mocking in BeforeAll (BeforeEach only when required)
  • Setup/teardown in BeforeAll,BeforeEach/AfterAll,AfterEach close to usage

Syntax Rules

  • PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
  • Use -BeTrue/-BeFalse never -Be $true/-Be $false
  • Never use Assert-MockCalled, use Should -Invoke instead
  • No Should -Not -Throw - invoke commands directly
  • Never add an empty -MockWith block
  • Omit -MockWith when returning $null
  • Set $PSDefaultParameterValues for Mock:ModuleName, Should:ModuleName, InModuleScope:ModuleName
  • Omit -ModuleName parameter on Pester commands
  • Never use Mock inside `InModuleSc...

Files:

  • tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1
  • tests/Unit/DSC_SqlEndpointPermission.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
tests/[iI]ntegration/Commands/*.[iI]ntegration.[tT]ests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md)

Place command integration tests at tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Files:

  • tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md)

tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1: Do not use mocking in integration tests; run against a real environment
In CI, use Get-ComputerName for computer names
Avoid using ExpectedMessage with Should -Throw assertions
When invoking commands in integration tests, pass -Force where applicable to avoid prompts
Use -ErrorAction Stop on commands so failures surface immediately
At the top of each integration test file, include SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments') with an empty justification parameter and param ()
In BeforeDiscovery, ensure DscResource.Test is available; if not loaded or not available, run build.ps1 -Tasks 'noop' (suppressing non-error streams) and Import-Module 'DscResource.Test' -Force -ErrorAction Stop
Catch [System.IO.FileNotFoundException] during setup and throw: "DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first."
In BeforeAll, set $script:moduleName and Import-Module -Name $script:moduleName -Force -ErrorAction Stop

Files:

  • tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1

⚙️ CodeRabbit configuration file

tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1: # Integration Tests Guidelines

Requirements

  • Location Commands: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1
  • Location Resources: tests/Integration/Resources/{ResourceName}.Integration.Tests.ps1
  • No mocking - real environment only
  • Cover all scenarios and code paths
  • Use Get-ComputerName for computer names in CI
  • Avoid ExpectedMessage for Should -Throw assertions
  • Only run integration tests in CI unless explicitly instructed.
  • Call commands with -Force parameter where applicable (avoids prompting).
  • Use -ErrorAction 'Stop' on commands so failures surface immediately

Required Setup Block

[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 -Force -ErrorAction 'Stop'
}

Files:

  • tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
**/*.{ps1,psm1}

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-powershell.instructions.md)

**/*.{ps1,psm1}: Use descriptive names (3+ characters, no abbreviations)
Function names use PascalCase Verb-Noun with approved verbs
Parameter names use PascalCase
Variable names use camelCase
Keywords are lower-case
Class names use PascalCase
Include scope prefixes for script/global/environment variables: $script:, $global:, $env:
Use one space around operators (e.g., $a = 1 + 2)
Use one space between type and variable (e.g., [String] $name)
Use one space between keyword and parenthesis (e.g., if ($condition))
Place 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)
Use single quotes unless variable expansion is needed
Arrays on one line use @('one','two'); multi-line arrays have one element per line with proper indentation
Do not use unary comma in return statements to force an array
Single-line comments: '# Comment' capitalized on its own line
Multi-line comments use <# #> with brackets on their own lines and indented text
No commented-out code
Add comment-based help to all functions and scripts
Comment-based help must include SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, and EXAMPLE sections before function/class
Comment-based help indentation: keywords at 4 spaces, text at 8 spaces
Include examples for all parameter sets and combinations
INPUTS: list each pipeline-accepted type with one-line description; repeat .INPUTS per type
OUTPUTS: list each return type with one-line description; repeat .OUTPUTS per type; must match [OutputType()] and actual returns
.NOTES only if critical (constraints, side effects, security, version compatibility, breaking behavior), ≤2 short sentences
Avoid aliases; use full command names
Avoid Write-Host; prefer Write-Verbose/Write-Information/etc.
Avoid Write-Output; use return instead
Do not use ConvertTo-SecureString -AsPlainText in production code
Do not redefine reserved parameters (Verbose, Debug, etc.)
In...

Files:

  • tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1
  • tests/Unit/DSC_SqlEndpointPermission.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
**/*.{ps1,psm1,psd1}

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-powershell.instructions.md)

**/*.{ps1,psm1,psd1}: Indent with 4 spaces; do not use tabs
No spaces on empty lines
Try to limit lines to 120 characters
Empty hashtable is @{}
Hashtable: each property on its own line with proper indentation
Hashtable property names use PascalCase
End files with exactly one blank line
Use line endings as defined by .gitattributes policy
Allow at most two consecutive newlines
No trailing whitespace on any line
Use UTF-8 encoding without BOM for all files

Files:

  • tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1
  • tests/Unit/DSC_SqlEndpointPermission.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
tests/Integration/Commands/*.Integration.Tests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines.instructions.md)

tests/Integration/Commands/*.Integration.Tests.ps1: Place integration tests for public commands in tests/Integration/Commands/{CommandName}.Integration.Tests.ps1
Add integration tests for all public commands (and resources)

Files:

  • tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
**/*.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines.instructions.md)

Follow PowerShell style and test guideline instructions strictly

Files:

  • tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1
  • tests/Unit/DSC_SqlEndpointPermission.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • 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 pwsh session): ./build.ps1 -Tasks noop
  • Build project before running tests: ./build.ps1 -Tasks build
  • Always run tests in new pwsh session: Invoke-Pester -Path @({test paths}) -Output Detailed

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • 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/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1
  • tests/Unit/DSC_SqlEndpointPermission.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
{**/*.ps1,**/*.psm1,**/*.psd1}

⚙️ CodeRabbit configuration file

{**/*.ps1,**/*.psm1,**/*.psd1}: # PowerShell Guidelines

Naming

  • 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.ps1 format (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 array

Hashtables

  • 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 (one per line) with a 1‑line description...

Files:

  • tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1
  • tests/Unit/DSC_SqlEndpointPermission.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.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: In unit tests, access localized strings using InModuleScope -ScriptBlock { $script:localizedData.Key }
When mocking files in tests, use the $TestDrive variable for file system operations
All public commands must include parameter set validation tests
Include the exact Pester setup block before Describe: SuppressMessage attribute with param (); BeforeDiscovery to ensure DscResource.Test is available (fallback to build.ps1 -Tasks 'noop') and Import-Module; BeforeAll to set $script:moduleName, import the module, and set PSDefaultParameterValues for InModuleScope/Mock/Should; AfterAll to remove those defaults and unload the tested module
Use the provided Parameter Set Validation test template to assert command ParameterSetName and full parameter list string; for multiple parameter sets, supply multiple hashtables via -ForEach
Use the Parameter Properties template to assert a parameter is mandatory via $parameterInfo = (Get-Command -Name 'CommandName').Parameters['ParameterName']; $parameterInfo.Attributes.Mandatory | Should -BeTrue

Files:

  • tests/Unit/DSC_SqlEndpointPermission.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 $TestDrive variable (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 -Force -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:ModuleNam...

Files:

  • tests/Unit/DSC_SqlEndpointPermission.Tests.ps1
🧠 Learnings (9)
📓 Common learnings
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-12T13:21:31.054Z
Learning: Applies to **/*.[Tt]ests.ps1 : Do not use Should -Not -Throw; invoke commands directly
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-09-16T16:32:58.363Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : Use -ErrorAction Stop on commands so failures surface immediately
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-09-16T16:32:58.363Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : Avoid using ExpectedMessage with Should -Throw assertions
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-16T16:34:27.319Z
Learning: Applies to **/*.{ps1,psm1} : Set $ErrorActionPreference='Stop' immediately before commands using -ErrorAction 'Stop' and restore after; do not use try-catch-finally for this
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-16T16:34:27.319Z
Learning: Applies to **/*.{ps1,psm1} : Avoid empty catch blocks; prefer -ErrorAction SilentlyContinue
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-12T13:21:31.054Z
Learning: Applies to **/*.[Tt]ests.ps1 : Inside It blocks, assign unused return objects to $null (unless part of a pipeline)
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-12T13:21:31.054Z
Learning: Applies to **/*.[Tt]ests.ps1 : Use Pester v5 syntax only
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-12T13:21:31.054Z
Learning: Applies to **/*.[Tt]ests.ps1 : Avoid try/catch/finally for cleanup; use AfterAll or AfterEach
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-12T13:21:31.054Z
Learning: Applies to **/*.[Tt]ests.ps1 : Never use Assert-MockCalled; use Should -Invoke instead
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-12T13:21:31.054Z
Learning: Applies to **/*.[Tt]ests.ps1 : Omit -MockWith when returning $null
📚 Learning: 2025-09-16T16:32:58.363Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-09-16T16:32:58.363Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : Use -ErrorAction Stop on commands so failures surface immediately

Applied to files:

  • tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1
  • tests/Unit/DSC_SqlEndpointPermission.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-09-23T10:20:59.832Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-09-23T10:20:59.832Z
Learning: In unit tests, add $env:SqlServerDscCI = $true in BeforeAll and remove it in AfterAll

Applied to files:

  • tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-09-16T16:32:58.363Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-09-16T16:32:58.363Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : In BeforeAll, set $script:moduleName and Import-Module -Name $script:moduleName -Force -ErrorAction Stop

Applied to files:

  • tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1
📚 Learning: 2025-09-12T13:21:31.054Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-12T13:21:31.054Z
Learning: Applies to **/*.[Tt]ests.ps1 : Avoid unnecessary remove/recreate cycles

Applied to files:

  • tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1
📚 Learning: 2025-09-23T10:20:59.832Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-09-23T10:20:59.832Z
Learning: Integration tests must use Connect-SqlDscDatabaseEngine with correct CI credentials and call Disconnect-SqlDscDatabaseEngine after

Applied to files:

  • tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-09-12T13:20:57.155Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-09-12T13:20:57.155Z
Learning: Applies to source/DSCResources/**/*.psm1 : Set-TargetResource must not return anything (void)

Applied to files:

  • tests/Unit/DSC_SqlEndpointPermission.Tests.ps1
📚 Learning: 2025-09-12T13:20:57.155Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-09-12T13:20:57.155Z
Learning: Applies to source/DSCResources/**/*.psm1 : Set-TargetResource and Test-TargetResource must have identical parameters

Applied to files:

  • tests/Unit/DSC_SqlEndpointPermission.Tests.ps1
📚 Learning: 2025-08-18T13:50:53.789Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2132
File: tests/Unit/Public/New-SqlDscLogin.Tests.ps1:0-0
Timestamp: 2025-08-18T13:50:53.789Z
Learning: In SqlServerDsc unit tests, SMO stub objects can be used to verify method calls like Create() on Login objects by adding mock verifications with Should -Invoke, providing more robust testing than just checking for no exceptions.

Applied to files:

  • tests/Integration/Commands/New-SqlDscAudit.Integration.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: Setup PowerShell Development Environment
🔇 Additional comments (17)
tests/Unit/DSC_SqlEndpointPermission.Tests.ps1 (4)

332-332: LGTM!

The change correctly replaces the Should -Not -Throw pattern with direct invocation. The -ErrorAction 'Stop' ensures failures surface as exceptions, and the $null assignment properly captures unused output.

Based on learnings


355-355: LGTM!

The change correctly implements the test pattern update. Direct invocation with -ErrorAction 'Stop' and $null assignment aligns with the PR objectives and DSC Community test guidelines.

Based on learnings


433-433: LGTM!

The change correctly removes the Should -Not -Throw wrapper and implements direct invocation. The -ErrorAction 'Stop' ensures exceptions are raised for failures.

Based on learnings


460-460: LGTM!

The change correctly implements the direct invocation pattern with -ErrorAction 'Stop' and $null assignment, consistent with the other changes in this file and the PR objectives.

Based on learnings

tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 (1)

46-115: LGTM! Changes correctly implement the PR objectives.

All modifications properly replace Should -Not -Throw patterns with direct command invocations using $null = Command -ErrorAction 'Stop', which aligns with the project's test guidelines. The cleanup operations now use -ErrorAction 'Stop' instead of -ErrorAction 'SilentlyContinue', ensuring failures surface immediately.

The error test cases at lines 108-109 and 113-114 correctly retain Should -Throw for testing expected failure scenarios, which is the appropriate pattern per Pester best practices.

Based on learnings.

tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 (6)

42-42: LGTM!

The connection setup correctly uses -ErrorAction 'Stop' to ensure failures surface immediately during integration tests. Based on learnings.


49-64: LGTM!

The cleanup pattern correctly uses -ErrorAction 'SilentlyContinue' for the Get operation (to check existence without errors) and -ErrorAction 'Stop' for the Remove operation (to surface failures immediately). This aligns with the PR objectives which focus on Remove operations using 'Stop'.


67-77: LGTM!

The test correctly uses direct invocation with -ErrorAction 'Stop' on both New-SqlDscDatabase and Get-SqlDscDatabase commands, ensuring failures surface immediately in integration tests. Based on learnings.


79-90: LGTM!

The test correctly uses direct invocation with -ErrorAction 'Stop', consistent with integration test guidelines.


92-95: LGTM!

The script block with Should -Throw is the correct pattern for testing that an operation should fail (duplicate database creation). This is different from the anti-pattern Should -Not -Throw that the PR aims to remove. The script block is necessary here to capture the expected error.


98-123: LGTM!

The test correctly uses direct invocation with -ErrorAction 'Stop' for the New-SqlDscDatabase command. The AfterEach cleanup follows the same safe pattern as AfterAll, using 'SilentlyContinue' for checking existence and 'Stop' for the actual removal.

tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 (3)

38-38: LGTM! Cleanup now uses direct invocation with explicit error handling.

The environment variable cleanup correctly assigns output to $null and uses -ErrorAction 'Stop' to ensure failures surface immediately, aligning with the PR objectives and integration test guidelines.


59-77: LGTM! Test patterns correctly refactored.

The changes successfully replace Should -Not -Throw patterns with direct command invocation:

  • Line 59: Cleanup operation properly assigns to $null with -ErrorAction 'Stop'
  • Lines 67, 71: Tests now invoke commands directly with $null assignment instead of wrapping in script blocks
  • Line 75: Appropriately assigns to $result variable for value assertion

All changes align with the PR objectives and follow the DSC Community test guidelines.

Based on learnings


82-82: LGTM! Negative test correctly uses Should -Throw.

The script block wrapper and Should -Throw assertion are appropriate here since the test verifies that a terminating error is thrown for a non-existent operator. This differs from the Should -Not -Throw patterns being removed elsewhere in the PR.

tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 (3)

42-42: LGTM: Standardized ErrorAction syntax.

The change from -ErrorAction Stop to -ErrorAction 'Stop' follows PowerShell best practices by using quoted strings for parameter values.


86-289: LGTM: ErrorAction syntax standardized across all test cases.

All test execution commands have been correctly updated to use -ErrorAction 'Stop' with quoted strings, ensuring failures surface immediately as required by the integration test guidelines.


308-322: LGTM: Should -Not -Throw pattern correctly removed.

Line 310 correctly replaces the Should -Not -Throw pattern with direct invocation using $null = assignment. Lines 313-314 and 320-321 appropriately retain Should -Throw for negative test cases to verify that errors are thrown in error conditions.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1 (2)

109-117: Consider removing unnecessary -PassThru parameters.

Lines 111 and 115 use -PassThru but discard the output by assigning to $null. Since these tests verify StatementTimeout and RedactText parameters (not PassThru functionality), the -PassThru parameter appears unnecessary.

Apply this diff to remove the unnecessary parameter:

-                $null = Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query 'SELECT COUNT(*) FROM TestTable' -StatementTimeout 30 -PassThru -Force -ErrorAction 'Stop'
+                $null = Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query 'SELECT COUNT(*) FROM TestTable' -StatementTimeout 30 -Force -ErrorAction 'Stop'
-                $null = Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query "SELECT * FROM TestTable WHERE Name = 'SensitiveData'" -RedactText @('SensitiveData') -PassThru -Force -ErrorAction 'Stop'
+                $null = Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query "SELECT * FROM TestTable WHERE Name = 'SensitiveData'" -RedactText @('SensitiveData') -Force -ErrorAction 'Stop'

147-164: Consider removing unnecessary -PassThru parameters.

Lines 150, 158, and 162 use -PassThru but discard the output by assigning to $null. Since these tests verify Encrypt, LoginType, and StatementTimeout parameters respectively (not PassThru functionality), the -PassThru parameter appears unnecessary.

Apply this diff to remove the unnecessary parameters:

-                $null = Invoke-SqlDscQuery -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -DatabaseName $script:testDatabaseName -Query 'SELECT 1 as TestValue' -Encrypt -PassThru -Force -ErrorAction 'Stop'
+                $null = Invoke-SqlDscQuery -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -DatabaseName $script:testDatabaseName -Query 'SELECT 1 as TestValue' -Encrypt -Force -ErrorAction 'Stop'
-                $null = Invoke-SqlDscQuery -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -Credential $sqlLoginCredential -LoginType 'SqlLogin' -DatabaseName $script:testDatabaseName -Query 'SELECT 1 as TestValue' -PassThru -Force -ErrorAction 'Stop'
+                $null = Invoke-SqlDscQuery -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -Credential $sqlLoginCredential -LoginType 'SqlLogin' -DatabaseName $script:testDatabaseName -Query 'SELECT 1 as TestValue' -Force -ErrorAction 'Stop'
-                $null = Invoke-SqlDscQuery -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -DatabaseName $script:testDatabaseName -Query 'SELECT 1 as TestValue' -StatementTimeout 60 -PassThru -Force -ErrorAction 'Stop'
+                $null = Invoke-SqlDscQuery -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -DatabaseName $script:testDatabaseName -Query 'SELECT 1 as TestValue' -StatementTimeout 60 -Force -ErrorAction 'Stop'
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 67a1b09 and 81bbdbf.

📒 Files selected for processing (1)
  • tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1 (4 hunks)
🧰 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 inside Describe blocks
Assertions only in It blocks
Never test verbose messages, debug messages, or parameter binding behavior
Pass all mandatory parameters to avoid prompts
Inside It blocks, assign unused return objects to $null (unless part of a pipeline)
Call the tested entity from within the It blocks
Keep results and assertions in the same It block
Avoid try/catch/finally for cleanup; use AfterAll or AfterEach
Avoid unnecessary remove/recreate cycles
One Describe block per file matching the tested entity name
Context descriptions start with 'When'
It descriptions start with 'Should' and must not contain 'when'
Mock variables must be prefixed with 'mock'
Public commands: never use InModuleScope (except for retrieving localized strings)
Private functions and class resources: always use InModuleScope
Each class method gets a separate Context block
Each scenario gets a separate Context block
Use nested Context blocks for complex scenarios
Perform mocking in BeforeAll (use BeforeEach only when required)
Place setup/teardown (BeforeAll/BeforeEach/AfterAll/AfterEach) close to usage
Use PascalCase for Pester keywords: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
Use -BeTrue/-BeFalse; never use -Be $true/-Be $false
Never use Assert-MockCalled; use Should -Invoke instead
Do not use Should -Not -Throw; invoke commands directly
Never add an empty -MockWith block
Omit -MockWith when returning $null
Set $PSDefaultParameterValues for Mock:ModuleName, Should:ModuleName, and InModuleScope:ModuleName
Omit the -ModuleName parameter on Pester commands
Never use Mock inside an InModuleScope block
Define variables for -ForEach in a separate BeforeDiscovery near usage
Use -ForEach only on Context and It blocks
Keep variable scope close to the usage c...

Files:

  • tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1

⚙️ CodeRabbit configuration file

**/*.[Tt]ests.ps1: # Tests Guidelines

Core 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 Describe blocks
  • Assertions only in It blocks
  • Never test verbose messages, debug messages or parameter binding behavior
  • Pass all mandatory parameters to avoid prompts

Requirements

  • Inside It blocks, assign unused return objects to $null (unless part of pipeline)
  • Tested entity must be called from within the It blocks
  • Keep results and assertions in same It block
  • Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
  • Avoid unnecessary remove/recreate cycles

Naming

  • One Describe block per file matching the tested entity name
  • Context descriptions start with 'When'
  • It descriptions start with 'Should', must not contain 'when'
  • Mock variables prefix: 'mock'

Structure & Scope

  • Public commands: Never use InModuleScope (unless retrieving localized strings)
  • Private functions/class resources: Always use InModuleScope
  • Each class method = separate Context block
  • Each scenario = separate Context block
  • Use nested Context blocks for complex scenarios
  • Mocking in BeforeAll (BeforeEach only when required)
  • Setup/teardown in BeforeAll,BeforeEach/AfterAll,AfterEach close to usage

Syntax Rules

  • PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
  • Use -BeTrue/-BeFalse never -Be $true/-Be $false
  • Never use Assert-MockCalled, use Should -Invoke instead
  • No Should -Not -Throw - invoke commands directly
  • Never add an empty -MockWith block
  • Omit -MockWith when returning $null
  • Set $PSDefaultParameterValues for Mock:ModuleName, Should:ModuleName, InModuleScope:ModuleName
  • Omit -ModuleName parameter on Pester commands
  • Never use Mock inside `InModuleSc...

Files:

  • tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1
tests/[iI]ntegration/Commands/*.[iI]ntegration.[tT]ests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md)

Place command integration tests at tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Files:

  • tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1
tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md)

tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1: Do not use mocking in integration tests; run against a real environment
In CI, use Get-ComputerName for computer names
Avoid using ExpectedMessage with Should -Throw assertions
When invoking commands in integration tests, pass -Force where applicable to avoid prompts
Use -ErrorAction Stop on commands so failures surface immediately
At the top of each integration test file, include SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments') with an empty justification parameter and param ()
In BeforeDiscovery, ensure DscResource.Test is available; if not loaded or not available, run build.ps1 -Tasks 'noop' (suppressing non-error streams) and Import-Module 'DscResource.Test' -Force -ErrorAction Stop
Catch [System.IO.FileNotFoundException] during setup and throw: "DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first."
In BeforeAll, set $script:moduleName and Import-Module -Name $script:moduleName -Force -ErrorAction Stop

Files:

  • tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1

⚙️ CodeRabbit configuration file

tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1: # Integration Tests Guidelines

Requirements

  • Location Commands: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1
  • Location Resources: tests/Integration/Resources/{ResourceName}.Integration.Tests.ps1
  • No mocking - real environment only
  • Cover all scenarios and code paths
  • Use Get-ComputerName for computer names in CI
  • Avoid ExpectedMessage for Should -Throw assertions
  • Only run integration tests in CI unless explicitly instructed.
  • Call commands with -Force parameter where applicable (avoids prompting).
  • Use -ErrorAction 'Stop' on commands so failures surface immediately

Required Setup Block

[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 -Force -ErrorAction 'Stop'
}

Files:

  • tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1
**/*.{ps1,psm1}

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-powershell.instructions.md)

**/*.{ps1,psm1}: Use descriptive names (3+ characters, no abbreviations)
Function names use PascalCase Verb-Noun with approved verbs
Parameter names use PascalCase
Variable names use camelCase
Keywords are lower-case
Class names use PascalCase
Include scope prefixes for script/global/environment variables: $script:, $global:, $env:
Use one space around operators (e.g., $a = 1 + 2)
Use one space between type and variable (e.g., [String] $name)
Use one space between keyword and parenthesis (e.g., if ($condition))
Place 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)
Use single quotes unless variable expansion is needed
Arrays on one line use @('one','two'); multi-line arrays have one element per line with proper indentation
Do not use unary comma in return statements to force an array
Single-line comments: '# Comment' capitalized on its own line
Multi-line comments use <# #> with brackets on their own lines and indented text
No commented-out code
Add comment-based help to all functions and scripts
Comment-based help must include SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, and EXAMPLE sections before function/class
Comment-based help indentation: keywords at 4 spaces, text at 8 spaces
Include examples for all parameter sets and combinations
INPUTS: list each pipeline-accepted type with one-line description; repeat .INPUTS per type
OUTPUTS: list each return type with one-line description; repeat .OUTPUTS per type; must match [OutputType()] and actual returns
.NOTES only if critical (constraints, side effects, security, version compatibility, breaking behavior), ≤2 short sentences
Avoid aliases; use full command names
Avoid Write-Host; prefer Write-Verbose/Write-Information/etc.
Avoid Write-Output; use return instead
Do not use ConvertTo-SecureString -AsPlainText in production code
Do not redefine reserved parameters (Verbose, Debug, etc.)
In...

Files:

  • tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1
**/*.{ps1,psm1,psd1}

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-powershell.instructions.md)

**/*.{ps1,psm1,psd1}: Indent with 4 spaces; do not use tabs
No spaces on empty lines
Try to limit lines to 120 characters
Empty hashtable is @{}
Hashtable: each property on its own line with proper indentation
Hashtable property names use PascalCase
End files with exactly one blank line
Use line endings as defined by .gitattributes policy
Allow at most two consecutive newlines
No trailing whitespace on any line
Use UTF-8 encoding without BOM for all files

Files:

  • tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1
tests/Integration/Commands/*.Integration.Tests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines.instructions.md)

tests/Integration/Commands/*.Integration.Tests.ps1: Place integration tests for public commands in tests/Integration/Commands/{CommandName}.Integration.Tests.ps1
Add integration tests for all public commands (and resources)

Files:

  • tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1
**/*.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines.instructions.md)

Follow PowerShell style and test guideline instructions strictly

Files:

  • tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • 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 pwsh session): ./build.ps1 -Tasks noop
  • Build project before running tests: ./build.ps1 -Tasks build
  • Always run tests in new pwsh session: Invoke-Pester -Path @({test paths}) -Output Detailed

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • 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/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1
{**/*.ps1,**/*.psm1,**/*.psd1}

⚙️ CodeRabbit configuration file

{**/*.ps1,**/*.psm1,**/*.psd1}: # PowerShell Guidelines

Naming

  • 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.ps1 format (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 array

Hashtables

  • 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 (one per line) with a 1‑line description...

Files:

  • tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1
🧠 Learnings (6)
📓 Common learnings
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-12T13:21:31.054Z
Learning: Applies to **/*.[Tt]ests.ps1 : Do not use Should -Not -Throw; invoke commands directly
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-09-16T16:32:58.363Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : Avoid using ExpectedMessage with Should -Throw assertions
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-12T13:21:31.054Z
Learning: Applies to **/*.[Tt]ests.ps1 : Inside It blocks, assign unused return objects to $null (unless part of a pipeline)
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-12T13:21:31.054Z
Learning: Applies to **/*.[Tt]ests.ps1 : Use Pester v5 syntax only
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-16T16:34:27.319Z
Learning: Applies to **/*.{ps1,psm1} : Avoid empty catch blocks; prefer -ErrorAction SilentlyContinue
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-09-16T16:32:58.363Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : Use -ErrorAction Stop on commands so failures surface immediately
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-12T13:21:31.054Z
Learning: Applies to **/*.[Tt]ests.ps1 : Avoid try/catch/finally for cleanup; use AfterAll or AfterEach
📚 Learning: 2025-09-12T13:21:31.054Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-12T13:21:31.054Z
Learning: Applies to **/*.[Tt]ests.ps1 : Do not use Should -Not -Throw; invoke commands directly

Applied to files:

  • tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1
📚 Learning: 2025-09-16T16:32:58.363Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-09-16T16:32:58.363Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : Avoid using ExpectedMessage with Should -Throw assertions

Applied to files:

  • tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1
📚 Learning: 2025-09-16T16:32:58.363Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-09-16T16:32:58.363Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : When invoking commands in integration tests, pass -Force where applicable to avoid prompts

Applied to files:

  • tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1
📚 Learning: 2025-09-12T13:21:31.054Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-12T13:21:31.054Z
Learning: Applies to **/*.[Tt]ests.ps1 : Inside It blocks, assign unused return objects to $null (unless part of a pipeline)

Applied to files:

  • tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1
📚 Learning: 2025-09-16T16:32:58.363Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-09-16T16:32:58.363Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : At the top of each integration test file, include SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments') with an empty justification parameter and param ()

Applied to files:

  • tests/Integration/Commands/Invoke-SqlDscQuery.Integration.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). (4)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer
  • GitHub Check: PSScriptAnalyzer
  • GitHub Check: Setup PowerShell Development Environment
🔇 Additional comments (3)
tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1 (3)

81-87: Conversions correctly implement the new test pattern.

The test cases now invoke commands directly with $null = assignment instead of using Should -Not -Throw, allowing exceptions to surface naturally. This aligns with the PR objectives and test guidelines.

Based on learnings.


130-135: LGTM! Correct conversion for ByServerName parameter set.

The test correctly invokes the command directly with $null = assignment, following the new pattern.

Based on learnings.


206-221: LGTM! WhatIf test correctly converted.

The test now invokes the command with -WhatIf directly, assigning to $null, and properly verifies that the operation was not executed by comparing record counts.

Based on learnings.

@johlju johlju merged commit 99ad254 into dsccommunity:main Oct 12, 2025
44 checks passed
@johlju johlju deleted the fix/issue#2275 branch October 12, 2025 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant