Fix multi-result behavior across all versions of PowerShell (fixes CI UT's on all platforms) #199
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Tests were failing on Mac and Linux, but not Windows (recent test run). That's because Windows CI was running against PoSh 5.x while Linux and Mac were running on PoSh 7.x.
There's a slight difference in behavior for how those two treat arrays.
The real root cause for this was the behavior of
Invoke-GHRestMethodMultipleResult
. When creating$finalResult
, it was always blindly adding the result to the existing array:PowerShellForGitHub/GitHubCore.ps1
Line 648 in 587e204
...
PowerShellForGitHub/GitHubCore.ps1
Line 670 in 587e204
Oddly enough, this created a difference in behavior between PowerShell versions when making the result an array on the caller side. Now I ensure that I don't add anything to
$finalResult
unless there's actually a value. With that change, we can now be sure that when we grab the result as an array, it'll be appropriately empty or populated (and not populated with a single$null
entry, thus makingCount
1, erroneously).I removed the attempt to force the results to be an array, because this is pointless. PowerShell will always unwrap an array of 0 or 1 in a return result. If you want to ensure that a result is always an array, you have to wrap the result in an object or you have to do wrap the result in an array on the caller side.
PowerShellForGitHub/GitHubCore.ps1
Lines 684 to 685 in 587e204
I also normalized some naming in all of the tests, so that when we're getting back a singular result (by querying for a specific item) that we use a singular variable name, and a plural variable name otherwise.
With this change, we should now be passing CI on all OS platforms and across PowerShell 4+.
Resolves #198