Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
84d99ad
Initial plan
Copilot Jan 5, 2026
581213b
Add BeforeAll.ps1 and AfterAll.ps1 for global test setup/teardown
Copilot Jan 5, 2026
e68238d
Add documentation for test setup/teardown scripts
Copilot Jan 5, 2026
5a69d8e
Fix hashtable splatting syntax in BeforeAll.ps1 and AfterAll.ps1
Copilot Jan 5, 2026
8ec4641
Add context logging for better debugging visibility
Copilot Jan 5, 2026
268c05c
Refactor: Move app authentication to BeforeAll blocks
MariusStorhaug Jan 6, 2026
333143d
Reset the tests and clear the AfterAll and BeforeAll files.
MariusStorhaug Jan 6, 2026
8867fe7
Add initial Pester tests for GitHub API interactions
MariusStorhaug Jan 12, 2026
6869f4a
Add Pester tests for GitHub API interactions
MariusStorhaug Jan 12, 2026
9e41346
Refactor: Add structure to Variables and Secrets setup log groups
MariusStorhaug Jan 12, 2026
f899e1e
Refactor: Enhance logging for repository setup in BeforeAll script
MariusStorhaug Jan 14, 2026
82d0a10
Refactor: Standardize context output formatting in repository setup
MariusStorhaug Jan 14, 2026
eda2347
Refactor: Remove redundant parameter from Connect-GitHubAccount call …
MariusStorhaug Jan 14, 2026
801b90a
Refactor: Skip setup for existing repositories using GITHUB_TOKEN
MariusStorhaug Jan 14, 2026
286ca3b
Refactor: Consolidate repository setup and environment initialization…
MariusStorhaug Jan 14, 2026
e70369c
Refactor: Remove unused variables and streamline repository setup in …
MariusStorhaug Jan 14, 2026
d3c5531
Merge branch 'main' of https://github.com/PSModule/GitHub into copilo…
MariusStorhaug Feb 15, 2026
32c55fe
Merge branch 'main' of https://github.com/PSModule/GitHub into copilo…
MariusStorhaug Feb 17, 2026
959366e
Move lightweight/medium test files back to tests/ and fix issues
MariusStorhaug Feb 17, 2026
29865ad
Move test files back to tmp/ for incremental migration
MariusStorhaug Feb 17, 2026
9c977a1
Add Enterprise tests to validate GitHubEnterprise properties and beha…
MariusStorhaug Feb 17, 2026
1e15271
Add 'API' tag to PSData in manifest.psd1
MariusStorhaug Feb 17, 2026
7d34687
Consolidate test setup configuration and update README formatting
MariusStorhaug Feb 17, 2026
5264066
Fix formatting in README-SETUP-TEARDOWN.md by removing extra whitespace
MariusStorhaug Feb 17, 2026
aba5a4e
Remove Enterprise.Tests.ps1 file to streamline test suite
MariusStorhaug Feb 17, 2026
1cab02e
Fix parameter name in Get-GitHubRepository call for clarity
MariusStorhaug Feb 17, 2026
ea974f7
Refactor test setup and teardown scripts to derive OS names from sett…
MariusStorhaug Feb 17, 2026
bc0a72f
Refactor test setup scripts to improve clarity and streamline reposit…
MariusStorhaug Feb 17, 2026
27ac6d3
Enhance test documentation and cleanup scripts for improved clarity a…
MariusStorhaug Feb 17, 2026
bdac052
Migrate all test files to shared repo pattern with run-scoped cleanup
MariusStorhaug Apr 4, 2026
a093666
Merge remote-tracking branch 'origin/main' into copilot/consolidate-t…
MariusStorhaug Apr 4, 2026
24da735
Merge branch 'main' into copilot/consolidate-test-setup-tasks
MariusStorhaug Apr 5, 2026
59a03ee
Merge branch 'main' of https://github.com/PSModule/GitHub into copilo…
MariusStorhaug May 1, 2026
ca70b97
✨ [Refactor]: Consolidate test setup across multiple test files
MariusStorhaug May 1, 2026
4e9bf57
✨ [Refactor]: Add environment variable checks for GITHUB_RUN_ID and S…
MariusStorhaug May 1, 2026
1300fb4
✨ [Refactor]: Simplify repository creation and logging for user and o…
MariusStorhaug May 1, 2026
36c0e05
Fix MD060 table alignment in tests/README.md (two data rows 1 char sh…
MariusStorhaug May 1, 2026
322329f
Fix review feedback: run-scoped team names, lowercase license keyword…
MariusStorhaug May 1, 2026
5d9c711
Fix formatting in README.md: add missing line breaks for better reada…
MariusStorhaug May 1, 2026
1eea360
Add GITHUB_RUN_ID guards to test files; fix /app endpoint context; co…
MariusStorhaug May 1, 2026
1ddb2ad
Fix misleading throw message in Variables.Tests.ps1 guard (Skipping -…
MariusStorhaug May 1, 2026
d271e09
Add GITHUB_RUN_ID guards to Actions/Environments/Releases tests; add …
MariusStorhaug May 1, 2026
bd17f82
Replace list+filter repo cleanup with deterministic lookups; add null…
MariusStorhaug May 1, 2026
2865f38
Fix README.md: use 'mit' keyword, clarify org-only extras, document d…
MariusStorhaug May 1, 2026
e3e9c0d
Guard shared repo null-check for repository/enterprise owner types in…
MariusStorhaug May 1, 2026
af4a749
Validate $osNames from Settings JSON in BeforeAll/AfterAll (review th…
MariusStorhaug May 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 16 additions & 27 deletions tests/Actions.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
param()

BeforeAll {
$testName = 'ActionsTests'
$testName = 'Actions'
$os = $env:RUNNER_OS
$guid = [guid]::NewGuid().ToString()
$id = $env:GITHUB_RUN_ID
Comment thread
MariusStorhaug marked this conversation as resolved.
if (-not $id) {
throw 'GITHUB_RUN_ID is required for Actions tests because it is used to build repository-scoped names for OIDC operations.'
}
}

Describe 'Actions' {
Expand Down Expand Up @@ -51,37 +54,23 @@ Describe 'Actions' {
Write-Host ($context | Format-List | Out-String)
}
}
$repoPrefix = "$testName-$os-$TokenType"
$repoName = "$repoPrefix-$guid"
$repoPrefix = "Test-$os-$TokenType"
$repoName = "$repoPrefix-$id"

switch ($OwnerType) {
'user' {
Get-GitHubRepository | Where-Object { $_.Name -like "$repoPrefix*" } |
Remove-GitHubRepository -Confirm:$false
$repo = New-GitHubRepository -Name $repoName -Confirm:$false
}
'organization' {
Get-GitHubRepository -Organization $Owner | Where-Object { $_.Name -like "$repoPrefix*" } |
Remove-GitHubRepository -Confirm:$false
$repo = New-GitHubRepository -Organization $Owner -Name $repoName -Confirm:$false
LogGroup "Using Repository - [$repoName]" {
if ($OwnerType -in ('repository', 'enterprise')) {
$repo = $null
} else {
$repo = Get-GitHubRepository -Owner $Owner -Name $repoName
Comment thread
MariusStorhaug marked this conversation as resolved.
if (-not $repo) {
throw "Shared test repository '$repoName' was not found for owner '$Owner' (OwnerType: '$OwnerType'). Ensure the repository was provisioned and the repository name is correct."
}
Write-Host ($repo | Select-Object * | Out-String)
}
}
LogGroup "Repository - [$repoName]" {
Write-Host ($repo | Select-Object * | Out-String)
}
}

AfterAll {
switch ($OwnerType) {
'user' {
Get-GitHubRepository | Where-Object { $_.Name -like "$repoPrefix*" } |
Remove-GitHubRepository -Confirm:$false
}
'organization' {
Get-GitHubRepository -Organization $Owner | Where-Object { $_.Name -like "$repoPrefix*" } |
Remove-GitHubRepository -Confirm:$false
}
}
Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent
Write-Host ('-' * 60)
}
Expand Down
77 changes: 77 additions & 0 deletions tests/AfterAll.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
[CmdletBinding()]
param()

LogGroup 'AfterAll - Global Test Teardown' {
$authCases = . "$PSScriptRoot/Data/AuthCases.ps1"

$id = $env:GITHUB_RUN_ID
if (-not $id) {
throw 'GITHUB_RUN_ID environment variable is not set. Refusing to clean up test repositories with an unscoped wildcard (would impact concurrent runs).'
}
if (-not $env:Settings) {
throw 'Settings environment variable is not set. Process-PSModule must populate it with the test suite configuration.'
}
$prefix = 'Test'

# Derive the list of OS names from the Settings JSON provided by Process-PSModule.
try {
$settings = $env:Settings | ConvertFrom-Json
} catch {
throw "Settings environment variable contains invalid JSON. Expected TestSuites.Module.OSName to be present. $_"
}

$osNames = @($settings.TestSuites.Module.OSName | Sort-Object -Unique)
if (-not $osNames) {
throw 'Settings JSON must include at least one non-empty TestSuites.Module.OSName value.'
}
$invalidOsNames = @($osNames | Where-Object { -not $_ -or -not $_.ToString().Trim() })
if ($invalidOsNames.Count -gt 0) {
throw 'Settings JSON contains one or more null or empty TestSuites.Module.OSName values.'
}
Write-Host "Cleaning up test repositories for OSes: $($osNames -join ', ')"

foreach ($authCase in $authCases) {
$authCase.GetEnumerator() | ForEach-Object { Set-Variable -Name $_.Key -Value $_.Value }

if ($TokenType -eq 'GITHUB_TOKEN') {
Write-Host "Skipping teardown for $AuthType-$TokenType (uses existing repository)"
continue
}

LogGroup "Teardown - $AuthType-$TokenType" {
$context = Connect-GitHubAccount @connectParams -PassThru -Silent
if ($AuthType -eq 'APP') {
$context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent
}
Write-Host ($context | Format-List | Out-String)

foreach ($os in $osNames) {
$repoPrefix = "$prefix-$os-$TokenType"
$repoName = "$repoPrefix-$id"

LogGroup "Repository cleanup - $AuthType-$TokenType - $os" {
# Use deterministic name lookups instead of listing all repos to reduce API calls.
$cleanupRepoNames = @($repoName)
if ($OwnerType -eq 'organization') {
$cleanupRepoNames += "$repoName-2", "$repoName-3"
}

foreach ($cleanupRepoName in $cleanupRepoNames) {
switch ($OwnerType) {
'user' {
Get-GitHubRepository -Name $cleanupRepoName -ErrorAction SilentlyContinue |
Remove-GitHubRepository -Confirm:$false
}
'organization' {
Get-GitHubRepository -Owner $Owner -Name $cleanupRepoName -ErrorAction SilentlyContinue |
Remove-GitHubRepository -Confirm:$false
}
}
}
}
}

Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent
}
}
}
6 changes: 6 additions & 0 deletions tests/Apps.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
[CmdletBinding()]
param()

BeforeAll {
$testName = 'Apps'
$os = $env:RUNNER_OS
$id = $env:GITHUB_RUN_ID
}

Describe 'Apps' {
$authCases = . "$PSScriptRoot/Data/AuthCases.ps1"

Expand Down
6 changes: 6 additions & 0 deletions tests/Artifacts.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
[CmdletBinding()]
param()

BeforeAll {
$testName = 'Artifacts'
$os = $env:RUNNER_OS
$id = $env:GITHUB_RUN_ID
}

Describe 'Artifacts' {
$authCases = . "$PSScriptRoot/Data/AuthCases.ps1"

Expand Down
99 changes: 99 additions & 0 deletions tests/BeforeAll.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
[CmdletBinding()]
param()

LogGroup 'BeforeAll - Global Test Setup' {
$authCases = . "$PSScriptRoot/Data/AuthCases.ps1"
$id = $env:GITHUB_RUN_ID
if (-not $id) {
throw 'GITHUB_RUN_ID environment variable is not set. Refusing to create or clean up test repositories with a non-deterministic name.'
}
if (-not $env:Settings) {
throw 'Settings environment variable is not set. Process-PSModule must populate it with the test suite configuration.'
}

# Derive the list of OS names from the Settings JSON provided by Process-PSModule.
try {
$settings = $env:Settings | ConvertFrom-Json
} catch {
throw "Settings environment variable does not contain valid JSON. Process-PSModule must populate it with a valid test suite configuration. $_"
}

$osNames = @($settings.TestSuites.Module.OSName | Sort-Object -Unique)
if (-not $osNames) {
throw 'Settings JSON must contain TestSuites.Module.OSName with at least one OS name.'
}
$invalidOsNames = @($osNames | Where-Object { -not $_ -or -not $_.ToString().Trim() })
if ($invalidOsNames.Count -gt 0) {
throw 'Settings JSON contains one or more null or empty values in TestSuites.Module.OSName.'
}
Write-Host "Creating test repositories for OSes: $($osNames -join ', ')"

foreach ($authCase in $authCases) {
$authCase.GetEnumerator() | ForEach-Object { Set-Variable -Name $_.Key -Value $_.Value }

if ($TokenType -eq 'GITHUB_TOKEN') {
Write-Host "Skipping setup for $AuthType-$TokenType (uses existing repository)"
continue
}

$context = Connect-GitHubAccount @connectParams -PassThru -Silent
if ($AuthType -eq 'APP') {
$context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent
}
Write-Host ($context | Format-List | Out-String)

foreach ($os in $osNames) {
$repoPrefix = "Test-$os-$TokenType"
$repoName = "$repoPrefix-$id"

LogGroup "Repository setup - $AuthType-$TokenType - $os" {
# Clean up repos from a previous attempt of the same run (re-runs).
# Use deterministic name lookups instead of listing all repos to reduce API calls.
$cleanupRepoNames = @($repoName)
if ($OwnerType -eq 'organization') {
$cleanupRepoNames += "$repoName-2", "$repoName-3"
}

foreach ($cleanupRepoName in $cleanupRepoNames) {
switch ($OwnerType) {
'user' {
Get-GitHubRepository -Name $cleanupRepoName -ErrorAction SilentlyContinue |
Remove-GitHubRepository -Confirm:$false
}
'organization' {
Get-GitHubRepository -Owner $Owner -Name $cleanupRepoName -ErrorAction SilentlyContinue |
Remove-GitHubRepository -Confirm:$false
}
}
}

# Create the primary shared repository (with readme, license, gitignore for release tests).
$repoParams = @{
Name = $repoName
AddReadme = $true
License = 'mit'
Gitignore = 'VisualStudio'
}
switch ($OwnerType) {
'user' {
New-GitHubRepository @repoParams
}
'organization' {
New-GitHubRepository @repoParams -Organization $Owner
}
}

# Create extra repositories needed by Secrets/Variables SelectedRepository tests.
# Only organization owners need them — those tests are skipped for user owners.
if ($OwnerType -eq 'organization') {
foreach ($suffix in 2, 3) {
$extraName = "$repoName-$suffix"
New-GitHubRepository -Organization $Owner -Name $extraName
}
}
}
}

Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent
}
}
24 changes: 11 additions & 13 deletions tests/Emojis.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
[CmdletBinding()]
param()

BeforeAll {
$testName = 'Emojis'
$os = $env:RUNNER_OS
$id = $env:GITHUB_RUN_ID
}

Describe 'Emojis' {
$authCases = . "$PSScriptRoot/Data/AuthCases.ps1"

Expand All @@ -28,26 +34,18 @@ Describe 'Emojis' {
LogGroup 'Context' {
Write-Host ($context | Format-List | Out-String)
}
}
AfterAll {
Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent
Write-Host ('-' * 60)
}

# Tests for APP goes here
if ($AuthType -eq 'APP') {
It 'Connect-GitHubApp - Connects as a GitHub App to <Owner>' {
if ($AuthType -eq 'APP') {
$context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent
LogGroup 'Context' {
Write-Host ($context | Format-List | Out-String)
}
}
}
AfterAll {
Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent
Write-Host ('-' * 60)
}

# Tests for runners goes here
if ($Type -eq 'GitHub Actions') {}

# Tests for IAT UAT and PAT goes here
It 'Get-GitHubEmoji - Gets a list of all emojis' {
$emojis = Get-GitHubEmoji
LogGroup 'emojis' {
Expand Down
6 changes: 4 additions & 2 deletions tests/Enterprise.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
param()

BeforeAll {
# DEFAULTS ACROSS ALL TESTS
$testName = 'Enterprise'
$os = $env:RUNNER_OS
$id = $env:GITHUB_RUN_ID
}

Describe 'Template' {
Describe 'Enterprise' {
$authCases = . "$PSScriptRoot/Data/AuthCases.ps1"

Context 'As <Type> using <Case> on <Target>' -ForEach $authCases {
Expand Down
35 changes: 12 additions & 23 deletions tests/Environments.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
param()

BeforeAll {
$testName = 'EnvironmentsTests'
$testName = 'Environments'
$os = $env:RUNNER_OS
$guid = [guid]::NewGuid().ToString()
$id = $env:GITHUB_RUN_ID
Comment thread
MariusStorhaug marked this conversation as resolved.
if (-not $id) {
throw 'GITHUB_RUN_ID is required for Environments tests.'
}
}

Describe 'Environments' {
Expand All @@ -40,34 +43,20 @@ Describe 'Environments' {
Write-Host ($context | Format-List | Out-String)
}
}
$repoPrefix = "$testName-$os-$TokenType"
$repoName = "$repoPrefix-$guid"
$environmentName = "$testName-$os-$TokenType-$guid"
$repoPrefix = "Test-$os-$TokenType"
$repoName = "$repoPrefix-$id"
$environmentName = "$testName-$os-$TokenType-$id"

switch ($OwnerType) {
'user' {
Get-GitHubRepository | Where-Object { $_.Name -like "$repoPrefix*" } | Remove-GitHubRepository -Confirm:$false
$repo = New-GitHubRepository -Name $repoName -Confirm:$false
}
'organization' {
Get-GitHubRepository -Organization $Owner | Where-Object { $_.Name -like "$repoPrefix*" } | Remove-GitHubRepository -Confirm:$false
$repo = New-GitHubRepository -Organization $owner -Name $repoName -Confirm:$false
LogGroup "Using Repository - [$repoName]" {
$repo = Get-GitHubRepository -Owner $Owner -Name $repoName
Comment thread
MariusStorhaug marked this conversation as resolved.
if (($OwnerType -notin ('repository', 'enterprise')) -and (-not $repo)) {
throw "Shared test repository '$repoName' was not found for owner '$Owner'. Ensure the repository was created before running the environment tests."
}
}
LogGroup "Repository - [$repoName]" {
Write-Host ($repo | Select-Object * | Out-String)
}
}

AfterAll {
switch ($OwnerType) {
'user' {
Get-GitHubRepository | Where-Object { $_.Name -like "$repoPrefix*" } | Remove-GitHubRepository -Confirm:$false
}
'organization' {
Get-GitHubRepository -Organization $Owner | Where-Object { $_.Name -like "$repoPrefix*" } | Remove-GitHubRepository -Confirm:$false
}
}
Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent
Write-Host ('-' * 60)
}
Expand Down
Loading
Loading