|
| 1 | +#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' } |
| 2 | + |
| 3 | +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( |
| 4 | + 'PSUseDeclaredVarsMoreThanAssignments', '', |
| 5 | + Justification = 'Pester grouping syntax: known issue.' |
| 6 | +)] |
| 7 | +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( |
| 8 | + 'PSAvoidUsingConvertToSecureStringWithPlainText', '', |
| 9 | + Justification = 'Used to create a secure string for testing.' |
| 10 | +)] |
| 11 | +[CmdletBinding()] |
| 12 | +param() |
| 13 | + |
| 14 | +Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { |
| 15 | + BeforeAll { |
| 16 | + Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT |
| 17 | + } |
| 18 | + AfterAll { |
| 19 | + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount |
| 20 | + } |
| 21 | + Context 'Repository' { |
| 22 | + It "Get-GitHubRepository - Gets the authenticated user's repositories (USER_FG_PAT)" { |
| 23 | + { Get-GitHubRepository } | Should -Not -Throw |
| 24 | + } |
| 25 | + It "Get-GitHubRepository - Gets the authenticated user's public repositories (USER_FG_PAT)" { |
| 26 | + { Get-GitHubRepository -Type 'public' } | Should -Not -Throw |
| 27 | + } |
| 28 | + It 'Get-GitHubRepository - Gets the public repos where the authenticated user is owner (USER_FG_PAT)' { |
| 29 | + { Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' } | Should -Not -Throw |
| 30 | + } |
| 31 | + It 'Get-GitHubRepository - Gets a specific repository (USER_FG_PAT)' { |
| 32 | + { Get-GitHubRepository -Owner 'PSModule' -Name 'GitHub' } | Should -Not -Throw |
| 33 | + } |
| 34 | + It 'Get-GitHubRepository - Gets all repositories from a organization (USER_FG_PAT)' { |
| 35 | + { Get-GitHubRepository -Owner 'PSModule' } | Should -Not -Throw |
| 36 | + } |
| 37 | + It 'Get-GitHubRepository - Gets all repositories from a user (USER_FG_PAT)' { |
| 38 | + { Get-GitHubRepository -Username 'MariusStorhaug' } | Should -Not -Throw |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +Describe 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { |
| 44 | + BeforeAll { |
| 45 | + Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT |
| 46 | + } |
| 47 | + AfterAll { |
| 48 | + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount |
| 49 | + } |
| 50 | + Context 'Repository' { |
| 51 | + It "Get-GitHubRepository - Gets the authenticated user's repositories (ORG_FG_PAT)" { |
| 52 | + { Get-GitHubRepository } | Should -Not -Throw |
| 53 | + } |
| 54 | + It "Get-GitHubRepository - Gets the authenticated user's public repositories (ORG_FG_PAT)" { |
| 55 | + { Get-GitHubRepository -Type 'public' } | Should -Not -Throw |
| 56 | + } |
| 57 | + It 'Get-GitHubRepository - Gets the public repos where the authenticated user is owner (ORG_FG_PAT)' { |
| 58 | + { Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' } | Should -Not -Throw |
| 59 | + } |
| 60 | + It 'Get-GitHubRepository - Gets a specific repository (ORG_FG_PAT)' { |
| 61 | + { Get-GitHubRepository -Owner 'PSModule' -Name 'GitHub' } | Should -Not -Throw |
| 62 | + } |
| 63 | + It 'Get-GitHubRepository - Gets all repositories from a organization (ORG_FG_PAT)' { |
| 64 | + { Get-GitHubRepository -Owner 'PSModule' } | Should -Not -Throw |
| 65 | + } |
| 66 | + It 'Get-GitHubRepository - Gets all repositories from a user (ORG_FG_PAT)' { |
| 67 | + { Get-GitHubRepository -Username 'MariusStorhaug' } | Should -Not -Throw |
| 68 | + } |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +Describe 'As a user - Classic PAT token (PAT)' { |
| 73 | + BeforeAll { |
| 74 | + Connect-GitHubAccount -Token $env:TEST_USER_PAT |
| 75 | + } |
| 76 | + AfterAll { |
| 77 | + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +Describe 'As GitHub Actions (GHA)' { |
| 82 | + BeforeAll { |
| 83 | + Connect-GitHubAccount |
| 84 | + } |
| 85 | + AfterAll { |
| 86 | + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +Describe 'As a GitHub App - Enterprise (APP_ENT)' { |
| 91 | + BeforeAll { |
| 92 | + Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY |
| 93 | + } |
| 94 | + AfterAll { |
| 95 | + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +Describe 'As a GitHub App - Organization (APP_ORG)' { |
| 100 | + BeforeAll { |
| 101 | + Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY |
| 102 | + } |
| 103 | + AfterAll { |
| 104 | + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount |
| 105 | + } |
| 106 | +} |
0 commit comments