-
Notifications
You must be signed in to change notification settings - Fork 27
Adds Test for correct ResourceIds #245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -222,6 +222,19 @@ configuration "Config_$dscResourceName" { | |
| $mofFile | Should -BeOfType System.IO.FileInfo | ||
| } | ||
|
|
||
| It "'<DscResourceName>' has ResourceIDs ending with [<DscResourceName>]<DscResourceName>" -TestCases $testCases { | ||
| if ($Skip) | ||
| { | ||
| Set-ItResult -Skipped -Because "Tests for '$DscResourceName' are skipped" | ||
| } | ||
| $mofContent = Get-Content -Raw -Path "$($OutputDirectory)\localhost_$dscResourceName.mof" | ||
| $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`";)" | ||
|
Comment on lines
+231
to
+234
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: Yes— 🏁 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"
}
EOFRepository: dsccommunity/CommonTasks Length of output: 1726 Add a check to ensure at least one ResourceID match exists before the foreach loop. The Note: The 🧰 Tools🪛 PSScriptAnalyzer (1.24.0)[warning] Missing BOM encoding for non-ASCII encoded file 'DscResources.Tests.ps1' (PSUseBOMForUnicodeEncodedFile) 🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
|
|
||
| AfterAll { | ||
| Remove-Item -Path C:\Temp\JeaRoleTest.ps1 | ||
| if (-not $tempExists) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the documented
ResourceIDsuffix example.[<ResourceName>]<Resourcenameis malformed and does not match the pattern the new test is asserting, so the changelog entry is misleading as written.Suggested wording
🤖 Prompt for AI Agents