Skip to content

Commit 1eea360

Browse files
Add GITHUB_RUN_ID guards to test files; fix /app endpoint context; correct README example suffix
1 parent 5d9c711 commit 1eea360

7 files changed

Lines changed: 18 additions & 2 deletions

File tree

tests/GitHub.Tests.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ Describe 'API' {
573573
Write-Host ($context | Format-List | Out-String)
574574
}
575575
$context | Should -Not -BeNullOrEmpty
576+
$appContext = $context
576577
if ($AuthType -eq 'APP') {
577578
$context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent
578579
LogGroup 'Context - Installation' {
@@ -587,7 +588,7 @@ Describe 'API' {
587588

588589
It 'Invoke-GitHubAPI - Gets the app details' -Skip:($AuthType -ne 'APP') {
589590
{
590-
$app = Invoke-GitHubAPI -ApiEndpoint '/app'
591+
$app = Invoke-GitHubAPI -ApiEndpoint '/app' -Context $appContext
591592
LogGroup 'App' {
592593
Write-Host ($app | Format-List | Out-String)
593594
}

tests/Organizations.Tests.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ BeforeAll {
2323
$testName = 'Organizations'
2424
$os = $env:RUNNER_OS
2525
$id = $env:GITHUB_RUN_ID
26+
if (-not $id) {
27+
throw 'GITHUB_RUN_ID is required to safely scope pre-test cleanup in Organizations.Tests.ps1.'
28+
}
2629
}
2730

2831
Describe 'Organizations' {

tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Describe 'TestName' {
146146
| Resource | Pattern | Example |
147147
|------------|----------------------------------------------|----------------------------------|
148148
| Repo | `Test-{OS}-{TokenType}-{RunID}` | `Test-Linux-USER_FG_PAT-1234` |
149-
| Extra repo | `Test-{OS}-{TokenType}-{RunID}-{N}` | `Test-Linux-USER_FG_PAT-1234-1` |
149+
| Extra repo | `Test-{OS}-{TokenType}-{RunID}-{N}` | `Test-Linux-USER_FG_PAT-1234-2` |
150150
| Secret | `{TestName}_{OS}_{TokenType}_{RunID}` | `Secrets_Linux_PAT_1234` |
151151
| Variable | `{TestName}_{OS}_{TokenType}_{RunID}` | `Variables_Linux_PAT_1234` |
152152
| Team | `{TestName}_{OS}_{TokenType}_{RunID}_{Name}` | `Teams_Linux_APP_ORG_1234_Pull` |

tests/Repositories.Tests.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ BeforeAll {
2323
$testName = 'Repositories'
2424
$os = $env:RUNNER_OS
2525
$id = $env:GITHUB_RUN_ID
26+
if (-not $id) {
27+
throw 'GITHUB_RUN_ID is required for Repositories tests because cleanup removes repositories and teams by name prefix.'
28+
}
2629
}
2730

2831
Describe 'Repositories' {

tests/Secrets.Tests.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ BeforeAll {
2323
$testName = 'Secrets'
2424
$os = $env:RUNNER_OS
2525
$id = $env:GITHUB_RUN_ID
26+
if (-not $id) {
27+
throw 'GITHUB_RUN_ID is required for Secrets tests because secret cleanup uses run-scoped wildcard names.'
28+
}
2629
}
2730

2831
Describe 'Secrets' {

tests/Teams.Tests.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ BeforeAll {
2323
$testName = 'Teams'
2424
$os = $env:RUNNER_OS
2525
$id = $env:GITHUB_RUN_ID
26+
if (-not $id) {
27+
throw 'GITHUB_RUN_ID is not set. Refusing to run Teams tests cleanup without a scoped run ID.'
28+
}
2629
}
2730

2831
Describe 'Teams' {

tests/Variables.Tests.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ BeforeAll {
2323
$testName = 'Variables'
2424
$os = $env:RUNNER_OS
2525
$id = $env:GITHUB_RUN_ID
26+
if (-not $id) {
27+
throw 'GITHUB_RUN_ID is not set. Skipping Variables tests to avoid deleting variables from other runs.'
28+
}
2629
}
2730

2831
Describe 'Variables' {

0 commit comments

Comments
 (0)