Fix multi-result behavior across all versions of PowerShell (fixes CI UT's on all platforms) (#199)

Tests were failing on Mac and Linux, but not Windows ([recent test run](https://dev.azure.com/ms/PowerShellForGitHub/_build/results?buildId=83887&view=logs&j=0da5d1d9-276d-5173-c4c4-9d4d4ed14fdb)).  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:

587e204262/GitHubCore.ps1 (L648)
`...`
587e204262/GitHubCore.ps1 (L670)

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 making `Count` 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](https://stackoverflow.com/a/60330501) or you have to do wrap the result in an array on the caller side.

587e204262/GitHubCore.ps1 (L684-L685)

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
This commit is contained in:
Howard Wolosky 2020-05-30 15:42:04 -07:00 коммит произвёл GitHub
Родитель 587e204262
Коммит bcd0a5616e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
12 изменённых файлов: 175 добавлений и 152 удалений

Просмотреть файл

@ -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)"
}
@ -681,8 +685,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
{

Просмотреть файл

@ -16,10 +16,10 @@ 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
$issues.Count | Should be 0
}
}
@ -34,29 +34,29 @@ 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.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
$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
$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') }
$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
$issues.Count | Should be 1
}
}
@ -88,18 +88,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 +186,10 @@ try
$null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit
$repositoryUrl = "https://github.com/$script:ownerName/$repositoryName"
$collaborators = Get-GitHubRepositoryCollaborator -Uri $repositoryUrl
$collaborators = @(Get-GitHubRepositoryCollaborator -Uri $repositoryUrl)
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
@ -201,10 +201,10 @@ try
$null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit
$repositoryUrl = "https://github.com/$script:ownerName/$repositoryName"
$contributors = Get-GitHubRepositoryContributor -Uri $repositoryUrl -IncludeStatistics
$contributors = @(Get-GitHubRepositoryContributor -Uri $repositoryUrl -IncludeStatistics)
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
@ -242,15 +242,13 @@ 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
$current = @(Get-GitHubRepository -OrganizationName $script:organizationName)
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
@ -260,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 |
@ -268,7 +266,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
@ -298,14 +296,14 @@ try
$repositoryName = [guid]::NewGuid().Guid
$null = New-GitHubRepository -RepositoryName $repositoryName -AutoInit
$branches = Get-GitHubRepositoryBranch -OwnerName $script:ownerName -RepositoryName $repositoryName
$branches = @(Get-GitHubRepositoryBranch -OwnerName $script:ownerName -RepositoryName $repositoryName)
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

Просмотреть файл

@ -44,7 +44,7 @@ try
Context 'For adding an assignee to an issue'{
$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

Просмотреть файл

@ -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"
}
@ -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
@ -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' {

Просмотреть файл

@ -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' {
@ -110,11 +110,11 @@ try
$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' {

Просмотреть файл

@ -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'
}
}
}

Просмотреть файл

@ -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
}
}
}

Просмотреть файл

@ -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
}
}
}

Просмотреть файл

@ -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,24 +26,24 @@ try
}
Context 'When getting the latest releases' {
$latest = Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -Latest
$latest = @(Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -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
}
}
Context 'When getting a specific release' {
$specificIndex = 5
$specific = Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -ReleaseId $releases[$specificIndex].id
$specific = @(Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -ReleaseId $releases[$specificIndex].id)
It 'Should return one value' {
@($specific).Count | Should Be 1
$specific.Count | Should Be 1
}
It 'Should return the correct release' {
@ -53,10 +53,10 @@ try
Context 'When getting a tagged release' {
$taggedIndex = 8
$tagged = Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -Tag $releases[$taggedIndex].tag_name
$tagged = @(Get-GitHubRelease -OwnerName $ownerName -RepositoryName $repositoryName -Tag $releases[$taggedIndex].tag_name)
It 'Should return one value' {
@($tagged).Count | Should Be 1
$tagged.Count | Should Be 1
}
It 'Should return the correct release' {
@ -72,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' {

Просмотреть файл

@ -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' {

Просмотреть файл

@ -13,14 +13,14 @@ $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
($newForks.Count - $originalForks.Count) | Should be 1
}
It 'Should be the latest fork in the list' {
@ -32,16 +32,14 @@ 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
($newForks.Count - $originalForks.Count) | Should be 1
}
It 'Should be the latest fork in the list' {

Просмотреть файл

@ -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