Skip to content

Adds Test for correct ResourceIds#245

Open
ChristophHannappel wants to merge 2 commits intodsccommunity:mainfrom
ChristophHannappel:ChristophHannappel-patch-1
Open

Adds Test for correct ResourceIds#245
ChristophHannappel wants to merge 2 commits intodsccommunity:mainfrom
ChristophHannappel:ChristophHannappel-patch-1

Conversation

@ChristophHannappel
Copy link
Contributor

@ChristophHannappel ChristophHannappel commented Mar 10, 2026

Pull Request

Pull Request (PR) description

Adds a Test, of the ResourceIDs of the the Composite DSC Ressources end with a [ResourceName]ResourceName.
This is necessary for the DSCWorkshop Framework to use it at the DependsOn Level and helps avoiding an error where the resource can not find its dependency.

Added

  • Test the compiled Mof File if the RessourceID ends with the ResourceName

Task list

  • The PR represents a single logical change. i.e. Cosmetic updates should go in different PRs.
  • Added an entry under the Unreleased section of in the CHANGELOG.md as per format.
  • [] Local clean build passes without issue or fail tests (build.ps1 -ResolveDependency).
  • Resource documentation added/updated in README.md.
  • Resource parameter descriptions added/updated in README.md, schema.mof
    and comment-based help.
  • Comment-based help added/updated.
  • Localization strings added/updated in all localization files as appropriate.
  • Examples appropriately added/updated.
  • Unit tests added/updated. See DSC Resource Testing Guidelines.
  • Integration tests added/updated (where possible). See DSC Resource Testing Guidelines.
  • New/changed code adheres to DSC Resource Style Guidelines and Best Practices.

This change is Reviewable

@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

Walkthrough

A new test case is added to validate that DSC resource MOF files contain ResourceID values ending with a specific naming pattern [<DscResourceName>]<DscResourceName>, with corresponding changelog documentation.

Changes

Cohort / File(s) Summary
Test & Documentation Addition
CHANGELOG.md, tests/Unit/DSCResources/DscResources.Tests.ps1
Added a test case that validates MOF file ResourceID values conform to the expected naming pattern to prevent DependsOn issues with DSCWorkshop Framework. Changelog entry documents the new test.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Adds Test for correct ResourceIds' directly describes the main change: adding a new test case for validating ResourceId format in composite DSC resources.
Description check ✅ Passed The description clearly explains the purpose of the test and why it's needed, relating directly to the ResourceId validation test added in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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: 2

🧹 Nitpick comments (1)
tests/Unit/DSCResources/DscResources.Tests.ps1 (1)

225-225: Rename this It block to start with Should.

The new test name breaks the repo's Pester naming rule. Should have ResourceIDs ending with ... would match the existing convention.

As per coding guidelines, "It descriptions start with 'Should', must not contain 'when'".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/Unit/DSCResources/DscResources.Tests.ps1` at line 225, Rename the
Pester It block description so it begins with "Should" to follow the repo naming
rule: change the It description "'<DscResourceName>' has ResourceIDs ending with
[<DscResourceName>]<DscResourceName>" to something like "Should have ResourceIDs
ending with [<DscResourceName>]<DscResourceName]" while keeping the same test
invocation (It ... -TestCases $testCases) so no other logic changes are needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@CHANGELOG.md`:
- Around line 10-11: The changelog entry contains a malformed example suffix
"[<ResourceName>]<Resourcename" that doesn't match the test's asserted pattern
for ResourceId; update the text so the example uses the correct casing and
bracketed pattern that the test validates (e.g., use
"[<ResourceName>]<ResourceName>" or the exact pattern your test asserts), and
ensure the entry references the ResourceId, ResourceName, DependsOn and
DSCWorkshop Framework consistently so the documented example matches the
implemented assertion.

In `@tests/Unit/DSCResources/DscResources.Tests.ps1`:
- Around line 231-234: Add an explicit assertion that Select-String found
matches before iterating: after the $selectString = Select-String -InputObject
$mofContent -Pattern 'ResourceID = ".+' call and before the foreach ($value in
$selectString.Matches ...) loop, assert that $selectString.Matches.Count |
Should -BeGreaterThan 0 (or equivalent) so the test fails when no ResourceID
lines are present; reference the $selectString variable, the Select-String
invocation, and the foreach loop when making the change.

---

Nitpick comments:
In `@tests/Unit/DSCResources/DscResources.Tests.ps1`:
- Line 225: Rename the Pester It block description so it begins with "Should" to
follow the repo naming rule: change the It description "'<DscResourceName>' has
ResourceIDs ending with [<DscResourceName>]<DscResourceName>" to something like
"Should have ResourceIDs ending with [<DscResourceName>]<DscResourceName]" while
keeping the same test invocation (It ... -TestCases $testCases) so no other
logic changes are needed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 65f7df8e-2604-430b-bfcb-b621c9f915d9

📥 Commits

Reviewing files that changed from the base of the PR and between 4f57b43 and 49151d2.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • tests/Unit/DSCResources/DscResources.Tests.ps1

Comment on lines +10 to +11
- Added a Test
Checks if the ResourceId ends with the [<ResourceName>]<Resourcename to prevent `DependsOn` Issues with the DSCWorkshop Framework.
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix the documented ResourceID suffix example.

[<ResourceName>]<Resourcename is malformed and does not match the pattern the new test is asserting, so the changelog entry is misleading as written.

Suggested wording
-- Added a Test
-  Checks if the ResourceId ends with the [<ResourceName>]<Resourcename to prevent `DependsOn` Issues with the DSCWorkshop Framework.
+- Added a test that verifies composite `ResourceID` values end with `::[<ResourceName>]<ResourceName>` to prevent `DependsOn` issues in the DSCWorkshop framework.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@CHANGELOG.md` around lines 10 - 11, The changelog entry contains a malformed
example suffix "[<ResourceName>]<Resourcename" that doesn't match the test's
asserted pattern for ResourceId; update the text so the example uses the correct
casing and bracketed pattern that the test validates (e.g., use
"[<ResourceName>]<ResourceName>" or the exact pattern your test asserts), and
ensure the entry references the ResourceId, ResourceName, DependsOn and
DSCWorkshop Framework consistently so the documented example matches the
implemented assertion.

Comment on lines +231 to +234
$selectString = Select-String -InputObject $mofContent -Pattern 'ResourceID = ".+' -AllMatches
foreach ($value in $selectString.Matches | Select-Object -ExpandProperty Value)
{
$value | Should -Match -RegularExpression "(ResourceID = `".*)(:{2}\[$DscResourceName\]$DscResourceName`";)"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

In Pester v5, is Should -Match -RegularExpression ""valid syntax, or must the regex be passed positionally asShould -Match ""?

💡 Result:

Yes—Should -Match -RegularExpression "<pattern>" is valid Pester v5 syntax; -RegularExpression is a named parameter for the -Match assertion. The regex can also be passed positionally as Should -Match "<pattern>" (equivalent). [1], [2]


🏁 Script executed:

#!/bin/bash

# Test Select-String behavior when no matches are found
pwsh -NoProfile -Command @'
# Simulate content with no matching ResourceID pattern
$content = "Some other content without ResourceID"
$selectString = Select-String -InputObject $content -Pattern 'ResourceID = ".+' -AllMatches
Write-Host "selectString result: $selectString"
Write-Host "selectString is null: $($selectString -eq $null)"

if ($selectString) {
    $matches = $selectString.Matches | Select-Object -ExpandProperty Value
    Write-Host "matches: $matches"
    Write-Host "matches count: $($matches.Count)"
    $runCount = 0
    foreach ($value in $matches) {
        $runCount++
    }
    Write-Host "foreach executed $runCount times"
} else {
    Write-Host "selectString is falsy, foreach would not run"
}

Write-Host ""
Write-Host "Testing with actual matches:"
# Simulate content WITH matching ResourceID pattern
$content2 = 'ResourceID = "something"'
$selectString2 = Select-String -InputObject $content2 -Pattern 'ResourceID = ".+' -AllMatches
Write-Host "selectString2 result: $selectString2"
Write-Host "selectString2 matches count: $($selectString2.Matches.Count)"
foreach ($value in $selectString2.Matches | Select-Object -ExpandProperty Value) {
    Write-Host "Found: $value"
}
'@

Repository: dsccommunity/CommonTasks

Length of output: 237


🏁 Script executed:

#!/bin/bash
pwsh -NoProfile << 'EOF'
# Test Select-String behavior when no matches are found
$content = "Some other content without ResourceID"
$selectString = Select-String -InputObject $content -Pattern 'ResourceID = ".+' -AllMatches
Write-Host "selectString result: $selectString"
Write-Host "selectString is null: $($null -eq $selectString)"

if ($selectString) {
    $matches = $selectString.Matches | Select-Object -ExpandProperty Value
    Write-Host "matches: $matches"
    Write-Host "matches count: $($matches.Count)"
} else {
    Write-Host "selectString is null/falsy, foreach would not execute"
}

Write-Host ""
Write-Host "Testing with actual matches:"
# Simulate content WITH matching ResourceID pattern
$content2 = 'ResourceID = "something"'
$selectString2 = Select-String -InputObject $content2 -Pattern 'ResourceID = ".+' -AllMatches
Write-Host "selectString2 result: $selectString2"
Write-Host "selectString2 matches count: $($selectString2.Matches.Count)"
foreach ($value in $selectString2.Matches | Select-Object -ExpandProperty Value) {
    Write-Host "Found: $value"
}
EOF

Repository: dsccommunity/CommonTasks

Length of output: 1726


Add a check to ensure at least one ResourceID match exists before the foreach loop.

The foreach loop will not execute if Select-String returns $null (no matches found), causing the test to pass without validating any ResourceID lines. Add $selectString.Matches.Count | Should -BeGreaterThan 0 or equivalent after the Select-String call and before the loop.

Note: The -RegularExpression parameter is valid Pester v5 syntax and does not need to be removed.

🧰 Tools
🪛 PSScriptAnalyzer (1.24.0)

[warning] Missing BOM encoding for non-ASCII encoded file 'DscResources.Tests.ps1'

(PSUseBOMForUnicodeEncodedFile)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/Unit/DSCResources/DscResources.Tests.ps1` around lines 231 - 234, Add
an explicit assertion that Select-String found matches before iterating: after
the $selectString = Select-String -InputObject $mofContent -Pattern 'ResourceID
= ".+' call and before the foreach ($value in $selectString.Matches ...) loop,
assert that $selectString.Matches.Count | Should -BeGreaterThan 0 (or
equivalent) so the test fails when no ResourceID lines are present; reference
the $selectString variable, the Select-String invocation, and the foreach loop
when making the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant