⚙️ [Maintenance]: Test infrastructure consolidated with shared repos and run-scoped cleanup#541
Conversation
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
- Created TEMPLATE.ps1 for structuring tests with Pester. - Implemented Teams.Tests.ps1 to test GitHub Teams API functionalities including team creation, retrieval, updating, and deletion. - Developed Users.Tests.ps1 to validate user-related API calls, including user retrieval and updates. - Added Variables.Tests.ps1 to test GitHub variable management across different scopes (organization, repository, environment). - Included necessary suppressions for Pester warnings and established logging for better output visibility during test execution.
- Created TEMPLATE.ps1 for structuring Pester tests with common setup. - Implemented Teams.Tests.ps1 to test GitHub Teams API functionalities including team creation, retrieval, updating, and deletion. - Developed Users.Tests.ps1 to validate user-related API calls, including user retrieval and updates. - Added Variables.Tests.ps1 to test GitHub repository and organization variable management, including creation, updating, and removal of variables.
…in BeforeAll script
… in AfterAll script
ad98f64 to
3dbdfc3
Compare
…t/consolidate-test-setup-tasks
No Significant Changes DetectedThis PR does not contain changes to files that would trigger a new release:
Build, test, and publish stages will be skipped for this PR. If you believe this is incorrect, please verify that your changes are in the correct locations. |
… checks for shared repos - BeforeAll.ps1/AfterAll.ps1: Use direct Get-GitHubRepository -Name lookups instead of listing all repos and filtering by wildcard. Reduces API call volume and avoids unnecessary pagination/rate-limit pressure. - Secrets.Tests.ps1/Variables.Tests.ps1: Add null checks after Get-GitHubRepository calls to fail fast with actionable error messages when shared test repos are missing.
No Significant Changes DetectedThis PR does not contain changes to files that would trigger a new release:
Build, test, and publish stages will be skipped for this PR. If you believe this is incorrect, please verify that your changes are in the correct locations. |
Super-linter summary
All files and directories linted successfully For more information, see the GitHub Actions workflow run Powered by Super-linter |
…eterministic cleanup
No Significant Changes DetectedThis PR does not contain changes to files that would trigger a new release:
Build, test, and publish stages will be skipped for this PR. If you believe this is incorrect, please verify that your changes are in the correct locations. |
Super-linter summary
All files and directories linted successfully For more information, see the GitHub Actions workflow run Powered by Super-linter |
… Releases.Tests.ps1
No Significant Changes DetectedThis PR does not contain changes to files that would trigger a new release:
Build, test, and publish stages will be skipped for this PR. If you believe this is incorrect, please verify that your changes are in the correct locations. |
Super-linter summary
All files and directories linted successfully For more information, see the GitHub Actions workflow run Powered by Super-linter |
No Significant Changes DetectedThis PR does not contain changes to files that would trigger a new release:
Build, test, and publish stages will be skipped for this PR. If you believe this is incorrect, please verify that your changes are in the correct locations. |
Super-linter summary
All files and directories linted successfully For more information, see the GitHub Actions workflow run Powered by Super-linter |
No changes to the module's public API or behavior. All changes are in
tests/.New:
tests/BeforeAll.ps1andtests/AfterAll.ps1Two new global scripts run once before and after all parallel test jobs per workflow run.
BeforeAll.ps1— for each auth case exceptGITHUB_TOKEN:GITHUB_RUN_IDandSettingsenv vars (prevents unscoped wildcard cleanup from affecting concurrent runs)Test-{OS}-{TokenType}-{RunID}*from a previous attempt of the same run (re-run safety)Test-{OS}-{TokenType}-{RunID}— includesAddReadme, MIT license, and VisualStudio gitignore to satisfy release asset test requirements-2,-3) per OS for organization owners only — user owners never enter theSelectedRepositorytest contexts so the extras are not neededAfterAll.ps1— for each auth case exceptGITHUB_TOKEN:GITHUB_RUN_IDandSettingsenv varsTest-{OS}-{TokenType}-{RunID}*New:
tests/README.mdDocuments the shared-repo pattern, naming conventions, and the per-file test structure for contributors.
Modified: test files that previously created their own repositories
The following files previously called
New-GitHubRepositoryin their per-contextBeforeAlland removed repos in theirAfterAll. They now reference the shared repo viaGet-GitHubRepositoryand contain no repo lifecycle code.Actions.Tests.ps1[guid]::NewGuid()→$env:GITHUB_RUN_ID;New-GitHubRepository→Get-GitHubRepository; repo cleanup removed fromBeforeAll/AfterAllEnvironments.Tests.ps1Releases.Tests.ps1Secrets.Tests.ps1$repo2/$repo3only fetched fororganizationowners; stale-secret cleanup filter tightened from$secretPrefix*to$secretName*(run-scoped)Variables.Tests.ps1Modified: test files that keep their own repo lifecycle (CRUD tests)
Repositories.Tests.ps1— still creates and deletes its own repos because that is what it tests. Change:[guid]::NewGuid()→$env:GITHUB_RUN_ID; cleanup filter tightened from$repoPrefix*to$repoName*(run-scoped, prevents collateral deletion across concurrent runs).Modified: naming alignment only
Teams.Tests.ps1[guid]::NewGuid()→$env:GITHUB_RUN_ID; cleanup filter tightened from$teamPrefix*to$teamName*Organizations.Tests.ps1Get-Random→$env:GITHUB_RUN_ID; pre-test cleanup filter tightened from$orgPrefix*to$orgName*Modified: top-level
BeforeAlladdedThe following files had no top-level
BeforeAllblock. One was added to each to establish$testName,$os, and$idvariables consistently with the rest of the test suite.Apps.Tests.ps1,Artifacts.Tests.ps1,Permissions.Tests.ps1Modified: top-level
BeforeAlladded + minor fixesEmojis.Tests.ps1Connect-GitHubAppmoved from an inlineif ($AuthType -eq 'APP')block into the contextBeforeAll; dead placeholderif ($Type -eq 'GitHub Actions') {}removedEnterprise.Tests.ps1# DEFAULTS ACROSS ALL TESTScomment removed;Describe 'Template'corrected toDescribe 'Enterprise'GitHub.Tests.ps1Connect-GitHubAppin theInvoke-GitHubAPIcontext moved into contextBeforeAll; inlineif ($AuthType -eq 'APP') { It ... }converted toIt ... -Skip:($AuthType -ne 'APP')Users.Tests.ps1if ($OwnerType -eq 'user') { It ... }converted toContext 'Authenticated user' -Skip:($OwnerType -ne 'user') { It ... }Modified:
tests/TEMPLATE.ps1Rewritten to demonstrate the shared-repo pattern:
Get-GitHubRepositoryinstead ofNew-GitHubRepository,$id = $env:GITHUB_RUN_ID,-Skip:($OwnerType -in ('repository', 'enterprise')).Repository creation budget
BeforeAll.ps1— 3 org cases × 3 reposBeforeAll.ps1— 2 user cases × 1 repoRepositories.TestsCRUD — 5 cases × ~7psmodule-userowner budget: 16/hr (was ~20/hr before this PR, now 4 under the secondary rate limit threshold).