Skip to content

Commit

Permalink
(chocolatey#66) Fixes Get-CCMComputer Matching Names
Browse files Browse the repository at this point in the history
Unless we intended to provide regex-matching functionality here (which isn't obvious from the help), this fixes the ability to return multiple computers with a single name (or even random regex query).
  • Loading branch information
JPRuskin committed May 6, 2023
1 parent 4a05bdb commit 98f3180
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Public/Get-CCMComputer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function Get-CCMComputer {
switch ($PSCmdlet.ParameterSetName) {
"Computer" {
foreach ($c in $computer) {
[pscustomobject]$records.result | Where-Object { $_.name -match "$c" }
[pscustomobject]$records.result | Where-Object { $_.name -eq $c }
}
}
"Id" {
Expand Down
8 changes: 3 additions & 5 deletions src/Tests/Public/Get-CCMComputer.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Describe "Get-CCMComputer" {
$Uri.AbsolutePath -eq "/api/services/app/Computers/GetAll"
} {
@{
result = 1..9 | ForEach-Object {
result = 1..20 | ForEach-Object {
[PSCustomObject]@{
name = "Computer $_"
}
Expand Down Expand Up @@ -41,7 +41,7 @@ Describe "Get-CCMComputer" {
}

It "Returns All Computers" {
$Result | Should -HaveCount 9
$Result | Should -HaveCount 20
}
}

Expand All @@ -68,9 +68,7 @@ Describe "Get-CCMComputer" {
Context "Getting computers by Name" {
BeforeAll {
$TestParams = @{
# This test fails when Computer 1 and Computer 10 are both selected, due to the naive match
Computer = 1..9 | Get-Random -Count (Get-Random -Minimum 1 -Maximum 9) | ForEach-Object { "Computer $($_)" }
# Computer = 1..10 | Get-Random -Count (Get-Random -Minimum 1 -Maximum 10) | ForEach-Object { "Computer $($_)" }
Computer = 1..10 | Get-Random -Count (Get-Random -Minimum 1 -Maximum 10) | ForEach-Object { "Computer $($_)" }
}
$Result = Get-CCMComputer @TestParams
}
Expand Down

0 comments on commit 98f3180

Please sign in to comment.