Skip to content

Commit f80b19d

Browse files
MariusStorhaugCopilot
andcommitted
Refactor test cleanup in AfterAll.ps1 and streamline organization removal tests in Organizations.Tests.ps1
Co-authored-by: Copilot <copilot@github.com>
1 parent 3362dc5 commit f80b19d

2 files changed

Lines changed: 5 additions & 29 deletions

File tree

tests/AfterAll.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ LogGroup 'AfterAll - Global Test Teardown' {
2929
}
3030
Write-Host "Cleaning up test repositories for OSes: $($osNames -join ', ')"
3131

32-
# Test files that own their per-test-file repositories. Mirror BeforeAll.ps1.
3332
$testNames = @('Environments', 'Secrets', 'Variables', 'Releases', 'Actions')
3433
$testNamesWithExtraRepos = @('Secrets', 'Variables')
35-
3634
foreach ($authCase in $authCases) {
3735
$authCase.GetEnumerator() | ForEach-Object { Set-Variable -Name $_.Key -Value $_.Value }
3836

tests/Organizations.Tests.ps1

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,12 @@ Describe 'Organizations' {
138138
{ Update-GitHubOrganization -Name $orgName -Location 'New Location' } | Should -Throw
139139
}
140140

141+
It 'Remove-GitHubOrganization - Removes an organization using enterprise installation' -Skip:($OwnerType -ne 'enterprise') {
142+
{ Remove-GitHubOrganization -Name $orgName -Confirm:$false } | Should -Throw
143+
}
144+
141145
It 'Install-GitHubApp - Installs a GitHub App to an organization' -Skip:($OwnerType -ne 'enterprise') {
142-
# The enterprise organization was just created and may not have propagated to the
143-
# enterprise apps endpoint yet. Retry briefly to absorb propagation delay before
144-
# failing — GitHub returns 404 (rather than 403) when the resource is not yet visible
145-
# to the token, which is indistinguishable from a missing-permission failure on the
146-
# first call. See issue #596.
147-
$installation = $null
148-
$maxAttempts = 5
149-
$delaySeconds = 3
150-
for ($attempt = 1; $attempt -le $maxAttempts; $attempt++) {
151-
try {
152-
$installation = Install-GitHubApp -Enterprise $owner -Organization $orgName -ClientID $installationContext.ClientID -RepositorySelection 'all'
153-
break
154-
} catch {
155-
if ($attempt -eq $maxAttempts) { throw }
156-
Write-Host "Install-GitHubApp attempt $attempt failed ($($_.Exception.Message)); retrying in $delaySeconds seconds..."
157-
Start-Sleep -Seconds $delaySeconds
158-
}
159-
}
146+
$installation = Install-GitHubApp -Enterprise $owner -Organization $orgName -ClientID $installationContext.ClientID -RepositorySelection 'all'
160147
LogGroup 'Installed App' {
161148
Write-Host ($installation | Select-Object * | Out-String)
162149
}
@@ -177,15 +164,6 @@ Describe 'Organizations' {
177164
Update-GitHubOrganization -Name $orgName -Location 'New Location' -Context $orgContext
178165
}
179166

180-
# GitHub's DELETE /orgs/{org} endpoint requires the app to have the org-level
181-
# `administration: write` permission. The enterprise IAT is enterprise-scoped and does not
182-
# carry org-level permissions, so this call is expected to fail regardless of which
183-
# enterprise permissions the app holds. An org-level IAT (obtained after Install-GitHubApp)
184-
# is required. See issue #596.
185-
It 'Remove-GitHubOrganization - Removes an organization using enterprise installation' -Skip:($OwnerType -ne 'enterprise') {
186-
{ Remove-GitHubOrganization -Name $orgName -Confirm:$false } | Should -Throw
187-
}
188-
189167
It 'Remove-GitHubOrganization - Removes an organization using organization installation' -Skip:($OwnerType -ne 'enterprise') {
190168
$orgContext = Connect-GitHubApp -Organization $orgName -Context $context -PassThru -Silent
191169
Remove-GitHubOrganization -Name $orgName -Confirm:$false -Context $orgContext

0 commit comments

Comments
 (0)