From 114e6f36efec6285c5222e8b031ae34461fe93e4 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Fri, 29 May 2020 08:41:37 -0700 Subject: [PATCH 1/5] Temporarily disable Linux in CI until unexpected UT failures are resolved Tests are failing remotely on Linux but not locally. Disabling for now until this can be investigated and resolved, so that we can still depend at least on the Windows CI build in the interim. Recent run with Linux UT failures: https://dev.azure.com/ms/PowerShellForGitHub/_build/results?buildId=83887&view=logs&j=0da5d1d9-276d-5173-c4c4-9d4d4ed14fdb --- build/pipelines/azure-pipelines.ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/pipelines/azure-pipelines.ci.yaml b/build/pipelines/azure-pipelines.ci.yaml index 9adc9f1a..1a9cdd2a 100644 --- a/build/pipelines/azure-pipelines.ci.yaml +++ b/build/pipelines/azure-pipelines.ci.yaml @@ -34,7 +34,7 @@ jobs: steps: - template: ./templates/verify-testConfigSettingsHash.yaml - template: ./templates/run-staticAnalysis.yaml - - template: ./templates/run-unitTests.yaml +# - template: ./templates/run-unitTests.yaml - job: macOS pool: From 55fabefc41943190795ab81034d0132ed9d9bc22 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Fri, 29 May 2020 16:06:04 -0700 Subject: [PATCH 2/5] Fixes --- GitHubAnalytics.ps1 | 8 ++-- GitHubCore.ps1 | 3 +- Tests/GitHubAnalytics.tests.ps1 | 58 +++++++++++++++++-------- Tests/GitHubAssignees.tests.ps1 | 10 +++-- Tests/GitHubComments.tests.ps1 | 12 +++-- Tests/GitHubEvents.tests.ps1 | 14 +++--- Tests/GitHubLabels.tests.ps1 | 6 +-- Tests/GitHubMilestones.tests.ps1 | 8 ++-- Tests/GitHubReleases.tests.ps1 | 22 +++++++--- Tests/GitHubRepositoryForks.tests.ps1 | 4 +- Tests/GitHubRepositoryTraffic.tests.ps1 | 4 +- 11 files changed, 96 insertions(+), 53 deletions(-) diff --git a/GitHubAnalytics.ps1 b/GitHubAnalytics.ps1 index e4bba220..d8958fd0 100644 --- a/GitHubAnalytics.ps1 +++ b/GitHubAnalytics.ps1 @@ -89,10 +89,10 @@ function Group-GitHubIssue $endOfWeek = Get-Date foreach ($week in $weekDates) { - $filteredIssues = @($Issue | Where-Object { + $filteredIssues = $Issue | Where-Object { (($DateType -eq 'Created') -and ($_.created_at -ge $week) -and ($_.created_at -le $endOfWeek)) -or (($DateType -eq 'Closed') -and ($_.closed_at -ge $week) -and ($_.closed_at -le $endOfWeek)) - }) + } $endOfWeek = $week @@ -210,10 +210,10 @@ function Group-GitHubPullRequest $endOfWeek = Get-Date foreach ($week in $weekDates) { - $filteredPullRequests = @($PullRequest | Where-Object { + $filteredPullRequests = $PullRequest | Where-Object { (($DateType -eq 'Created') -and ($_.created_at -ge $week) -and ($_.created_at -le $endOfWeek)) -or (($DateType -eq 'Merged') -and ($_.merged_at -ge $week) -and ($_.merged_at -le $endOfWeek)) - }) + } $endOfWeek = $week diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index 2bf3f185..d8b8871c 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -681,8 +681,7 @@ function Invoke-GHRestMethodMultipleResult Set-TelemetryEvent -EventName $TelemetryEventName -Properties $TelemetryProperties -Metrics $telemetryMetrics } - # Ensure we're always returning our results as an array, even if there is a single result. - return @($finalResult) + return $finalResult } catch { diff --git a/Tests/GitHubAnalytics.tests.ps1 b/Tests/GitHubAnalytics.tests.ps1 index 0fb70198..a9c514b9 100644 --- a/Tests/GitHubAnalytics.tests.ps1 +++ b/Tests/GitHubAnalytics.tests.ps1 @@ -19,7 +19,7 @@ try $issues = Get-GitHubIssue -Uri $repo.svn_url It 'Should return expected number of issues' { - @($issues).Count | Should be 0 + $issues.Count | Should be 0 } } @@ -36,12 +36,12 @@ try $issues = Get-GitHubIssue -Uri $repo.svn_url It 'Should return only open issues' { - @($issues).Count | Should be 2 + $issues.Count | Should be 2 } $issues = Get-GitHubIssue -Uri $repo.svn_url -State All It 'Should return all issues' { - @($issues).Count | Should be 4 + $issues.Count | Should be 4 } $createdOnOrAfterDate = Get-Date -Date $newIssues[0].created_at @@ -49,21 +49,25 @@ try $issues = (Get-GitHubIssue -Uri $repo.svn_url) | Where-Object { ($_.created_at -ge $createdOnOrAfterDate) -and ($_.created_at -le $createdOnOrBeforeDate) } It 'Smart object date conversion works for comparing dates' { - @($issues).Count | Should be 2 + $issues.Count | Should be 2 } $createdDate = Get-Date -Date $newIssues[1].created_at $issues = Get-GitHubIssue -Uri $repo.svn_url -State All | Where-Object { ($_.created_at -ge $createdDate) -and ($_.state -eq 'closed') } + # Account for differences in array handling between PowerShell 7 vs earlier versions. + # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. + $issues = ,$issues + It 'Able to filter based on date and state' { - @($issues).Count | Should be 1 + $issues.Count | Should be 1 } } Context 'When issues are retrieved with a specific MediaTypes' { $newIssue = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([guid]::NewGuid()) -Body ([guid]::NewGuid()) - $issues = @(Get-GitHubIssue -Uri $repo.svn_url -Issue $newIssue.number -MediaType 'Html') + $issues = Get-GitHubIssue -Uri $repo.svn_url -Issue $newIssue.number -MediaType 'Html' It 'Should return an issue with body_html' { $issues[0].body_html | Should not be $null } @@ -88,18 +92,18 @@ try $issueCounts = $issueCounts | Sort-Object -Property Count -Descending It 'Should return expected number of issues for each repository' { - @($issueCounts[0].Count) | Should be 3 - @($issueCounts[1].Count) | Should be 0 + $issueCounts[0].Count | Should be 3 + $issueCounts[1].Count | Should be 0 } It 'Should return expected repository names' { - @($issueCounts[0].Uri) | Should be ($repo1.svn_url) - @($issueCounts[1].Uri) | Should be ($repo2.svn_url) + $issueCounts[0].Uri | Should be $repo1.svn_url + $issueCounts[1].Uri | Should be $repo2.svn_url } } - $null = Remove-GitHubRepository -Uri ($repo1.svn_url) - $null = Remove-GitHubRepository -Uri ($repo2.svn_url) + $null = Remove-GitHubRepository -Uri $repo1.svn_url + $null = Remove-GitHubRepository -Uri $repo2.svn_url } @@ -186,10 +190,14 @@ try $null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit $repositoryUrl = "https://github.com/$script:ownerName/$repositoryName" - $collaborators = Get-GitHubRepositoryCollaborator -Uri $repositoryUrl + $collaborators = @(Get-GitHubRepositoryCollaborator -Uri $repositoryUrl) + + # Account for differences in array handling between PowerShell 7 vs earlier versions. + # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. + #$collaborators = ,$collaborators It 'Should return expected number of collaborators' { - @($collaborators).Count | Should be 1 + $collaborators.Count | Should be 1 } $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName @@ -203,8 +211,12 @@ try $contributors = Get-GitHubRepositoryContributor -Uri $repositoryUrl -IncludeStatistics + # Account for differences in array handling between PowerShell 7 vs earlier versions. + # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. + $contributors = ,$contributors + It 'Should return expected number of contributors' { - @($contributors).Count | Should be 1 + $contributors.Count | Should be 1 } $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName @@ -249,8 +261,12 @@ try $repo = New-GitHubRepository -RepositoryName ([guid]::NewGuid().Guid) -OrganizationName $script:organizationName $current = Get-GitHubRepository -OrganizationName $script:organizationName + # Account for differences in array handling between PowerShell 7 vs earlier versions. + # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. + $current = ,$current + It 'Should return expected number of organization repositories' { - (@($current).Count - @($original).Count) | Should be 1 + ($current.Count - $original.Count) | Should be 1 } $null = Remove-GitHubRepository -Uri $repo.svn_url @@ -268,7 +284,7 @@ try Sort-Object It 'Should return expected number of unique contributors' { - @($uniqueContributors).Count | Should be 1 + $uniqueContributors.Count | Should be 1 } $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName @@ -300,12 +316,16 @@ try $branches = Get-GitHubRepositoryBranch -OwnerName $script:ownerName -RepositoryName $repositoryName + # Account for differences in array handling between PowerShell 7 vs earlier versions. + # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. + $branches = ,$branches + It 'Should return expected number of repository branches' { - @($branches).Count | Should be 1 + $branches.Count | Should be 1 } It 'Should return the name of the branches' { - @($branches[0].name) | Should be "master" + $branches[0].name | Should be 'master' } $null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName diff --git a/Tests/GitHubAssignees.tests.ps1 b/Tests/GitHubAssignees.tests.ps1 index 9ea07346..f290ba10 100644 --- a/Tests/GitHubAssignees.tests.ps1 +++ b/Tests/GitHubAssignees.tests.ps1 @@ -18,7 +18,11 @@ try Describe 'Getting a valid assignee' { Context 'For getting a valid assignee' { - $assigneeList = @(Get-GitHubAssignee -Uri $repo.svn_url) + $assigneeList = Get-GitHubAssignee -Uri $repo.svn_url + + # Account for differences in array handling between PowerShell 7 vs earlier versions. + # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. + $assigneeList = ,$assigneeList It 'Should have returned the one assignee' { $assigneeList.Count | Should be 1 @@ -42,9 +46,9 @@ try Describe 'Adding and removing an assignee to an issue'{ Context 'For adding an assignee to an issue'{ - $assigneeList = @(Get-GitHubAssignee -Uri $repo.svn_url) + $assigneeList = Get-GitHubAssignee -Uri $repo.svn_url $assigneeUserName = $assigneeList[0].login - $assignees = @($assigneeUserName) + $assignees = $assigneeUserName New-GithubAssignee -Uri $repo.svn_url -Issue $issue.number -Assignee $assignees $issue = Get-GitHubIssue -Uri $repo.svn_url -Issue $issue.number diff --git a/Tests/GitHubComments.tests.ps1 b/Tests/GitHubComments.tests.ps1 index 9bdd5a62..cc2b754a 100644 --- a/Tests/GitHubComments.tests.ps1 +++ b/Tests/GitHubComments.tests.ps1 @@ -36,7 +36,11 @@ try } Context 'For getting comments from an issue' { - $existingComments = @(Get-GitHubComment -Uri $repo.svn_url -Issue $issue.number) + $existingComments = Get-GitHubComment -Uri $repo.svn_url -Issue $issue.number + + # Account for differences in array handling between PowerShell 7 vs earlier versions. + # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. + $existingComments = ,$existingComments It 'Should have the expected number of comments' { $existingComments.Count | Should be 1 @@ -48,7 +52,7 @@ try } Context 'For getting comments from an issue with a specific MediaType' { - $existingComments = @(Get-GitHubComment -Uri $repo.svn_url -Issue $issue.number -MediaType 'Html') + $existingComments = Get-GitHubComment -Uri $repo.svn_url -Issue $issue.number -MediaType 'Html' It 'Should have the expected body_html on the first comment' { $existingComments[0].body_html | Should not be $null @@ -69,7 +73,7 @@ try } Context 'For getting comments from a repository and deleting them' { - $existingComments = @(Get-GitHubComment -Uri $repo.svn_url) + $existingComments = Get-GitHubComment -Uri $repo.svn_url It 'Should have the expected number of comments' { $existingComments.Count | Should be 2 @@ -79,7 +83,7 @@ try Remove-GitHubComment -Uri $repo.svn_url -CommentID $comment.id } - $existingComments = @(Get-GitHubComment -Uri $repo.svn_url) + $existingComments = Get-GitHubComment -Uri $repo.svn_url It 'Should have no comments' { $existingComments.Count | Should be 0 diff --git a/Tests/GitHubEvents.tests.ps1 b/Tests/GitHubEvents.tests.ps1 index 4364dcf0..5b809f18 100644 --- a/Tests/GitHubEvents.tests.ps1 +++ b/Tests/GitHubEvents.tests.ps1 @@ -19,7 +19,7 @@ try $null = New-GitHubRepository -RepositoryName $repositoryName Context 'For getting events from a new repository' { - $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) + $events = Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName It 'Should have no events' { $events.Count | Should be 0 @@ -30,7 +30,11 @@ try Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Closed Context 'For getting events from a repository' { - $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) + $events = Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName + + # Account for differences in array handling between PowerShell 7 vs earlier versions + # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. + $events = ,$events It 'Should have an event from closing an issue' { $events.Count | Should be 1 @@ -46,7 +50,7 @@ try $issue = New-GithubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" Context 'For getting events from a new issue' { - $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number) + $events = Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number It 'Should have no events' { $events.Count | Should be 0 @@ -56,7 +60,7 @@ try Context 'For getting events from an issue' { Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Closed Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Open - $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) + $events = Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName It 'Should have two events from closing and opening the issue' { $events.Count | Should be 2 @@ -72,7 +76,7 @@ try $issue = New-GithubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Closed Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Open - $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) + $events = Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName Context 'For getting an event directly'{ $singleEvent = Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName -EventID $events[0].id diff --git a/Tests/GitHubLabels.tests.ps1 b/Tests/GitHubLabels.tests.ps1 index 9d1158b3..1f1322a6 100644 --- a/Tests/GitHubLabels.tests.ps1 +++ b/Tests/GitHubLabels.tests.ps1 @@ -222,7 +222,7 @@ try Context 'Adding labels to an issue' { $labelsToAdd = @('pri:lowest', 'pri:low', 'pri:medium', 'pri:high', 'pri:highest', 'bug', 'duplicate', 'enhancement', 'up for grabs', 'question', 'discussion', 'wontfix', 'in progress', 'ready') - $addedLabels = @(Add-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd) + $addedLabels = Add-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd It 'Should return the number of labels that were just added' { $addedLabels.Count | Should be $defaultLabels.Count @@ -300,7 +300,7 @@ try Add-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName 'pri:medium' - $addedLabels = @(Set-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd) + $addedLabels = Set-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd It 'Should return the issue with 14 labels' { $addedLabels.Count | Should be $labelsToAdd.Count @@ -312,7 +312,7 @@ try $labelIssues.Count | Should be $defaultLabels.Count } - $updatedIssueLabels = @($labelsToAdd[0]) + $updatedIssueLabels = $labelsToAdd[0] $updatedIssue = Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -Label $updatedIssueLabels It 'Should have 1 label after updating the issue' { diff --git a/Tests/GitHubMilestones.tests.ps1 b/Tests/GitHubMilestones.tests.ps1 index 9e943908..b6792ec5 100644 --- a/Tests/GitHubMilestones.tests.ps1 +++ b/Tests/GitHubMilestones.tests.ps1 @@ -71,7 +71,7 @@ try } Context 'For getting milestones from a repo' { - $existingMilestones = @(Get-GitHubMilestone -Uri $repo.svn_url -State Closed) + $existingMilestones = Get-GitHubMilestone -Uri $repo.svn_url -State Closed $issue = Get-GitHubIssue -Uri $repo.svn_url -Issue $issue.number It 'Should have the expected number of milestones' { @@ -104,17 +104,17 @@ try } Context 'For getting milestones from a repository and deleting them' { - $existingMilestones = @(Get-GitHubMilestone -Uri $repo.svn_url -State All -Sort Completeness -Direction Descending) + $existingMilestones = Get-GitHubMilestone -Uri $repo.svn_url -State All -Sort Completeness -Direction Descending It 'Should have the expected number of milestones' { $existingMilestones.Count | Should be 4 } - foreach($milestone in $existingMilestones) { + foreach ($milestone in $existingMilestones) { Remove-GitHubMilestone -Uri $repo.svn_url -Milestone $milestone.number } - $existingMilestones = @(Get-GitHubMilestone -Uri $repo.svn_url) + $existingMilestones = Get-GitHubMilestone -Uri $repo.svn_url -State All $issue = Get-GitHubIssue -Uri $repo.svn_url -Issue $issue.number It 'Should have no milestones' { diff --git a/Tests/GitHubReleases.tests.ps1 b/Tests/GitHubReleases.tests.ps1 index 9a4fbd5e..c414a38f 100644 --- a/Tests/GitHubReleases.tests.ps1 +++ b/Tests/GitHubReleases.tests.ps1 @@ -28,13 +28,17 @@ try Context 'When getting the latest releases' { $latest = Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -Latest + # Account for differences in array handling between PowerShell 7 vs earlier versions + # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. + $latest = ,$latest + It 'Should return one value' { - @($latest).Count | Should Be 1 + $latest.Count | Should Be 1 } It 'Should return the first release from the full releases list' { - $releases[0].url | Should Be $releases[0].url - $releases[0].name | Should Be $releases[0].name + $latest[0].url | Should Be $releases[0].url + $latest[0].name | Should Be $releases[0].name } } @@ -42,8 +46,12 @@ try $specificIndex = 5 $specific = Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -ReleaseId $releases[$specificIndex].id + # Account for differences in array handling between PowerShell 7 vs earlier versions + # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. + $specific = ,$specific + It 'Should return one value' { - @($specific).Count | Should Be 1 + $specific.Count | Should Be 1 } It 'Should return the correct release' { @@ -55,8 +63,12 @@ try $taggedIndex = 8 $tagged = Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -Tag $releases[$taggedIndex].tag_name + # Account for differences in array handling between PowerShell 7 vs earlier versions + # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. + $tagged = ,$tagged + It 'Should return one value' { - @($tagged).Count | Should Be 1 + $tagged.Count | Should Be 1 } It 'Should return the correct release' { diff --git a/Tests/GitHubRepositoryForks.tests.ps1 b/Tests/GitHubRepositoryForks.tests.ps1 index 7c80ab7a..ee8c13fd 100644 --- a/Tests/GitHubRepositoryForks.tests.ps1 +++ b/Tests/GitHubRepositoryForks.tests.ps1 @@ -20,7 +20,7 @@ try $newForks = Get-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Sort Newest It 'Should have one more fork than before' { - (@($newForks).Count - @($originalForks).Count) | Should be 1 + ($newForks.Count - $originalForks.Count) | Should be 1 } It 'Should be the latest fork in the list' { @@ -41,7 +41,7 @@ try $newForks = Get-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Sort Newest It 'Should have one more fork than before' { - (@($newForks).Count - @($originalForks).Count) | Should be 1 + ($newForks.Count - $originalForks.Count) | Should be 1 } It 'Should be the latest fork in the list' { diff --git a/Tests/GitHubRepositoryTraffic.tests.ps1 b/Tests/GitHubRepositoryTraffic.tests.ps1 index 19d76d8e..53adb0d5 100644 --- a/Tests/GitHubRepositoryTraffic.tests.ps1 +++ b/Tests/GitHubRepositoryTraffic.tests.ps1 @@ -19,7 +19,7 @@ try $referrerList = Get-GitHubReferrerTraffic -Uri $repo.svn_url It 'Should return expected number of referrers' { - @($referrerList).Count | Should be 0 + $referrerList.Count | Should be 0 } Remove-GitHubRepository -Uri $repo.svn_url @@ -33,7 +33,7 @@ try $pathList = Get-GitHubPathTraffic -Uri $repo.svn_url It 'Should return expected number of popular content' { - @($pathList).Count | Should be 0 + $pathList.Count | Should be 0 } Remove-GitHubRepository -Uri $repo.svn_url From 453ff192d90a690bcd5e2091247498244f39fc16 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sat, 30 May 2020 14:01:49 -0700 Subject: [PATCH 3/5] Everything passing --- GitHubCore.ps1 | 6 +- Tests/GitHubAnalytics.tests.ps1 | 44 ++++--------- Tests/GitHubAssignees.tests.ps1 | 8 +-- Tests/GitHubComments.tests.ps1 | 12 ++-- Tests/GitHubEvents.tests.ps1 | 14 ++-- Tests/GitHubLabels.tests.ps1 | 26 ++++---- Tests/GitHubMilestones.tests.ps1 | 6 +- Tests/GitHubProjectCards.tests.ps1 | 48 +++++++------- Tests/GitHubProjectColumns.tests.ps1 | 32 +++++---- Tests/GitHubProjects.tests.ps1 | 94 ++++++++++++++++----------- Tests/GitHubReleases.tests.ps1 | 22 ++----- Tests/GitHubRepositories.tests.ps1 | 16 ++--- Tests/GitHubRepositoryForks.tests.ps1 | 10 ++- 13 files changed, 159 insertions(+), 179 deletions(-) diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index d8b8871c..59acd6f4 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -667,7 +667,11 @@ function Invoke-GHRestMethodMultipleResult } $result = Invoke-GHRestMethod @params - $finalResult += $result.result + if ($null -ne $result.result) + { + $finalResult += $result.result + } + $nextLink = $result.nextLink $currentDescription = "$Description (getting additional results)" } diff --git a/Tests/GitHubAnalytics.tests.ps1 b/Tests/GitHubAnalytics.tests.ps1 index a9c514b9..8c5c51c2 100644 --- a/Tests/GitHubAnalytics.tests.ps1 +++ b/Tests/GitHubAnalytics.tests.ps1 @@ -16,7 +16,7 @@ try $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit Context 'When initially created, there are no issues' { - $issues = Get-GitHubIssue -Uri $repo.svn_url + $issues = @(Get-GitHubIssue -Uri $repo.svn_url) It 'Should return expected number of issues' { $issues.Count | Should be 0 @@ -34,30 +34,26 @@ try $newIssues[0] = Update-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[0].number -State Closed $newIssues[-1] = Update-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[-1].number -State Closed - $issues = Get-GitHubIssue -Uri $repo.svn_url + $issues = @(Get-GitHubIssue -Uri $repo.svn_url) It 'Should return only open issues' { $issues.Count | Should be 2 } - $issues = Get-GitHubIssue -Uri $repo.svn_url -State All + $issues = @(Get-GitHubIssue -Uri $repo.svn_url -State All) It 'Should return all issues' { $issues.Count | Should be 4 } $createdOnOrAfterDate = Get-Date -Date $newIssues[0].created_at $createdOnOrBeforeDate = Get-Date -Date $newIssues[2].created_at - $issues = (Get-GitHubIssue -Uri $repo.svn_url) | Where-Object { ($_.created_at -ge $createdOnOrAfterDate) -and ($_.created_at -le $createdOnOrBeforeDate) } + $issues = @((Get-GitHubIssue -Uri $repo.svn_url) | Where-Object { ($_.created_at -ge $createdOnOrAfterDate) -and ($_.created_at -le $createdOnOrBeforeDate) }) It 'Smart object date conversion works for comparing dates' { $issues.Count | Should be 2 } $createdDate = Get-Date -Date $newIssues[1].created_at - $issues = Get-GitHubIssue -Uri $repo.svn_url -State All | Where-Object { ($_.created_at -ge $createdDate) -and ($_.state -eq 'closed') } - - # Account for differences in array handling between PowerShell 7 vs earlier versions. - # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. - $issues = ,$issues + $issues = @(Get-GitHubIssue -Uri $repo.svn_url -State All | Where-Object { ($_.created_at -ge $createdDate) -and ($_.state -eq 'closed') }) It 'Able to filter based on date and state' { $issues.Count | Should be 1 @@ -67,7 +63,7 @@ try Context 'When issues are retrieved with a specific MediaTypes' { $newIssue = New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([guid]::NewGuid()) -Body ([guid]::NewGuid()) - $issues = Get-GitHubIssue -Uri $repo.svn_url -Issue $newIssue.number -MediaType 'Html' + $issues = @(Get-GitHubIssue -Uri $repo.svn_url -Issue $newIssue.number -MediaType 'Html') It 'Should return an issue with body_html' { $issues[0].body_html | Should not be $null } @@ -192,10 +188,6 @@ try $collaborators = @(Get-GitHubRepositoryCollaborator -Uri $repositoryUrl) - # Account for differences in array handling between PowerShell 7 vs earlier versions. - # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. - #$collaborators = ,$collaborators - It 'Should return expected number of collaborators' { $collaborators.Count | Should be 1 } @@ -209,11 +201,7 @@ try $null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit $repositoryUrl = "https://github.com/$script:ownerName/$repositoryName" - $contributors = Get-GitHubRepositoryContributor -Uri $repositoryUrl -IncludeStatistics - - # Account for differences in array handling between PowerShell 7 vs earlier versions. - # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. - $contributors = ,$contributors + $contributors = @(Get-GitHubRepositoryContributor -Uri $repositoryUrl -IncludeStatistics) It 'Should return expected number of contributors' { $contributors.Count | Should be 1 @@ -254,16 +242,10 @@ try } Describe 'Getting repositories from organization' { - <# Temporary hack due to issues with this test in ADO #> . (Join-Path -Path $moduleRootPath -ChildPath 'Tests\Config\Settings.ps1') - - $original = Get-GitHubRepository -OrganizationName $script:organizationName + $original = @(Get-GitHubRepository -OrganizationName $script:organizationName) $repo = New-GitHubRepository -RepositoryName ([guid]::NewGuid().Guid) -OrganizationName $script:organizationName - $current = Get-GitHubRepository -OrganizationName $script:organizationName - - # Account for differences in array handling between PowerShell 7 vs earlier versions. - # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. - $current = ,$current + $current = @(Get-GitHubRepository -OrganizationName $script:organizationName) It 'Should return expected number of organization repositories' { ($current.Count - $original.Count) | Should be 1 @@ -276,7 +258,7 @@ try $repositoryName = [guid]::NewGuid().Guid $null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit - $contributors = Get-GitHubRepositoryContributor -OwnerName $script:ownerName -RepositoryName $repositoryName -IncludeStatistics + $contributors = @(Get-GitHubRepositoryContributor -OwnerName $script:ownerName -RepositoryName $repositoryName -IncludeStatistics) $uniqueContributors = $contributors | Select-Object -ExpandProperty author | @@ -314,11 +296,7 @@ try $repositoryName = [guid]::NewGuid().Guid $null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit - $branches = Get-GitHubRepositoryBranch -OwnerName $script:ownerName -RepositoryName $repositoryName - - # Account for differences in array handling between PowerShell 7 vs earlier versions. - # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. - $branches = ,$branches + $branches = @(Get-GitHubRepositoryBranch -OwnerName $script:ownerName -RepositoryName $repositoryName) It 'Should return expected number of repository branches' { $branches.Count | Should be 1 diff --git a/Tests/GitHubAssignees.tests.ps1 b/Tests/GitHubAssignees.tests.ps1 index f290ba10..fc1a89de 100644 --- a/Tests/GitHubAssignees.tests.ps1 +++ b/Tests/GitHubAssignees.tests.ps1 @@ -18,11 +18,7 @@ try Describe 'Getting a valid assignee' { Context 'For getting a valid assignee' { - $assigneeList = Get-GitHubAssignee -Uri $repo.svn_url - - # Account for differences in array handling between PowerShell 7 vs earlier versions. - # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. - $assigneeList = ,$assigneeList + $assigneeList = @(Get-GitHubAssignee -Uri $repo.svn_url) It 'Should have returned the one assignee' { $assigneeList.Count | Should be 1 @@ -46,7 +42,7 @@ try Describe 'Adding and removing an assignee to an issue'{ Context 'For adding an assignee to an issue'{ - $assigneeList = Get-GitHubAssignee -Uri $repo.svn_url + $assigneeList = @(Get-GitHubAssignee -Uri $repo.svn_url) $assigneeUserName = $assigneeList[0].login $assignees = $assigneeUserName New-GithubAssignee -Uri $repo.svn_url -Issue $issue.number -Assignee $assignees diff --git a/Tests/GitHubComments.tests.ps1 b/Tests/GitHubComments.tests.ps1 index cc2b754a..9bdd5a62 100644 --- a/Tests/GitHubComments.tests.ps1 +++ b/Tests/GitHubComments.tests.ps1 @@ -36,11 +36,7 @@ try } Context 'For getting comments from an issue' { - $existingComments = Get-GitHubComment -Uri $repo.svn_url -Issue $issue.number - - # Account for differences in array handling between PowerShell 7 vs earlier versions. - # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. - $existingComments = ,$existingComments + $existingComments = @(Get-GitHubComment -Uri $repo.svn_url -Issue $issue.number) It 'Should have the expected number of comments' { $existingComments.Count | Should be 1 @@ -52,7 +48,7 @@ try } Context 'For getting comments from an issue with a specific MediaType' { - $existingComments = Get-GitHubComment -Uri $repo.svn_url -Issue $issue.number -MediaType 'Html' + $existingComments = @(Get-GitHubComment -Uri $repo.svn_url -Issue $issue.number -MediaType 'Html') It 'Should have the expected body_html on the first comment' { $existingComments[0].body_html | Should not be $null @@ -73,7 +69,7 @@ try } Context 'For getting comments from a repository and deleting them' { - $existingComments = Get-GitHubComment -Uri $repo.svn_url + $existingComments = @(Get-GitHubComment -Uri $repo.svn_url) It 'Should have the expected number of comments' { $existingComments.Count | Should be 2 @@ -83,7 +79,7 @@ try Remove-GitHubComment -Uri $repo.svn_url -CommentID $comment.id } - $existingComments = Get-GitHubComment -Uri $repo.svn_url + $existingComments = @(Get-GitHubComment -Uri $repo.svn_url) It 'Should have no comments' { $existingComments.Count | Should be 0 diff --git a/Tests/GitHubEvents.tests.ps1 b/Tests/GitHubEvents.tests.ps1 index 5b809f18..4364dcf0 100644 --- a/Tests/GitHubEvents.tests.ps1 +++ b/Tests/GitHubEvents.tests.ps1 @@ -19,7 +19,7 @@ try $null = New-GitHubRepository -RepositoryName $repositoryName Context 'For getting events from a new repository' { - $events = Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName + $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) It 'Should have no events' { $events.Count | Should be 0 @@ -30,11 +30,7 @@ try Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Closed Context 'For getting events from a repository' { - $events = Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName - - # Account for differences in array handling between PowerShell 7 vs earlier versions - # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. - $events = ,$events + $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) It 'Should have an event from closing an issue' { $events.Count | Should be 1 @@ -50,7 +46,7 @@ try $issue = New-GithubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" Context 'For getting events from a new issue' { - $events = Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number + $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number) It 'Should have no events' { $events.Count | Should be 0 @@ -60,7 +56,7 @@ try Context 'For getting events from an issue' { Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Closed Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Open - $events = Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName + $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) It 'Should have two events from closing and opening the issue' { $events.Count | Should be 2 @@ -76,7 +72,7 @@ try $issue = New-GithubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title "New Issue" Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Closed Update-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -State Open - $events = Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName + $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) Context 'For getting an event directly'{ $singleEvent = Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName -EventID $events[0].id diff --git a/Tests/GitHubLabels.tests.ps1 b/Tests/GitHubLabels.tests.ps1 index 1f1322a6..e040579b 100644 --- a/Tests/GitHubLabels.tests.ps1 +++ b/Tests/GitHubLabels.tests.ps1 @@ -79,10 +79,10 @@ try Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels Context 'When querying for all labels' { - $labels = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName + $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) It 'Should return expected number of labels' { - $($labels).Count | Should be $:defaultLabels.Count + $labels.Count | Should be $:defaultLabels.Count } } @@ -123,17 +123,17 @@ try $labelName = [Guid]::NewGuid().Guid New-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Color BBBBBB - $labels = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName + $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) It 'Should return increased number of labels' { - $($labels).Count | Should be ($defaultLabels.Count + 1) + $labels.Count | Should be ($defaultLabels.Count + 1) } Remove-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName - $labels = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName + $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) It 'Should return expected number of labels' { - $($labels).Count | Should be $defaultLabels.Count + $labels.Count | Should be $defaultLabels.Count } $null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName @@ -187,7 +187,7 @@ try # Add new label New-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name $labelName -Color BBBBBB - $labels = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName + $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) # Change color of existing label Update-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "bug" -NewName "bug" -Color BBBBBB @@ -200,10 +200,10 @@ try } Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels - $labels = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName + $labels = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName) It 'Should return expected number of labels' { - $($labels).Count | Should be $defaultLabels.Count + $labels.Count | Should be $defaultLabels.Count $bugLabel = $labels | Where-Object {$_.name -eq "bug"} $bugLabel.color | Should be "fc2929" } @@ -222,7 +222,7 @@ try Context 'Adding labels to an issue' { $labelsToAdd = @('pri:lowest', 'pri:low', 'pri:medium', 'pri:high', 'pri:highest', 'bug', 'duplicate', 'enhancement', 'up for grabs', 'question', 'discussion', 'wontfix', 'in progress', 'ready') - $addedLabels = Add-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd + $addedLabels = @(Add-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd) It 'Should return the number of labels that were just added' { $addedLabels.Count | Should be $defaultLabels.Count @@ -269,7 +269,7 @@ try Remove-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "discussion" -Issue $issue.number Remove-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "question" -Issue $issue.number Remove-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Name "bug" -Issue $issue.number - $labelIssues = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number + $labelIssues = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number) It 'Should have removed three labels from the issue' { $labelIssues.Count | Should be ($defaultLabels.Count - 3) @@ -278,7 +278,7 @@ try Context 'For removing all issues'{ Remove-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number - $labelIssues = Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number + $labelIssues = @(Get-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number) It 'Should have removed all labels from the issue' { $labelIssues.Count | Should be 0 @@ -300,7 +300,7 @@ try Add-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName 'pri:medium' - $addedLabels = Set-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd + $addedLabels = @(Set-GitHubIssueLabel -OwnerName $ownerName -RepositoryName $repositoryName -Issue $issue.number -LabelName $labelsToAdd) It 'Should return the issue with 14 labels' { $addedLabels.Count | Should be $labelsToAdd.Count diff --git a/Tests/GitHubMilestones.tests.ps1 b/Tests/GitHubMilestones.tests.ps1 index b6792ec5..5255afd4 100644 --- a/Tests/GitHubMilestones.tests.ps1 +++ b/Tests/GitHubMilestones.tests.ps1 @@ -71,7 +71,7 @@ try } Context 'For getting milestones from a repo' { - $existingMilestones = Get-GitHubMilestone -Uri $repo.svn_url -State Closed + $existingMilestones =@(Get-GitHubMilestone -Uri $repo.svn_url -State Closed) $issue = Get-GitHubIssue -Uri $repo.svn_url -Issue $issue.number It 'Should have the expected number of milestones' { @@ -104,7 +104,7 @@ try } Context 'For getting milestones from a repository and deleting them' { - $existingMilestones = Get-GitHubMilestone -Uri $repo.svn_url -State All -Sort Completeness -Direction Descending + $existingMilestones = @(Get-GitHubMilestone -Uri $repo.svn_url -State All -Sort Completeness -Direction Descending) It 'Should have the expected number of milestones' { $existingMilestones.Count | Should be 4 @@ -114,7 +114,7 @@ try Remove-GitHubMilestone -Uri $repo.svn_url -Milestone $milestone.number } - $existingMilestones = Get-GitHubMilestone -Uri $repo.svn_url -State All + $existingMilestones = @(Get-GitHubMilestone -Uri $repo.svn_url -State All) $issue = Get-GitHubIssue -Uri $repo.svn_url -Issue $issue.number It 'Should have no milestones' { diff --git a/Tests/GitHubProjectCards.tests.ps1 b/Tests/GitHubProjectCards.tests.ps1 index e7a571d9..9ffbf7e2 100644 --- a/Tests/GitHubProjectCards.tests.ps1 +++ b/Tests/GitHubProjectCards.tests.ps1 @@ -52,7 +52,7 @@ try } Context 'Get cards for a column' { - $results = Get-GitHubProjectCard -Column $column.id + $results = @(Get-GitHubProjectCard -Column $column.id) It 'Should get cards' { $results | Should Not BeNullOrEmpty } @@ -63,24 +63,24 @@ try } Context 'Get all cards for a column' { - $results = Get-GitHubProjectCard -Column $column.id -ArchivedState All + $results = @(Get-GitHubProjectCard -Column $column.id -ArchivedState All) It 'Should get all cards' { $results.Count | Should Be 2 } } Context 'Get archived cards for a column' { - $results = Get-GitHubProjectCard -Column $column.id -ArchivedState Archived + $result = Get-GitHubProjectCard -Column $column.id -ArchivedState Archived It 'Should get archived card' { - $results | Should Not BeNullOrEmpty + $result | Should Not BeNullOrEmpty } It 'Note is correct' { - $results.note | Should be $defaultArchivedCard + $result.note | Should be $defaultArchivedCard } It 'Should be archived' { - $results.Archived | Should be $true + $result.Archived | Should be $true } } } @@ -103,46 +103,46 @@ try Context 'Modify card note' { $null = Set-GitHubProjectCard -Card $card.id -Note $defaultCardUpdated - $results = Get-GitHubProjectCard -Card $card.id + $result = Get-GitHubProjectCard -Card $card.id It 'Should get card' { - $results | Should Not BeNullOrEmpty + $result | Should Not BeNullOrEmpty } It 'Note has been updated' { - $results.note | Should be $defaultCardUpdated + $result.note | Should be $defaultCardUpdated } } Context 'Archive a card' { $null = Set-GitHubProjectCard -Card $cardArchived.id -Archive - $results = Get-GitHubProjectCard -Card $cardArchived.id + $result = Get-GitHubProjectCard -Card $cardArchived.id It 'Should get card' { - $results | Should Not BeNullOrEmpty + $result | Should Not BeNullOrEmpty } It 'Card is archived' { - $results.Archived | Should be $true + $result.Archived | Should be $true } } Context 'Restore a card' { $null = Set-GitHubProjectCard -Card $cardArchived.id -Restore - $results = Get-GitHubProjectCard -Card $cardArchived.id + $result = Get-GitHubProjectCard -Card $cardArchived.id It 'Should get card' { - $results | Should Not BeNullOrEmpty + $result | Should Not BeNullOrEmpty } It 'Card is not archived' { - $results.Archived | Should be $false + $result.Archived | Should be $false } } Context 'Move card position within column' { $null = Move-GitHubProjectCard -Card $cardTwo.id -Top - $results = Get-GitHubProjectCard -Column $column.id + $results = @(Get-GitHubProjectCard -Column $column.id) It 'Card is now top' { $results[0].note | Should be $defaultCardTwo @@ -151,7 +151,7 @@ try Context 'Move card using after parameter' { $null = Move-GitHubProjectCard -Card $cardTwo.id -After $card.id - $results = Get-GitHubProjectCard -Column $column.id + $results = @(Get-GitHubProjectCard -Column $column.id) It 'Card now exists in new column' { $results[1].note | Should be $defaultCardTwo @@ -160,7 +160,7 @@ try Context 'Move card to another column' { $null = Move-GitHubProjectCard -Card $cardTwo.id -Top -ColumnId $columnTwo.id - $results = Get-GitHubProjectCard -Column $columnTwo.id + $results = @(Get-GitHubProjectCard -Column $columnTwo.id) It 'Card now exists in new column' { $results[0].note | Should be $defaultCardTwo @@ -189,14 +189,14 @@ try } $card.id = (New-GitHubProjectCard -Column $column.id -Note $defaultCard).id - $results = Get-GitHubProjectCard -Card $card.id + $result = Get-GitHubProjectCard -Card $card.id It 'Card exists' { - $results | Should Not BeNullOrEmpty + $result | Should Not BeNullOrEmpty } It 'Note is correct' { - $results.note | Should be $defaultCard + $result.note | Should be $defaultCard } } @@ -214,14 +214,14 @@ try } $card.id = (New-GitHubProjectCard -Column $column.id -ContentId $issue.id -ContentType 'Issue').id - $results = Get-GitHubProjectCard -Card $card.id + $result = Get-GitHubProjectCard -Card $card.id It 'Card exists' { - $results | Should Not BeNullOrEmpty + $result | Should Not BeNullOrEmpty } It 'Content url is for an issue' { - $results.content_url | Should match 'issues' + $result.content_url | Should match 'issues' } } } diff --git a/Tests/GitHubProjectColumns.tests.ps1 b/Tests/GitHubProjectColumns.tests.ps1 index 2adf2a26..4591b677 100644 --- a/Tests/GitHubProjectColumns.tests.ps1 +++ b/Tests/GitHubProjectColumns.tests.ps1 @@ -37,13 +37,17 @@ try } Context 'Get columns for a project' { - $results = Get-GitHubProjectColumn -Project $project.id + $results = @(Get-GitHubProjectColumn -Project $project.id) It 'Should get column' { $results | Should Not BeNullOrEmpty } + It 'Should only have one column' { + $results.Count | Should Be 1 + } + It 'Name is correct' { - $results.name | Should be $defaultColumn + $results[0].name | Should Be $defaultColumn } } } @@ -65,32 +69,36 @@ try Context 'Modify column name' { $null = Set-GitHubProjectColumn -Column $column.id -Name $defaultColumnUpdate - $results = Get-GitHubProjectColumn -Column $column.id + $result = Get-GitHubProjectColumn -Column $column.id It 'Should get column' { - $results | Should Not BeNullOrEmpty + $result | Should Not BeNullOrEmpty } It 'Name has been updated' { - $results.name | Should be $defaultColumnUpdate + $result.name | Should Be $defaultColumnUpdate } } Context 'Move column to first position' { $null = Move-GitHubProjectColumn -Column $columntwo.id -First - $results = Get-GitHubProjectColumn -Project $project.id + $results = @(Get-GitHubProjectColumn -Project $project.id) + + It 'Should still have more than one column in the project' { + $results.Count | Should Be 2 + } It 'Column is now in the first position' { - $results[0].name | Should be $defaultColumnTwo + $results[0].name | Should Be $defaultColumnTwo } } Context 'Move column using after parameter' { $null = Move-GitHubProjectColumn -Column $columntwo.id -After $column.id - $results = Get-GitHubProjectColumn -Project $project.id + $results = @(Get-GitHubProjectColumn -Project $project.id) It 'Column is now not in the first position' { - $results[1].name | Should be $defaultColumnTwo + $results[1].name | Should Be $defaultColumnTwo } } @@ -116,14 +124,14 @@ try } $column.id = (New-GitHubProjectColumn -Project $project.id -Name $defaultColumn).id - $results = Get-GitHubProjectColumn -Column $column.id + $result = Get-GitHubProjectColumn -Column $column.id It 'Column exists' { - $results | Should Not BeNullOrEmpty + $result | Should Not BeNullOrEmpty } It 'Name is correct' { - $results.name | Should be $defaultColumn + $result.name | Should Be $defaultColumn } } } diff --git a/Tests/GitHubProjects.tests.ps1 b/Tests/GitHubProjects.tests.ps1 index 1ae123b8..931aa9c7 100644 --- a/Tests/GitHubProjects.tests.ps1 +++ b/Tests/GitHubProjects.tests.ps1 @@ -47,17 +47,21 @@ try $null = Remove-GitHubProject -Project $project.id -Confirm:$false } - $results = Get-GitHubProject -UserName $script:ownerName | Where-Object Name -eq $defaultUserProject + $results = @(Get-GitHubProject -UserName $script:ownerName | Where-Object Name -eq $defaultUserProject) It 'Should get project' { $results | Should Not BeNullOrEmpty } + It 'Should only get a single project' { + $results.Count | Should Be 1 + } + It 'Name is correct' { - $results.name | Should be $defaultUserProject + $results[0].name | Should be $defaultUserProject } It 'Description is correct' { - $results.body | Should be $defaultUserProjectDesc + $results[0].body | Should be $defaultUserProjectDesc } } @@ -73,17 +77,21 @@ try $null = Remove-GitHubProject -Project $project.id -Confirm:$false } - $results = Get-GitHubProject -OrganizationName $script:organizationName | Where-Object Name -eq $defaultOrgProject + $results = @(Get-GitHubProject -OrganizationName $script:organizationName | Where-Object Name -eq $defaultOrgProject) It 'Should get project' { $results | Should Not BeNullOrEmpty } + It 'Should only get a single project' { + $results.Count | Should Be 1 + } + It 'Name is correct' { - $results.name | Should be $defaultOrgProject + $results[0].name | Should be $defaultOrgProject } It 'Description is correct' { - $results.body | Should be $defaultOrgProjectDesc + $results[0].body | Should be $defaultOrgProjectDesc } } @@ -99,17 +107,21 @@ try $null = Remove-GitHubProject -Project $project.id -Confirm:$false } - $results = Get-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name | Where-Object Name -eq $defaultRepoProject + $results = @(Get-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name | Where-Object Name -eq $defaultRepoProject) It 'Should get project' { $results | Should Not BeNullOrEmpty } + It 'Should only get a single project' { + $results.Count | Should Be 1 + } + It 'Name is correct' { - $results.name | Should be $defaultRepoProject + $results[0].name | Should be $defaultRepoProject } It 'Description is correct' { - $results.body | Should be $defaultRepoProjectDesc + $results[0].body | Should be $defaultRepoProjectDesc } } @@ -126,21 +138,25 @@ try $null = Remove-GitHubProject -Project $project.id -Confirm:$false } - $results = Get-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -State 'Closed' | Where-Object Name -eq $defaultProjectClosed + $results = @(Get-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -State 'Closed' | Where-Object Name -eq $defaultProjectClosed) It 'Should get project' { $results | Should Not BeNullOrEmpty } + It 'Should only get a single project' { + $results.Count | Should Be 1 + } + It 'Name is correct' { - $results.name | Should be $defaultProjectClosed + $results[0].name | Should be $defaultProjectClosed } It 'Description is correct' { - $results.body | Should be $defaultProjectClosedDesc + $results[0].body | Should be $defaultProjectClosedDesc } It 'State is correct' { - $results.state | Should be "Closed" + $results[0].state | Should be "Closed" } } } @@ -159,17 +175,17 @@ try } $null = Set-GitHubProject -Project $project.id -Description $modifiedUserProjectDesc - $results = Get-GitHubProject -Project $project.id + $result = Get-GitHubProject -Project $project.id It 'Should get project' { - $results | Should Not BeNullOrEmpty + $result | Should Not BeNullOrEmpty } It 'Name is correct' { - $results.name | Should be $defaultUserProject + $result.name | Should be $defaultUserProject } It 'Description should be updated' { - $results.body | Should be $modifiedUserProjectDesc + $result.body | Should be $modifiedUserProjectDesc } } @@ -186,25 +202,25 @@ try } $null = Set-GitHubProject -Project $project.id -Description $modifiedOrgProjectDesc -Private:$false -OrganizationPermission Admin - $results = Get-GitHubProject -Project $project.id + $result = Get-GitHubProject -Project $project.id It 'Should get project' { - $results | Should Not BeNullOrEmpty + $result | Should Not BeNullOrEmpty } It 'Name is correct' { - $results.name | Should be $defaultOrgProject + $result.name | Should be $defaultOrgProject } It 'Description should be updated' { - $results.body | Should be $modifiedOrgProjectDesc + $result.body | Should be $modifiedOrgProjectDesc } It 'Visibility should be updated to public' { - $results.private | Should be $false + $result.private | Should be $false } It 'Organization permission should be updated to admin' { - $results.organization_permission | Should be 'admin' + $result.organization_permission | Should be 'admin' } } @@ -222,17 +238,17 @@ try } $null = Set-GitHubProject -Project $project.id -Description $modifiedRepoProjectDesc - $results = Get-GitHubProject -Project $project.id + $result = Get-GitHubProject -Project $project.id It 'Should get project' { - $results | Should Not BeNullOrEmpty + $result | Should Not BeNullOrEmpty } It 'Name is correct' { - $results.name | Should be $defaultRepoProject + $result.name | Should be $defaultRepoProject } It 'Description should be updated' { - $results.body | Should be $modifiedRepoProjectDesc + $result.body | Should be $modifiedRepoProjectDesc } } } @@ -252,17 +268,17 @@ try } $project.id = (New-GitHubProject -UserProject -Name $defaultUserProject -Description $defaultUserProjectDesc).id - $results = Get-GitHubProject -Project $project.id + $result = Get-GitHubProject -Project $project.id It 'Project exists' { - $results | Should Not BeNullOrEmpty + $result | Should Not BeNullOrEmpty } It 'Name is correct' { - $results.name | Should be $defaultUserProject + $result.name | Should be $defaultUserProject } It 'Description should be updated' { - $results.body | Should be $defaultUserProjectDesc + $result.body | Should be $defaultUserProjectDesc } } @@ -280,17 +296,17 @@ try } $project.id = (New-GitHubProject -OrganizationName $script:organizationName -Name $defaultOrgProject -Description $defaultOrgProjectDesc).id - $results = Get-GitHubProject -Project $project.id + $result = Get-GitHubProject -Project $project.id It 'Project exists' { - $results | Should Not BeNullOrEmpty + $result | Should Not BeNullOrEmpty } It 'Name is correct' { - $results.name | Should be $defaultOrgProject + $result.name | Should be $defaultOrgProject } It 'Description should be updated' { - $results.body | Should be $defaultOrgProjectDesc + $result.body | Should be $defaultOrgProjectDesc } } @@ -308,17 +324,17 @@ try } $project.id = (New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -Name $defaultRepoProject -Description $defaultRepoProjectDesc).id - $results = Get-GitHubProject -Project $project.id + $result = Get-GitHubProject -Project $project.id It 'Project Exists' { - $results | Should Not BeNullOrEmpty + $result | Should Not BeNullOrEmpty } It 'Name is correct' { - $results.name | Should be $defaultRepoProject + $result.name | Should be $defaultRepoProject } It 'Description should be updated' { - $results.body | Should be $defaultRepoProjectDesc + $result.body | Should be $defaultRepoProjectDesc } } } diff --git a/Tests/GitHubReleases.tests.ps1 b/Tests/GitHubReleases.tests.ps1 index c414a38f..53d5ed31 100644 --- a/Tests/GitHubReleases.tests.ps1 +++ b/Tests/GitHubReleases.tests.ps1 @@ -17,7 +17,7 @@ try Describe 'Getting releases from repository' { $ownerName = "dotnet" $repositoryName = "core" - $releases = Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName + $releases = @(Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName) Context 'When getting all releases' { It 'Should return multiple releases' { @@ -26,11 +26,7 @@ try } Context 'When getting the latest releases' { - $latest = Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -Latest - - # Account for differences in array handling between PowerShell 7 vs earlier versions - # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. - $latest = ,$latest + $latest = @(Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -Latest) It 'Should return one value' { $latest.Count | Should Be 1 @@ -44,11 +40,7 @@ try Context 'When getting a specific release' { $specificIndex = 5 - $specific = Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -ReleaseId $releases[$specificIndex].id - - # Account for differences in array handling between PowerShell 7 vs earlier versions - # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. - $specific = ,$specific + $specific = @(Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -ReleaseId $releases[$specificIndex].id) It 'Should return one value' { $specific.Count | Should Be 1 @@ -61,11 +53,7 @@ try Context 'When getting a tagged release' { $taggedIndex = 8 - $tagged = Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -Tag $releases[$taggedIndex].tag_name - - # Account for differences in array handling between PowerShell 7 vs earlier versions - # In PowerShell 7 ([PSCustomObject]@{}).Count is 1. In earlier versions, it's $null. - $tagged = ,$tagged + $tagged = @(Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -Tag $releases[$taggedIndex].tag_name) It 'Should return one value' { $tagged.Count | Should Be 1 @@ -84,7 +72,7 @@ try try { Set-GitHubConfiguration -DefaultOwnerName "dotnet" Set-GitHubConfiguration -DefaultRepositoryName "core" - $releases = Get-GitHubRelease + $releases = @(Get-GitHubRelease) Context 'When getting all releases' { It 'Should return multiple releases' { diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index a313d40c..2a7361be 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -25,8 +25,8 @@ try $privateRepo = $privateRepo } - $publicRepos = Get-GitHubRepository -Visibility Public - $privateRepos = Get-GitHubRepository -Visibility Private + $publicRepos = @(Get-GitHubRepository -Visibility Public) + $privateRepos = @(Get-GitHubRepository -Visibility Private) It "Should have the public repo" { $publicRepo.Name | Should BeIn $publicRepos.Name @@ -50,7 +50,7 @@ try } Context 'For any user' { - $repos = Get-GitHubRepository -OwnerName 'octocat' -Type Public + $repos = @(Get-GitHubRepository -OwnerName 'octocat' -Type Public) It "Should have results for The Octocat" { $repos.Count | Should -BeGreaterThan 0 @@ -66,7 +66,7 @@ try $repo = $repo } - $repos = Get-GitHubRepository -OrganizationName $script:organizationName -Type All + $repos = @(Get-GitHubRepository -OrganizationName $script:organizationName -Type All) It "Should have results for the organization" { $repo.name | Should BeIn $repos.name } @@ -89,14 +89,14 @@ try $repo = $repo } - $returned = Get-GitHubRepository -Uri $repo.svn_url + $result = Get-GitHubRepository -Uri $repo.svn_url It "Should be a single result using Uri ParameterSet" { - $returned | Should -BeOfType PSCustomObject + $result | Should -BeOfType PSCustomObject } - $returned = Get-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.Name + $result = Get-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.Name It "Should be a single result using Elements ParameterSet" { - $returned | Should -BeOfType PSCustomObject + $result | Should -BeOfType PSCustomObject } It 'Should not permit additional parameters' { diff --git a/Tests/GitHubRepositoryForks.tests.ps1 b/Tests/GitHubRepositoryForks.tests.ps1 index ee8c13fd..be56f282 100644 --- a/Tests/GitHubRepositoryForks.tests.ps1 +++ b/Tests/GitHubRepositoryForks.tests.ps1 @@ -13,11 +13,11 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent try { Describe 'Creating a new fork for user' { - $originalForks = Get-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub + $originalForks = @(Get-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub) Context 'When a new fork is created' { $repo = New-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub - $newForks = Get-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Sort Newest + $newForks = @(Get-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Sort Newest) It 'Should have one more fork than before' { ($newForks.Count - $originalForks.Count) | Should be 1 @@ -32,13 +32,11 @@ try } Describe 'Creating a new fork for an org' { - $originalForks = Get-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub + $originalForks = @(Get-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub) Context 'When a new fork is created' { - <# Temporary hack due to issues with this test in ADO #> . (Join-Path -Path $moduleRootPath -ChildPath 'Tests\Config\Settings.ps1') - $repo = New-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub -OrganizationName $script:organizationName - $newForks = Get-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Sort Newest + $newForks = @(Get-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Sort Newest) It 'Should have one more fork than before' { ($newForks.Count - $originalForks.Count) | Should be 1 From 23a680a7ce23ddd3ce6ef58266c27ddfc993b8df Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sat, 30 May 2020 14:02:30 -0700 Subject: [PATCH 4/5] Re-enable tests for Linux --- build/pipelines/azure-pipelines.ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/pipelines/azure-pipelines.ci.yaml b/build/pipelines/azure-pipelines.ci.yaml index 1a9cdd2a..9adc9f1a 100644 --- a/build/pipelines/azure-pipelines.ci.yaml +++ b/build/pipelines/azure-pipelines.ci.yaml @@ -34,7 +34,7 @@ jobs: steps: - template: ./templates/verify-testConfigSettingsHash.yaml - template: ./templates/run-staticAnalysis.yaml -# - template: ./templates/run-unitTests.yaml + - template: ./templates/run-unitTests.yaml - job: macOS pool: From 3066540a24ef0ba65839fbbda9cc95511498bff1 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sat, 30 May 2020 14:05:52 -0700 Subject: [PATCH 5/5] Restore GitHubAnalytics functions to previous (correct) array behavior --- GitHubAnalytics.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/GitHubAnalytics.ps1 b/GitHubAnalytics.ps1 index d8958fd0..e4bba220 100644 --- a/GitHubAnalytics.ps1 +++ b/GitHubAnalytics.ps1 @@ -89,10 +89,10 @@ function Group-GitHubIssue $endOfWeek = Get-Date foreach ($week in $weekDates) { - $filteredIssues = $Issue | Where-Object { + $filteredIssues = @($Issue | Where-Object { (($DateType -eq 'Created') -and ($_.created_at -ge $week) -and ($_.created_at -le $endOfWeek)) -or (($DateType -eq 'Closed') -and ($_.closed_at -ge $week) -and ($_.closed_at -le $endOfWeek)) - } + }) $endOfWeek = $week @@ -210,10 +210,10 @@ function Group-GitHubPullRequest $endOfWeek = Get-Date foreach ($week in $weekDates) { - $filteredPullRequests = $PullRequest | Where-Object { + $filteredPullRequests = @($PullRequest | Where-Object { (($DateType -eq 'Created') -and ($_.created_at -ge $week) -and ($_.created_at -le $endOfWeek)) -or (($DateType -eq 'Merged') -and ($_.merged_at -ge $week) -and ($_.merged_at -le $endOfWeek)) - } + }) $endOfWeek = $week