From 18502e73415359b1e04a0173ef8357a75005d909 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 15:39:44 +0100 Subject: [PATCH 01/60] =?UTF-8?q?=F0=9F=9A=80=20[Feature]:=20Add=20compreh?= =?UTF-8?q?ensive=20authentication=20tests=20for=20GitHub=20account=20conn?= =?UTF-8?q?ections?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Auth.Tests.ps1 | 100 +++++++++++++++----------------- tests/Auth2.Tests.ps1 | 36 ++++++++++++ tests/AuthCases.ps1 | 64 ++++++++++++++++++++ tests/Emojis.Tests.ps1 | 109 +++++++++++++++-------------------- tests/Environments.Tests.ps1 | 90 ++++++++++++++--------------- 5 files changed, 236 insertions(+), 163 deletions(-) create mode 100644 tests/Auth2.Tests.ps1 create mode 100644 tests/AuthCases.ps1 diff --git a/tests/Auth.Tests.ps1 b/tests/Auth.Tests.ps1 index 9433e969e..bf2dc9cf9 100644 --- a/tests/Auth.Tests.ps1 +++ b/tests/Auth.Tests.ps1 @@ -11,7 +11,9 @@ [CmdletBinding()] param() -Describe 'GitHub' { +Describe 'Auth' { + $tests = . "$PSScriptRoot/AuthCases.ps1" + Context 'Auth' { It 'Connect-GitHubAccount - Connects GitHub Actions without parameters' { { Connect-GitHubAccount } | Should -Not -Throw @@ -133,72 +135,62 @@ Describe 'GitHub' { Get-GitHubContext -ListAvailable | Should -HaveCount 0 } } -} -Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Auth' { + Context 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { + BeforeAll { + Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT + } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } It 'Get-GitHubViewer - Gets the logged in context (USER_FG_PAT)' { Get-GitHubViewer | Should -Not -BeNullOrEmpty } } -} -Describe 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Auth' { + Context 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { + BeforeAll { + Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT + } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } It 'Get-GitHubViewer - Gets the logged in context (ORG_FG_PAT)' { Get-GitHubViewer | Should -Not -BeNullOrEmpty } } -} -Describe 'As a user - Classic PAT token (PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Auth' { + Context 'As a user - Classic PAT token (PAT)' { + BeforeAll { + Connect-GitHubAccount -Token $env:TEST_USER_PAT + } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } It 'Get-GitHubViewer - Gets the logged in context (PAT)' { Get-GitHubViewer | Should -Not -BeNullOrEmpty } } -} -Describe 'As GitHub Actions (GHA)' { - BeforeAll { - Connect-GitHubAccount - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Auth' { + Context 'As GitHub Actions (GHA)' { + BeforeAll { + Connect-GitHubAccount + } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } It 'Get-GitHubViewer - Gets the logged in context (GHA)' { Get-GitHubViewer | Should -Not -BeNullOrEmpty } } -} -Describe 'As a GitHub App - Enterprise (APP_ENT)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Auth' { + Context 'As a GitHub App - Enterprise (APP_ENT)' { + BeforeAll { + Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY + } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } It 'Connect-GitHubApp - Connects one enterprise installation for the authenticated GitHub App (APP_ENT)' { $context = Get-GitHubContext { Connect-GitHubApp -Enterprise msx -Context $context } | Should -Not -Throw @@ -214,16 +206,14 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Get-GitHubContext -ListAvailable | Should -HaveCount 3 } } -} -Describe 'As a GitHub App - Organization (APP_ORG)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Auth' { + Context 'As a GitHub App - Organization (APP_ORG)' { + BeforeAll { + Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY + } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } It 'Connect-GitHubApp - Connects one user installation for the authenticated GitHub App (APP_ORG)' { $context = Get-GitHubContext { Connect-GitHubApp -User 'psmodule-user' -Context $context } | Should -Not -Throw diff --git a/tests/Auth2.Tests.ps1 b/tests/Auth2.Tests.ps1 new file mode 100644 index 000000000..f71f74ede --- /dev/null +++ b/tests/Auth2.Tests.ps1 @@ -0,0 +1,36 @@ +#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' } + +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', '', + Justification = 'Pester grouping syntax: known issue.' +)] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingConvertToSecureStringWithPlainText', '', + Justification = 'Used to create a secure string for testing.' +)] +[CmdletBinding()] +param() + +Describe 'Auth' { + $tests = . "$PSScriptRoot/AuthCases.ps1" + + Context 'As using on ' { + It 'Connect-GitHubAccount - Connects GitHub Actions without parameters' { + $context = Connect-GitHubAccount @connectParams -PassThru + $context | Should -Not -BeNullOrEmpty + } + if ($context.AuthType -eq 'APP') { + It 'Connect-GitHubApp - Connects the app to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default + $context | Should -Not -BeNullOrEmpty + } + } + It 'Get-GitHubViewer - Gets the logged in context' { + Get-GitHubViewer | Should -Not -BeNullOrEmpty + } + } + + AfterEach { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } +} diff --git a/tests/AuthCases.ps1 b/tests/AuthCases.ps1 new file mode 100644 index 000000000..42a6ddd96 --- /dev/null +++ b/tests/AuthCases.ps1 @@ -0,0 +1,64 @@ +@( + @{ + Type = 'a user' + Case = 'Fine-grained PAT token' + Target = 'it self (user account)' + Owner = 'psmodule-user' + $connectParams = @{ + Token = $env:TEST_USER_USER_FG_PAT + } + } + @{ + Type = 'a user' + Case = 'Fine-grained PAT token' + Target = 'organization account' + Owner = 'psmodule-test-org2' + $connectParams = @{ + Token = $env:TEST_USER_ORG_FG_PAT + } + } + @{ + Type = 'a user' + Case = 'Classic PAT token' + Target = 'user account' + Owner = 'psmodule-user' + $connectParams = @{ + Token = $env:TEST_USER_PAT + } + } + @{ + Type = 'GitHub Actions' + Case = 'GITHUB_TOKEN' + Target = 'this repository (GitHub)' + Owner = 'PSModule' + $connectParams = @{ + Token = $env:GITHUB_TOKEN + } + } + @{ + Type = 'a GitHub App from an Enterprise' + Case = 'PEM + IAT' + Target = 'organization account' + Owner = 'psmodule-test-org3' + $connectParams = @{ + ClientID = $env:TEST_APP_ENT_CLIENT_ID + $PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY + } + $connectAppParams = @{ + Organization = 'psmodule-test-org3' + } + } + @{ + Type = 'a GitHub App from an Organization' + Case = 'PEM + IAT' + Target = 'organization account' + Owner = 'psmodule-test-org' + $connectParams = @{ + ClientID = $env:TEST_APP_ORG_CLIENT_ID + $PrivateKey = $env:TEST_APP_ORG_PRIVATE_KEY + } + $connectAppParams = @{ + Organization = 'psmodule-test-org' + } + } +) diff --git a/tests/Emojis.Tests.ps1 b/tests/Emojis.Tests.ps1 index 2159a14af..65515443e 100644 --- a/tests/Emojis.Tests.ps1 +++ b/tests/Emojis.Tests.ps1 @@ -11,106 +11,89 @@ [CmdletBinding()] param() -Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Emoji' { - It 'Get-GitHubEmoji - Gets a list of all emojis (USER_FG_PAT)' { +Describe 'Emoji' { + Context 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { + BeforeAll { + Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT + } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } + + It 'Get-GitHubEmoji - Gets a list of all emojis' { { Get-GitHubEmoji } | Should -Not -Throw } - It 'Get-GitHubEmoji - Downloads all emojis (USER_FG_PAT)' { + It 'Get-GitHubEmoji - Downloads all emojis' { { Get-GitHubEmoji -Path $Home } | Should -Not -Throw } } -} -Describe 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Emoji' { - It 'Get-GitHubEmoji - Gets a list of all emojis (ORG_FG_PAT)' { + Context 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { + BeforeAll { + Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT + } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } + It 'Get-GitHubEmoji - Gets a list of all emojis' { { Get-GitHubEmoji } | Should -Not -Throw } - It 'Get-GitHubEmoji - Downloads all emojis (ORG_FG_PAT)' { + It 'Get-GitHubEmoji - Downloads all emojis' { { Get-GitHubEmoji -Path $Home } | Should -Not -Throw } } -} -Describe 'As a user - Classic PAT token (PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Emoji' { - It 'Get-GitHubEmoji - Gets a list of all emojis (PAT)' { + Context 'As a user - Classic PAT token (PAT)' { + BeforeAll { + Connect-GitHubAccount -Token $env:TEST_USER_PAT + } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } + It 'Get-GitHubEmoji - Gets a list of all emojis' { { Get-GitHubEmoji } | Should -Not -Throw } - It 'Get-GitHubEmoji - Downloads all emojis (PAT)' { + It 'Get-GitHubEmoji - Downloads all emojis' { { Get-GitHubEmoji -Path $Home } | Should -Not -Throw } - } -} -Describe 'As GitHub Actions (GHA)' { - BeforeAll { - Connect-GitHubAccount - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } - Context 'Emoji' { - It 'Get-GitHubEmoji - Gets a list of all emojis (GHA)' { + + Context 'As GitHub Actions (GHA)' { + BeforeAll { + Connect-GitHubAccount + } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } + It 'Get-GitHubEmoji - Gets a list of all emojis' { { Get-GitHubEmoji } | Should -Not -Throw } - It 'Get-GitHubEmoji - Downloads all emojis (GHA)' { + It 'Get-GitHubEmoji - Downloads all emojis' { { Get-GitHubEmoji -Path $Home } | Should -Not -Throw } - } -} -Describe 'As a GitHub App - Enterprise (APP_ENT)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Emoji' { + + Context 'As a GitHub App - Enterprise (APP_ENT)' { BeforeAll { + Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY Connect-GitHubApp -Organization 'psmodule-test-org3' -Default } AfterAll { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } - It 'Get-GitHubEmoji - Gets a list of all emojis (APP_ENT)' { + It 'Get-GitHubEmoji - Gets a list of all emojis' { { Get-GitHubEmoji } | Should -Not -Throw } - It 'Get-GitHubEmoji - Downloads all emojis (APP_ENT)' { + It 'Get-GitHubEmoji - Downloads all emojis' { { Get-GitHubEmoji -Path $Home } | Should -Not -Throw } } -} -Describe 'As a GitHub App - Organization (APP_ORG)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Emoji' { + Context 'As a GitHub App - Organization (APP_ORG)' { BeforeAll { + Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY Connect-GitHubApp -Organization 'psmodule-test-org' -Default } AfterAll { diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 index 0fd0a6ddf..b816021fb 100644 --- a/tests/Environments.Tests.ps1 +++ b/tests/Environments.Tests.ps1 @@ -2,7 +2,7 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSUseDeclaredVarsMoreThanAssignments', '', - Justification = 'Pester grouping syntax: known issue.' + Justification = 'Pester grouping syntax - known issue.' )] [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidUsingConvertToSecureStringWithPlainText', '', @@ -31,52 +31,52 @@ Describe 'Environments' { Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } - It 'Get-GitHubEnvironment: should return an empty list when no environments exist' { + It 'Get-GitHubEnvironment - should return an empty list when no environments exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result | Should -BeNullOrEmpty } - It 'Get-GitHubEnvironment: should return null when retrieving a non-existent environment' { + It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } - It 'Set-GitHubEnvironment: should successfully create an environment with a wait timer of 10' { + It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -WaitTimer 10 $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $environmentName $result.ProtectionRules.wait_timer | Should -Be 10 } - It 'Get-GitHubEnvironment: should retrieve the environment that was created' { + It 'Get-GitHubEnvironment - should retrieve the environment that was created' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $environmentName } - It 'Set-GitHubEnvironment: should successfully create an environment with a slash in its name' { + It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - It 'Get-GitHubEnvironment: should retrieve the environment with a slash in its name' { + It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - It 'Remove-GitHubEnvironment: should delete the environment with a slash in its name without errors' { + It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' { { Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false } | Should -Not -Throw } - It 'Get-GitHubEnvironment: should return null when retrieving the deleted environment with a slash in its name' { + It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -BeNullOrEmpty } - It 'Get-GitHubEnvironment: should list one remaining environment' { + It 'Get-GitHubEnvironment - should list one remaining environment' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result.Count | Should -Be 1 } - It 'Remove-GitHubEnvironment: should delete the remaining environment without errors' { + It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' { { Remove-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -Confirm:$false } | Should -Not -Throw } - It 'Get-GitHubEnvironment: should return null when retrieving an environment that does not exist' { + It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } @@ -94,52 +94,52 @@ Describe 'Environments' { Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } - It 'Get-GitHubEnvironment: should return an empty list when no environments exist' { + It 'Get-GitHubEnvironment - should return an empty list when no environments exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result | Should -BeNullOrEmpty } - It 'Get-GitHubEnvironment: should return null when retrieving a non-existent environment' { + It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } - It 'Set-GitHubEnvironment: should successfully create an environment with a wait timer of 10' { + It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -WaitTimer 10 $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $environmentName $result.ProtectionRules.wait_timer | Should -Be 10 } - It 'Get-GitHubEnvironment: should retrieve the environment that was created' { + It 'Get-GitHubEnvironment - should retrieve the environment that was created' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $environmentName } - It 'Set-GitHubEnvironment: should successfully create an environment with a slash in its name' { + It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - It 'Get-GitHubEnvironment: should retrieve the environment with a slash in its name' { + It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - It 'Remove-GitHubEnvironment: should delete the environment with a slash in its name without errors' { + It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' { { Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false } | Should -Not -Throw } - It 'Get-GitHubEnvironment: should return null when retrieving the deleted environment with a slash in its name' { + It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -BeNullOrEmpty } - It 'Get-GitHubEnvironment: should list one remaining environment' { + It 'Get-GitHubEnvironment - should list one remaining environment' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result.Count | Should -Be 1 } - It 'Remove-GitHubEnvironment: should delete the remaining environment without errors' { + It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' { { Remove-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -Confirm:$false } | Should -Not -Throw } - It 'Get-GitHubEnvironment: should return null when retrieving an environment that does not exist' { + It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } @@ -162,52 +162,52 @@ Describe 'Environments' { Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } - It 'Get-GitHubEnvironment: should return an empty list when no environments exist' { + It 'Get-GitHubEnvironment - should return an empty list when no environments exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result | Should -BeNullOrEmpty } - It 'Get-GitHubEnvironment: should return null when retrieving a non-existent environment' { + It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } - It 'Set-GitHubEnvironment: should successfully create an environment with a wait timer of 10' { + It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -WaitTimer 10 $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $environmentName $result.ProtectionRules.wait_timer | Should -Be 10 } - It 'Get-GitHubEnvironment: should retrieve the environment that was created' { + It 'Get-GitHubEnvironment - should retrieve the environment that was created' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $environmentName } - It 'Set-GitHubEnvironment: should successfully create an environment with a slash in its name' { + It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - It 'Get-GitHubEnvironment: should retrieve the environment with a slash in its name' { + It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - It 'Remove-GitHubEnvironment: should delete the environment with a slash in its name without errors' { + It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' { { Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false } | Should -Not -Throw } - It 'Get-GitHubEnvironment: should return null when retrieving the deleted environment with a slash in its name' { + It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -BeNullOrEmpty } - It 'Get-GitHubEnvironment: should list one remaining environment' { + It 'Get-GitHubEnvironment - should list one remaining environment' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result.Count | Should -Be 1 } - It 'Remove-GitHubEnvironment: should delete the remaining environment without errors' { + It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' { { Remove-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -Confirm:$false } | Should -Not -Throw } - It 'Get-GitHubEnvironment: should return null when retrieving an environment that does not exist' { + It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } @@ -226,52 +226,52 @@ Describe 'Environments' { Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } - It 'Get-GitHubEnvironment: should return an empty list when no environments exist' { + It 'Get-GitHubEnvironment - should return an empty list when no environments exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result | Should -BeNullOrEmpty } - It 'Get-GitHubEnvironment: should return null when retrieving a non-existent environment' { + It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } - It 'Set-GitHubEnvironment: should successfully create an environment with a wait timer of 10' { + It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -WaitTimer 10 $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $environmentName $result.ProtectionRules.wait_timer | Should -Be 10 } - It 'Get-GitHubEnvironment: should retrieve the environment that was created' { + It 'Get-GitHubEnvironment - should retrieve the environment that was created' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $environmentName } - It 'Set-GitHubEnvironment: should successfully create an environment with a slash in its name' { + It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - It 'Get-GitHubEnvironment: should retrieve the environment with a slash in its name' { + It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - It 'Remove-GitHubEnvironment: should delete the environment with a slash in its name without errors' { + It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' { { Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false } | Should -Not -Throw } - It 'Get-GitHubEnvironment: should return null when retrieving the deleted environment with a slash in its name' { + It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -BeNullOrEmpty } - It 'Get-GitHubEnvironment: should list one remaining environment' { + It 'Get-GitHubEnvironment - should list one remaining environment' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result.Count | Should -Be 1 } - It 'Remove-GitHubEnvironment: should delete the remaining environment without errors' { + It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' { { Remove-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -Confirm:$false } | Should -Not -Throw } - It 'Get-GitHubEnvironment: should return null when retrieving an environment that does not exist' { + It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } From c281be028e5f48032ae675883255d5802bef24c4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 16:12:05 +0100 Subject: [PATCH 02/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20conn?= =?UTF-8?q?ection=20parameter=20variable=20names=20in=20authentication=20t?= =?UTF-8?q?est=20cases=20for=20consistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/AuthCases.ps1 | 72 ++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/AuthCases.ps1 b/tests/AuthCases.ps1 index 42a6ddd96..ddf67541c 100644 --- a/tests/AuthCases.ps1 +++ b/tests/AuthCases.ps1 @@ -1,63 +1,63 @@ @( @{ - Type = 'a user' - Case = 'Fine-grained PAT token' - Target = 'it self (user account)' - Owner = 'psmodule-user' - $connectParams = @{ + Type = 'a user' + Case = 'Fine-grained PAT token' + Target = 'it self (user account)' + Owner = 'psmodule-user' + ConnectParams = @{ Token = $env:TEST_USER_USER_FG_PAT } } @{ - Type = 'a user' - Case = 'Fine-grained PAT token' - Target = 'organization account' - Owner = 'psmodule-test-org2' - $connectParams = @{ + Type = 'a user' + Case = 'Fine-grained PAT token' + Target = 'organization account' + Owner = 'psmodule-test-org2' + ConnectParams = @{ Token = $env:TEST_USER_ORG_FG_PAT } } @{ - Type = 'a user' - Case = 'Classic PAT token' - Target = 'user account' - Owner = 'psmodule-user' - $connectParams = @{ + Type = 'a user' + Case = 'Classic PAT token' + Target = 'user account' + Owner = 'psmodule-user' + ConnectParams = @{ Token = $env:TEST_USER_PAT } } @{ - Type = 'GitHub Actions' - Case = 'GITHUB_TOKEN' - Target = 'this repository (GitHub)' - Owner = 'PSModule' - $connectParams = @{ + Type = 'GitHub Actions' + Case = 'GITHUB_TOKEN' + Target = 'this repository (GitHub)' + Owner = 'PSModule' + ConnectParams = @{ Token = $env:GITHUB_TOKEN } } @{ - Type = 'a GitHub App from an Enterprise' - Case = 'PEM + IAT' - Target = 'organization account' - Owner = 'psmodule-test-org3' - $connectParams = @{ - ClientID = $env:TEST_APP_ENT_CLIENT_ID - $PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY + Type = 'a GitHub App from an Enterprise' + Case = 'PEM + IAT' + Target = 'organization account' + Owner = 'psmodule-test-org3' + ConnectParams = @{ + ClientID = $env:TEST_APP_ENT_CLIENT_ID + PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY } - $connectAppParams = @{ + ConnectAppParams = @{ Organization = 'psmodule-test-org3' } } @{ - Type = 'a GitHub App from an Organization' - Case = 'PEM + IAT' - Target = 'organization account' - Owner = 'psmodule-test-org' - $connectParams = @{ - ClientID = $env:TEST_APP_ORG_CLIENT_ID - $PrivateKey = $env:TEST_APP_ORG_PRIVATE_KEY + Type = 'a GitHub App from an Organization' + Case = 'PEM + IAT' + Target = 'organization account' + Owner = 'psmodule-test-org' + ConnectParams = @{ + ClientID = $env:TEST_APP_ORG_CLIENT_ID + PrivateKey = $env:TEST_APP_ORG_PRIVATE_KEY } - $connectAppParams = @{ + ConnectAppParams = @{ Organization = 'psmodule-test-org' } } From 8a6c5dd6a290b1ae35cf27d3ea2d73955f9c80cc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 16:13:37 +0100 Subject: [PATCH 03/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Rename=20variab?= =?UTF-8?q?le=20for=20authentication=20test=20cases=20and=20enhance=20cont?= =?UTF-8?q?ext=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Auth2.Tests.ps1 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/Auth2.Tests.ps1 b/tests/Auth2.Tests.ps1 index f71f74ede..39b5bf282 100644 --- a/tests/Auth2.Tests.ps1 +++ b/tests/Auth2.Tests.ps1 @@ -12,9 +12,9 @@ param() Describe 'Auth' { - $tests = . "$PSScriptRoot/AuthCases.ps1" + $authCases = . "$PSScriptRoot/AuthCases.ps1" - Context 'As using on ' { + Context 'As using on ' -ForEach $authCases { It 'Connect-GitHubAccount - Connects GitHub Actions without parameters' { $context = Connect-GitHubAccount @connectParams -PassThru $context | Should -Not -BeNullOrEmpty @@ -25,12 +25,14 @@ Describe 'Auth' { $context | Should -Not -BeNullOrEmpty } } + It 'Get-GitHubViewer - Gets the logged in context' { Get-GitHubViewer | Should -Not -BeNullOrEmpty } - } - AfterEach { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + It 'Get-GitHubContext - Gets the logged in context' { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } } + } From ba92286142f2754e7a48859d0b75f51973fbd614 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 16:21:07 +0100 Subject: [PATCH 04/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20debug=20o?= =?UTF-8?q?utput=20for=20context=20in=20authentication=20test=20cases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Auth2.Tests.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Auth2.Tests.ps1 b/tests/Auth2.Tests.ps1 index 39b5bf282..78f8f76f0 100644 --- a/tests/Auth2.Tests.ps1 +++ b/tests/Auth2.Tests.ps1 @@ -17,15 +17,17 @@ Describe 'Auth' { Context 'As using on ' -ForEach $authCases { It 'Connect-GitHubAccount - Connects GitHub Actions without parameters' { $context = Connect-GitHubAccount @connectParams -PassThru + Write-Host ($context | Format-List | Out-String) $context | Should -Not -BeNullOrEmpty } if ($context.AuthType -eq 'APP') { It 'Connect-GitHubApp - Connects the app to ' { $context = Connect-GitHubApp @connectAppParams -PassThru -Default + Write-Host ($context | Format-List | Out-String) $context | Should -Not -BeNullOrEmpty } } - + It 'Get-GitHubViewer - Gets the logged in context' { Get-GitHubViewer | Should -Not -BeNullOrEmpty } From 5d0602d0bf805bf3d8628b214d6af23368d225ac Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 16:29:26 +0100 Subject: [PATCH 05/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Enhance=20login?= =?UTF-8?q?=20feedback=20for=20GitHub=20account=20connections=20and=20clea?= =?UTF-8?q?n=20up=20test=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Auth/Connect-GitHubAccount.ps1 | 10 ++++++++-- tests/Auth2.Tests.ps1 | 1 - 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index 8390f272a..443d305a3 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -293,8 +293,14 @@ Write-Verbose ($contextObj | Format-List | Out-String) if (-not $Silent) { $name = $contextObj.Username - Write-Host '✓ ' -ForegroundColor Green -NoNewline - Write-Host "Logged in as $name!" + if ($script.GitHub.EnvironmentType -eq 'GHA') { + LogGroup "✓ Logged in as $name!" { + Write-Host ($contextObj | Format-List | Out-String) + } + } else { + Write-Host '✓ ' -ForegroundColor Green -NoNewline + Write-Host "Logged in as $name!" + } } if ($PassThru) { Write-Debug "Passing context [$contextObj] to the pipeline." diff --git a/tests/Auth2.Tests.ps1 b/tests/Auth2.Tests.ps1 index 78f8f76f0..399316414 100644 --- a/tests/Auth2.Tests.ps1 +++ b/tests/Auth2.Tests.ps1 @@ -36,5 +36,4 @@ Describe 'Auth' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } } - } From 1593fc5f7d37c9bcdebfb0b55fd54d79fe2f9bd6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 16:41:14 +0100 Subject: [PATCH 06/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20loggin?= =?UTF-8?q?g=20and=20test=20descriptions=20for=20GitHub=20account=20connec?= =?UTF-8?q?tion=20functionality?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Auth/Connect-GitHubAccount.ps1 | 2 +- tests/Auth2.Tests.ps1 | 6 +++--- tests/AuthCases.ps1 | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index 443d305a3..c6531fd78 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -294,7 +294,7 @@ if (-not $Silent) { $name = $contextObj.Username if ($script.GitHub.EnvironmentType -eq 'GHA') { - LogGroup "✓ Logged in as $name!" { + Set-GitHubLogGroup "✓ Logged in as $name!" { Write-Host ($contextObj | Format-List | Out-String) } } else { diff --git a/tests/Auth2.Tests.ps1 b/tests/Auth2.Tests.ps1 index 399316414..fdb016156 100644 --- a/tests/Auth2.Tests.ps1 +++ b/tests/Auth2.Tests.ps1 @@ -15,13 +15,13 @@ Describe 'Auth' { $authCases = . "$PSScriptRoot/AuthCases.ps1" Context 'As using on ' -ForEach $authCases { - It 'Connect-GitHubAccount - Connects GitHub Actions without parameters' { + It 'Connect-GitHubAccount - Connects using the provided credentials' { $context = Connect-GitHubAccount @connectParams -PassThru Write-Host ($context | Format-List | Out-String) $context | Should -Not -BeNullOrEmpty } - if ($context.AuthType -eq 'APP') { - It 'Connect-GitHubApp - Connects the app to ' { + if ($AuthType -eq 'APP') { + It 'Connect-GitHubApp - Connects as a GitHub App to ' { $context = Connect-GitHubApp @connectAppParams -PassThru -Default Write-Host ($context | Format-List | Out-String) $context | Should -Not -BeNullOrEmpty diff --git a/tests/AuthCases.ps1 b/tests/AuthCases.ps1 index ddf67541c..6a445b94d 100644 --- a/tests/AuthCases.ps1 +++ b/tests/AuthCases.ps1 @@ -1,5 +1,6 @@ @( @{ + AuthType = 'PAT' Type = 'a user' Case = 'Fine-grained PAT token' Target = 'it self (user account)' @@ -9,6 +10,7 @@ } } @{ + AuthType = 'PAT' Type = 'a user' Case = 'Fine-grained PAT token' Target = 'organization account' @@ -18,6 +20,7 @@ } } @{ + AuthType = 'PAT' Type = 'a user' Case = 'Classic PAT token' Target = 'user account' @@ -27,6 +30,7 @@ } } @{ + AuthType = 'IAT' Type = 'GitHub Actions' Case = 'GITHUB_TOKEN' Target = 'this repository (GitHub)' @@ -36,6 +40,7 @@ } } @{ + AuthType = 'App' Type = 'a GitHub App from an Enterprise' Case = 'PEM + IAT' Target = 'organization account' @@ -49,6 +54,7 @@ } } @{ + AuthType = 'App' Type = 'a GitHub App from an Organization' Case = 'PEM + IAT' Target = 'organization account' From 5aa1172e1c715f4c8cd4a62e74e1950d514bcf93 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 17:03:10 +0100 Subject: [PATCH 07/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Improve=20loggi?= =?UTF-8?q?ng=20for=20GitHub=20account=20connection=20and=20enhance=20test?= =?UTF-8?q?=20output=20formatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Auth/Connect-GitHubAccount.ps1 | 2 +- src/functions/public/Auth/Connect-GitHubApp.ps1 | 10 ++++++++-- tests/Auth.Tests.ps1 | 2 -- tests/Auth2.Tests.ps1 | 11 +++++++---- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index c6531fd78..aa161e19e 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -293,7 +293,7 @@ Write-Verbose ($contextObj | Format-List | Out-String) if (-not $Silent) { $name = $contextObj.Username - if ($script.GitHub.EnvironmentType -eq 'GHA') { + if ($script:GitHub.EnvironmentType -eq 'GHA') { Set-GitHubLogGroup "✓ Logged in as $name!" { Write-Host ($contextObj | Format-List | Out-String) } diff --git a/src/functions/public/Auth/Connect-GitHubApp.ps1 b/src/functions/public/Auth/Connect-GitHubApp.ps1 index 5c0a4abfe..90e067a1c 100644 --- a/src/functions/public/Auth/Connect-GitHubApp.ps1 +++ b/src/functions/public/Auth/Connect-GitHubApp.ps1 @@ -160,8 +160,14 @@ Write-Verbose ($contextObj | Format-List | Out-String) if (-not $Silent) { $name = $contextObj.name - Write-Host '✓ ' -ForegroundColor Green -NoNewline - Write-Host "Connected $name!" + if ($script:GitHub.EnvironmentType -eq 'GHA') { + Set-GitHubLogGroup "✓ Connected $name!" { + Write-Host ($contextObj | Format-List | Out-String) + } + } else { + Write-Host '✓ ' -ForegroundColor Green -NoNewline + Write-Host "Connected $name!" + } } if ($PassThru) { Write-Debug "Passing context [$contextObj] to the pipeline." diff --git a/tests/Auth.Tests.ps1 b/tests/Auth.Tests.ps1 index bf2dc9cf9..2a3f34c02 100644 --- a/tests/Auth.Tests.ps1 +++ b/tests/Auth.Tests.ps1 @@ -12,8 +12,6 @@ param() Describe 'Auth' { - $tests = . "$PSScriptRoot/AuthCases.ps1" - Context 'Auth' { It 'Connect-GitHubAccount - Connects GitHub Actions without parameters' { { Connect-GitHubAccount } | Should -Not -Throw diff --git a/tests/Auth2.Tests.ps1 b/tests/Auth2.Tests.ps1 index fdb016156..2462bad8a 100644 --- a/tests/Auth2.Tests.ps1 +++ b/tests/Auth2.Tests.ps1 @@ -17,23 +17,26 @@ Describe 'Auth' { Context 'As using on ' -ForEach $authCases { It 'Connect-GitHubAccount - Connects using the provided credentials' { $context = Connect-GitHubAccount @connectParams -PassThru - Write-Host ($context | Format-List | Out-String) $context | Should -Not -BeNullOrEmpty } if ($AuthType -eq 'APP') { It 'Connect-GitHubApp - Connects as a GitHub App to ' { $context = Connect-GitHubApp @connectAppParams -PassThru -Default - Write-Host ($context | Format-List | Out-String) $context | Should -Not -BeNullOrEmpty } } It 'Get-GitHubViewer - Gets the logged in context' { - Get-GitHubViewer | Should -Not -BeNullOrEmpty + $viewer = Get-GitHubViewer + LogGroup 'Viewer' { + Write-Host ($viewer | Format-List | Out-String) + } + $viewer | Should -Not -BeNullOrEmpty } - It 'Get-GitHubContext - Gets the logged in context' { + It 'Disconnect-GitHubAccount - Disconnects all contexts' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + (Get-GitHubContext -ListAvailable).count | Should -Be 0 } } } From 71d197aded6c3236bd5236260171e4e849fe54e5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 17:20:40 +0100 Subject: [PATCH 08/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Enhance=20login?= =?UTF-8?q?=20and=20logout=20messages=20with=20color=20formatting=20for=20?= =?UTF-8?q?GitHub=20account=20connections?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Auth/Connect-GitHubAccount.ps1 | 4 +++- src/functions/public/Auth/Connect-GitHubApp.ps1 | 4 +++- src/functions/public/Auth/Disconnect-GitHubAccount.ps1 | 10 ++++++++-- src/loader.ps1 | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index aa161e19e..d4ace134d 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -294,7 +294,9 @@ if (-not $Silent) { $name = $contextObj.Username if ($script:GitHub.EnvironmentType -eq 'GHA') { - Set-GitHubLogGroup "✓ Logged in as $name!" { + $green = $PSStyle.Foreground.Green + $reset = $PSStyle.Reset + Set-GitHubLogGroup "$green✓$reset Logged in as $name!" { Write-Host ($contextObj | Format-List | Out-String) } } else { diff --git a/src/functions/public/Auth/Connect-GitHubApp.ps1 b/src/functions/public/Auth/Connect-GitHubApp.ps1 index 90e067a1c..719aa46fd 100644 --- a/src/functions/public/Auth/Connect-GitHubApp.ps1 +++ b/src/functions/public/Auth/Connect-GitHubApp.ps1 @@ -161,7 +161,9 @@ if (-not $Silent) { $name = $contextObj.name if ($script:GitHub.EnvironmentType -eq 'GHA') { - Set-GitHubLogGroup "✓ Connected $name!" { + $green = $PSStyle.Foreground.Green + $reset = $PSStyle.Reset + Set-GitHubLogGroup "$green✓$reset Connected $name!" { Write-Host ($contextObj | Format-List | Out-String) } } else { diff --git a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 index 1b2aafc29..7a67f2c43 100644 --- a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 @@ -52,8 +52,14 @@ } if (-not $Silent) { - Write-Host '✓ ' -ForegroundColor Green -NoNewline - Write-Host "Logged out of GitHub! [$contextItem]" + if ($script:GitHub.EnvironmentType -eq 'GHA') { + $green = $PSStyle.Foreground.Green + $reset = $PSStyle.Reset + Write-Host "$green✓$reset Logged out of GitHub! [$contextItem]" + } else { + Write-Host '✓ ' -ForegroundColor Green -NoNewline + Write-Host "Logged out of GitHub! [$contextItem]" + } } } } diff --git a/src/loader.ps1 b/src/loader.ps1 index bae17d6de..8fed8712b 100644 --- a/src/loader.ps1 +++ b/src/loader.ps1 @@ -4,6 +4,7 @@ Write-Verbose "Path: $scriptFilePath" switch ($script:GitHub.EnvironmentType) { 'GHA' { + $PSStyle.OutputRendering = 'Ansi' Write-Verbose 'Detected running on a GitHub Actions runner, preparing environment...' $env:GITHUB_REPOSITORY_NAME = $env:GITHUB_REPOSITORY -replace '.+/' Set-GitHubEnvironmentVariable -Name 'GITHUB_REPOSITORY_NAME' -Value $env:GITHUB_REPOSITORY_NAME From c585d03f156e6b0d99b6f36fea91600d988f5ab1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 17:29:31 +0100 Subject: [PATCH 09/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Simplify=20logi?= =?UTF-8?q?n=20and=20connection=20messages=20by=20removing=20unnecessary?= =?UTF-8?q?=20logging=20group?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Auth/Connect-GitHubAccount.ps1 | 4 +--- src/functions/public/Auth/Connect-GitHubApp.ps1 | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index d4ace134d..738944c73 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -296,9 +296,7 @@ if ($script:GitHub.EnvironmentType -eq 'GHA') { $green = $PSStyle.Foreground.Green $reset = $PSStyle.Reset - Set-GitHubLogGroup "$green✓$reset Logged in as $name!" { - Write-Host ($contextObj | Format-List | Out-String) - } + Write-Host "$green✓$reset Logged in as $name!" } else { Write-Host '✓ ' -ForegroundColor Green -NoNewline Write-Host "Logged in as $name!" diff --git a/src/functions/public/Auth/Connect-GitHubApp.ps1 b/src/functions/public/Auth/Connect-GitHubApp.ps1 index 719aa46fd..62fdad600 100644 --- a/src/functions/public/Auth/Connect-GitHubApp.ps1 +++ b/src/functions/public/Auth/Connect-GitHubApp.ps1 @@ -163,9 +163,7 @@ if ($script:GitHub.EnvironmentType -eq 'GHA') { $green = $PSStyle.Foreground.Green $reset = $PSStyle.Reset - Set-GitHubLogGroup "$green✓$reset Connected $name!" { - Write-Host ($contextObj | Format-List | Out-String) - } + Write-Host "$green✓$reset Connected $name!" } else { Write-Host '✓ ' -ForegroundColor Green -NoNewline Write-Host "Connected $name!" From 438df9dd2b57201b80c1de4ef63fa39e3db3233f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 17:39:53 +0100 Subject: [PATCH 10/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20authen?= =?UTF-8?q?tication=20tests=20to=20use=20silent=20mode=20for=20GitHub=20ac?= =?UTF-8?q?count=20and=20app=20connections?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Auth2.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Auth2.Tests.ps1 b/tests/Auth2.Tests.ps1 index 2462bad8a..1b41e6446 100644 --- a/tests/Auth2.Tests.ps1 +++ b/tests/Auth2.Tests.ps1 @@ -16,12 +16,12 @@ Describe 'Auth' { Context 'As using on ' -ForEach $authCases { It 'Connect-GitHubAccount - Connects using the provided credentials' { - $context = Connect-GitHubAccount @connectParams -PassThru + $context = Connect-GitHubAccount @connectParams -PassThru -Silent $context | Should -Not -BeNullOrEmpty } if ($AuthType -eq 'APP') { It 'Connect-GitHubApp - Connects as a GitHub App to ' { - $context = Connect-GitHubApp @connectAppParams -PassThru -Default + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent $context | Should -Not -BeNullOrEmpty } } @@ -35,7 +35,7 @@ Describe 'Auth' { } It 'Disconnect-GitHubAccount - Disconnects all contexts' { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent (Get-GitHubContext -ListAvailable).count | Should -Be 0 } } From 6907b56d47bc8bb759b111bd2f8eea978bb01d06 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 17:48:11 +0100 Subject: [PATCH 11/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20Discon?= =?UTF-8?q?nect-GitHubAccount=20test=20to=20suppress=20warnings=20during?= =?UTF-8?q?=20disconnection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Auth2.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Auth2.Tests.ps1 b/tests/Auth2.Tests.ps1 index 1b41e6446..2cf745f3b 100644 --- a/tests/Auth2.Tests.ps1 +++ b/tests/Auth2.Tests.ps1 @@ -35,7 +35,7 @@ Describe 'Auth' { } It 'Disconnect-GitHubAccount - Disconnects all contexts' { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent -WarningAction SilentlyContinue (Get-GitHubContext -ListAvailable).count | Should -Be 0 } } From 8d0c719aaccfa6c5dfc56a2c4a340a081bed6c9a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 17:57:00 +0100 Subject: [PATCH 12/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20auth?= =?UTF-8?q?entication=20tests=20to=20remove=20redundant=20contexts=20and?= =?UTF-8?q?=20enhance=20logging=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Auth.Tests.ps1 | 47 ------------------------------------------- tests/Auth2.Tests.ps1 | 14 +++++++++++++ 2 files changed, 14 insertions(+), 47 deletions(-) diff --git a/tests/Auth.Tests.ps1 b/tests/Auth.Tests.ps1 index 2a3f34c02..2f157d10c 100644 --- a/tests/Auth.Tests.ps1 +++ b/tests/Auth.Tests.ps1 @@ -134,53 +134,6 @@ Describe 'Auth' { } } - Context 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - It 'Get-GitHubViewer - Gets the logged in context (USER_FG_PAT)' { - Get-GitHubViewer | Should -Not -BeNullOrEmpty - } - } - - Context 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - It 'Get-GitHubViewer - Gets the logged in context (ORG_FG_PAT)' { - Get-GitHubViewer | Should -Not -BeNullOrEmpty - } - } - - Context 'As a user - Classic PAT token (PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - It 'Get-GitHubViewer - Gets the logged in context (PAT)' { - Get-GitHubViewer | Should -Not -BeNullOrEmpty - } - } - - Context 'As GitHub Actions (GHA)' { - BeforeAll { - Connect-GitHubAccount - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - It 'Get-GitHubViewer - Gets the logged in context (GHA)' { - Get-GitHubViewer | Should -Not -BeNullOrEmpty - } - } Context 'As a GitHub App - Enterprise (APP_ENT)' { BeforeAll { diff --git a/tests/Auth2.Tests.ps1 b/tests/Auth2.Tests.ps1 index 2cf745f3b..ad5903d9b 100644 --- a/tests/Auth2.Tests.ps1 +++ b/tests/Auth2.Tests.ps1 @@ -17,13 +17,27 @@ Describe 'Auth' { Context 'As using on ' -ForEach $authCases { It 'Connect-GitHubAccount - Connects using the provided credentials' { $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } $context | Should -Not -BeNullOrEmpty } if ($AuthType -eq 'APP') { It 'Connect-GitHubApp - Connects as a GitHub App to ' { $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } $context | Should -Not -BeNullOrEmpty } + + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $contexts = Connect-GitHubApp @connectAppParams -PassThru -Silent + LogGroup 'Contexts' { + Write-Host ($contexts | Format-List | Out-String) + } + $contexts | Should -Not -BeNullOrEmpty + } } It 'Get-GitHubViewer - Gets the logged in context' { From 36e9736114e37f27e7a40a1f04c5730490f672da Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 18:02:59 +0100 Subject: [PATCH 13/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20Conn?= =?UTF-8?q?ect-GitHubApp=20test=20to=20improve=20context=20handling=20and?= =?UTF-8?q?=20logging=20structure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Auth2.Tests.ps1 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/Auth2.Tests.ps1 b/tests/Auth2.Tests.ps1 index ad5903d9b..34ea68cdd 100644 --- a/tests/Auth2.Tests.ps1 +++ b/tests/Auth2.Tests.ps1 @@ -23,14 +23,6 @@ Describe 'Auth' { $context | Should -Not -BeNullOrEmpty } if ($AuthType -eq 'APP') { - It 'Connect-GitHubApp - Connects as a GitHub App to ' { - $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - $context | Should -Not -BeNullOrEmpty - } - It 'Connect-GitHubApp - Connects as a GitHub App to ' { $contexts = Connect-GitHubApp @connectAppParams -PassThru -Silent LogGroup 'Contexts' { @@ -38,6 +30,14 @@ Describe 'Auth' { } $contexts | Should -Not -BeNullOrEmpty } + + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + $context | Should -Not -BeNullOrEmpty + } } It 'Get-GitHubViewer - Gets the logged in context' { From 16e612da030ea586ef0fd9d2da02916897ee9961 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 18:22:01 +0100 Subject: [PATCH 14/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Suppress=20Writ?= =?UTF-8?q?e-Host=20warnings=20in=20test=20files=20to=20improve=20logging?= =?UTF-8?q?=20for=20GitHub=20Actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/API.Tests.ps1 | 4 ++++ tests/Apps.Tests.ps1 | 4 ++++ tests/Auth.Tests.ps1 | 4 ++++ tests/Auth2.Tests.ps1 | 4 ++++ tests/Emojis.Tests.ps1 | 4 ++++ tests/Environments.Tests.ps1 | 4 ++++ tests/GitHub.Tests.ps1 | 4 ++++ tests/Organization.Tests.ps1 | 4 ++++ tests/Repositories.Tests.ps1 | 4 ++++ tests/TEMPLATE.ps1 | 4 ++++ tests/User.Tests.ps1 | 4 ++++ 11 files changed, 44 insertions(+) diff --git a/tests/API.Tests.ps1 b/tests/API.Tests.ps1 index 94975fd05..2fa51c1df 100644 --- a/tests/API.Tests.ps1 +++ b/tests/API.Tests.ps1 @@ -8,6 +8,10 @@ 'PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'Used to create a secure string for testing.' )] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', + Justification = 'Log outputs to GitHub Actions logs.' +)] [CmdletBinding()] param() diff --git a/tests/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 index 14c975ff7..7b6735e7b 100644 --- a/tests/Apps.Tests.ps1 +++ b/tests/Apps.Tests.ps1 @@ -8,6 +8,10 @@ 'PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'Used to create a secure string for testing.' )] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', + Justification = 'Log outputs to GitHub Actions logs.' +)] [CmdletBinding()] param() diff --git a/tests/Auth.Tests.ps1 b/tests/Auth.Tests.ps1 index 2f157d10c..c9c7a0cfc 100644 --- a/tests/Auth.Tests.ps1 +++ b/tests/Auth.Tests.ps1 @@ -8,6 +8,10 @@ 'PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'Used to create a secure string for testing.' )] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', + Justification = 'Log outputs to GitHub Actions logs.' +)] [CmdletBinding()] param() diff --git a/tests/Auth2.Tests.ps1 b/tests/Auth2.Tests.ps1 index 34ea68cdd..301f2dee1 100644 --- a/tests/Auth2.Tests.ps1 +++ b/tests/Auth2.Tests.ps1 @@ -8,6 +8,10 @@ 'PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'Used to create a secure string for testing.' )] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', + Justification = 'Log outputs to GitHub Actions logs.' +)] [CmdletBinding()] param() diff --git a/tests/Emojis.Tests.ps1 b/tests/Emojis.Tests.ps1 index 65515443e..a3ff81fa7 100644 --- a/tests/Emojis.Tests.ps1 +++ b/tests/Emojis.Tests.ps1 @@ -8,6 +8,10 @@ 'PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'Used to create a secure string for testing.' )] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', + Justification = 'Log outputs to GitHub Actions logs.' +)] [CmdletBinding()] param() diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 index b816021fb..6c628b108 100644 --- a/tests/Environments.Tests.ps1 +++ b/tests/Environments.Tests.ps1 @@ -8,6 +8,10 @@ 'PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'Used to create a secure string for testing.' )] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', + Justification = 'Log outputs to GitHub Actions logs.' +)] [CmdletBinding()] param() diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index 810ab6b2f..4391ea3ec 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -8,6 +8,10 @@ 'PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'Used to create a secure string for testing.' )] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', + Justification = 'Log outputs to GitHub Actions logs.' +)] [CmdletBinding()] param() diff --git a/tests/Organization.Tests.ps1 b/tests/Organization.Tests.ps1 index 0d0a9abde..7270407f4 100644 --- a/tests/Organization.Tests.ps1 +++ b/tests/Organization.Tests.ps1 @@ -8,6 +8,10 @@ 'PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'Used to create a secure string for testing.' )] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', + Justification = 'Log outputs to GitHub Actions logs.' +)] [CmdletBinding()] param() diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 5ee35e843..9776e8fc1 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -8,6 +8,10 @@ 'PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'Used to create a secure string for testing.' )] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', + Justification = 'Log outputs to GitHub Actions logs.' +)] [CmdletBinding()] param() diff --git a/tests/TEMPLATE.ps1 b/tests/TEMPLATE.ps1 index f9d18a136..69ef37347 100644 --- a/tests/TEMPLATE.ps1 +++ b/tests/TEMPLATE.ps1 @@ -8,6 +8,10 @@ 'PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'Used to create a secure string for testing.' )] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', + Justification = 'Log outputs to GitHub Actions logs.' +)] [CmdletBinding()] param() diff --git a/tests/User.Tests.ps1 b/tests/User.Tests.ps1 index c0fac21c8..0e92b0637 100644 --- a/tests/User.Tests.ps1 +++ b/tests/User.Tests.ps1 @@ -8,6 +8,10 @@ 'PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'Used to create a secure string for testing.' )] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', + Justification = 'Log outputs to GitHub Actions logs.' +)] [CmdletBinding()] param() From 83679eb0a2665a788894c713b1ebeb9f0b59752d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 18:30:16 +0100 Subject: [PATCH 15/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Simplify=20Conn?= =?UTF-8?q?ect-GitHubApp=20invocation=20in=20authentication=20tests=20by?= =?UTF-8?q?=20removing=20redundant=20parameters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Auth2.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Auth2.Tests.ps1 b/tests/Auth2.Tests.ps1 index 301f2dee1..457dba328 100644 --- a/tests/Auth2.Tests.ps1 +++ b/tests/Auth2.Tests.ps1 @@ -28,7 +28,7 @@ Describe 'Auth' { } if ($AuthType -eq 'APP') { It 'Connect-GitHubApp - Connects as a GitHub App to ' { - $contexts = Connect-GitHubApp @connectAppParams -PassThru -Silent + $contexts = Connect-GitHubApp -PassThru -Silent LogGroup 'Contexts' { Write-Host ($contexts | Format-List | Out-String) } From 244cb7276cd5f54f9abd9ca39d1990672f4ecbf4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 18:55:33 +0100 Subject: [PATCH 16/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20auth?= =?UTF-8?q?entication=20tests=20to=20enhance=20context=20handling=20and=20?= =?UTF-8?q?add=20new=20connection=20tests=20for=20GitHub=20App?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Auth.Tests.ps1 | 47 ------------------------------------------- tests/Auth2.Tests.ps1 | 22 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 47 deletions(-) diff --git a/tests/Auth.Tests.ps1 b/tests/Auth.Tests.ps1 index c9c7a0cfc..92a267443 100644 --- a/tests/Auth.Tests.ps1 +++ b/tests/Auth.Tests.ps1 @@ -137,51 +137,4 @@ Describe 'Auth' { Get-GitHubContext -ListAvailable | Should -HaveCount 0 } } - - - Context 'As a GitHub App - Enterprise (APP_ENT)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - It 'Connect-GitHubApp - Connects one enterprise installation for the authenticated GitHub App (APP_ENT)' { - $context = Get-GitHubContext - { Connect-GitHubApp -Enterprise msx -Context $context } | Should -Not -Throw - Get-GitHubContext -ListAvailable | Should -HaveCount 2 - } - It 'Connect-GitHubApp - Connects one organization installation for the authenticated GitHub App (APP_ENT)' { - $context = Connect-GitHubApp -Organization 'psmodule-test-org3' -PassThru - $context.Name | Should -BeLike '*/Organization/psmodule-test-org3' - Get-GitHubContext -ListAvailable | Should -HaveCount 3 - } - It 'Connect-GitHubApp - Connects all installations for the authenticated GitHub App (APP_ENT)' { - { Connect-GitHubApp } | Should -Not -Throw - Get-GitHubContext -ListAvailable | Should -HaveCount 3 - } - } - - Context 'As a GitHub App - Organization (APP_ORG)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - It 'Connect-GitHubApp - Connects one user installation for the authenticated GitHub App (APP_ORG)' { - $context = Get-GitHubContext - { Connect-GitHubApp -User 'psmodule-user' -Context $context } | Should -Not -Throw - Get-GitHubContext -ListAvailable | Should -HaveCount 2 - } - It 'Connect-GitHubApp - Connects one organization installation for the authenticated GitHub App (APP_ORG)' { - $context = Connect-GitHubApp -Organization psmodule-test-org -PassThru - $context.Name | Should -BeLike '*/Organization/psmodule-test-org' - Get-GitHubContext -ListAvailable | Should -HaveCount 3 - } - It 'Connect-GitHubApp - Connects all installations for the authenticated GitHub App (APP_ORG)' { - { Connect-GitHubApp } | Should -Not -Throw - Get-GitHubContext -ListAvailable | Should -HaveCount 3 - } - } } diff --git a/tests/Auth2.Tests.ps1 b/tests/Auth2.Tests.ps1 index 457dba328..2673673ba 100644 --- a/tests/Auth2.Tests.ps1 +++ b/tests/Auth2.Tests.ps1 @@ -27,6 +27,13 @@ Describe 'Auth' { $context | Should -Not -BeNullOrEmpty } if ($AuthType -eq 'APP') { + It 'Connect-GitHubAccount - Connects using the provided credentials' { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent -AutoloadInstallations + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + $context | Should -Not -BeNullOrEmpty + } It 'Connect-GitHubApp - Connects as a GitHub App to ' { $contexts = Connect-GitHubApp -PassThru -Silent LogGroup 'Contexts' { @@ -52,6 +59,21 @@ Describe 'Auth' { $viewer | Should -Not -BeNullOrEmpty } + It 'GetGitHubContext - Gets the default context' { + $context = Get-GitHubContext + LogGroup 'Default context' { + Write-Host ($viewer | Format-List | Out-String) + } + } + + It 'GetGitHubContext - List all contexts' { + $contexts = Get-GitHubContext -ListAvailable + LogGroup 'Contexts' { + Write-Host ($contexts | Format-List | Out-String) + } + $contexts.count | Should -BeGreaterThan 2 + } + It 'Disconnect-GitHubAccount - Disconnects all contexts' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent -WarningAction SilentlyContinue (Get-GitHubContext -ListAvailable).count | Should -Be 0 From fea5849b6d9b12f8c2b3fcadb9c62f79dcba308d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 19:09:05 +0100 Subject: [PATCH 17/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20obsole?= =?UTF-8?q?te=20Auth2.Tests.ps1=20file=20to=20streamline=20test=20suite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Auth.Tests.ps1 | 167 ++++++++++++++++-------------------------- tests/Auth2.Tests.ps1 | 82 --------------------- 2 files changed, 64 insertions(+), 185 deletions(-) delete mode 100644 tests/Auth2.Tests.ps1 diff --git a/tests/Auth.Tests.ps1 b/tests/Auth.Tests.ps1 index 92a267443..1aa232129 100644 --- a/tests/Auth.Tests.ps1 +++ b/tests/Auth.Tests.ps1 @@ -16,125 +16,86 @@ param() Describe 'Auth' { - Context 'Auth' { - It 'Connect-GitHubAccount - Connects GitHub Actions without parameters' { - { Connect-GitHubAccount } | Should -Not -Throw - [string]::IsNullOrEmpty($(gh auth token)) | Should -Be $false - } - It 'Disconnect-GitHubAccount - Disconnects GitHub Actions' { - { Disconnect-GitHubAccount } | Should -Not -Throw - } - It 'Connect-GitHubAccount - Passes the context to the pipeline' { - $context = Connect-GitHubAccount -PassThru - Write-Verbose (Get-GitHubContext | Out-String) -Verbose + $authCases = . "$PSScriptRoot/AuthCases.ps1" + + Context 'As using on ' -ForEach $authCases { + It 'Connect-GitHubAccount - Connects using the provided credentials' { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } $context | Should -Not -BeNullOrEmpty } - It 'Connect-GitHubAccount - Connects with default settings' { - $context = Get-GitHubContext - Write-Verbose ($context | Select-Object -Property * | Out-String) -Verbose + It 'Connect-GitHubAccount - Connects using the provided credentials - Double' { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } $context | Should -Not -BeNullOrEmpty - $context.ApiBaseUri | Should -Be 'https://api.github.com' - $context.ApiVersion | Should -Be '2022-11-28' - $context.AuthType | Should -Be 'IAT' - $context.HostName | Should -Be 'github.com' - $context.HttpVersion | Should -Be '2.0' - $context.TokenType | Should -Be 'ghs' - $context.Name | Should -Be 'github.com/github-actions/Organization/PSModule' } - It 'Disconnect-GitHubAccount - Disconnects the context from the pipeline' { - $context = Get-GitHubContext - { $context | Disconnect-GitHubAccount } | Should -Not -Throw - } - It 'Connect-GitHubAccount - Connects GitHub Actions even if called multiple times' { - { Connect-GitHubAccount } | Should -Not -Throw - { Connect-GitHubAccount } | Should -Not -Throw - } - It 'Connect-GitHubAccount - Connects multiple contexts, GitHub Actions and a user via classic PAT token' { - { Connect-GitHubAccount -Token $env:TEST_USER_PAT } | Should -Not -Throw - { Connect-GitHubAccount -Token $env:TEST_USER_PAT } | Should -Not -Throw - { Connect-GitHubAccount } | Should -Not -Throw - (Get-GitHubContext -ListAvailable).Count | Should -Be 2 - Get-GitHubConfig -Name 'DefaultContext' | Should -Be 'github.com/github-actions/Organization/PSModule' - Write-Verbose (Get-GitHubContext | Out-String) -Verbose - } - It 'Connect-GitHubAccount - Reconfigures an existing user context to be a fine-grained PAT token' { - { Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT } | Should -Not -Throw - (Get-GitHubContext -ListAvailable).Count | Should -Be 2 - Write-Verbose (Get-GitHubContext -ListAvailable | Out-String) -Verbose - } - It 'Connect-GitHubAccount - Connects a GitHub App from an organization' { - $params = @{ - ClientID = $env:TEST_APP_ORG_CLIENT_ID - PrivateKey = $env:TEST_APP_ORG_PRIVATE_KEY + It 'Connect-GitHubAccount - Connects using the provided credentials - Relog' { + Disconnect-GitHub -Silent + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) } - { Connect-GitHubAccount @params } | Should -Not -Throw - $contexts = Get-GitHubContext -ListAvailable -Verbose:$false - Write-Verbose ($contexts | Out-String) -Verbose - ($contexts).Count | Should -Be 3 + $context | Should -Not -BeNullOrEmpty } - It 'Connect-GitHubAccount - Connects all of a (org) GitHub Apps installations' { - $params = @{ - ClientID = $env:TEST_APP_ORG_CLIENT_ID - PrivateKey = $env:TEST_APP_ORG_PRIVATE_KEY + if ($AuthType -eq 'APP') { + It 'Connect-GitHubAccount - Connects using the provided credentials + AutoloadInstallations' { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent -AutoloadInstallations + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + $context | Should -Not -BeNullOrEmpty } - { Connect-GitHubAccount @params -AutoloadInstallations } | Should -Not -Throw - $contexts = Get-GitHubContext -ListAvailable -Verbose:$false - Write-Verbose ($contexts | Out-String) -Verbose - ($contexts).Count | Should -Be 5 - } - It 'Connect-GitHubAccount - Connects a GitHub App from an enterprise' { - $params = @{ - ClientID = $env:TEST_APP_ENT_CLIENT_ID - PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $contexts = Connect-GitHubApp -PassThru -Silent + LogGroup 'Contexts' { + Write-Host ($contexts | Format-List | Out-String) + } + $contexts | Should -Not -BeNullOrEmpty } - { Connect-GitHubAccount @params } | Should -Not -Throw - $contexts = Get-GitHubContext -ListAvailable -Verbose:$false - Write-Verbose ($contexts | Out-String) -Verbose - ($contexts).Count | Should -Be 6 - } - It 'Connect-GitHubAccount - Connects all of a (ent) GitHub Apps installations' { - $params = @{ - ClientID = $env:TEST_APP_ENT_CLIENT_ID - PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY + + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + $context | Should -Not -BeNullOrEmpty } - { Connect-GitHubAccount @params -AutoloadInstallations } | Should -Not -Throw - $contexts = Get-GitHubContext -ListAvailable -Verbose:$false - Write-Verbose ($contexts | Out-String) -Verbose - ($contexts).Count | Should -Be 8 - } - It 'Disconnect-GitHubAccount - Disconnects a specific context' { - { Disconnect-GitHubAccount -Context 'github.com/psmodule-enterprise-app/Enterprise/msx' -Silent } | Should -Not -Throw - $contexts = Get-GitHubContext -Context 'github.com/psmodule-enterprise-app/*' -Verbose:$false - Write-Verbose ($contexts | Out-String) -Verbose - ($contexts).Count | Should -Be 1 } - } - Context 'DefaultContext' { - BeforeAll { - Connect-GitHub + + It 'Connect-GitHubAccount - Connects to GitHub CLI on runners' { + [string]::IsNullOrEmpty($(gh auth token)) | Should -Be $false } - It 'Set-GitHubDefaultContext - Can swap context to another' { - Write-Verbose (Get-GitHubContext -ListAvailable | Out-String) -Verbose - { Set-GitHubDefaultContext -Context 'github.com/github-actions/Organization/PSModule' } | Should -Not -Throw - Get-GitHubConfig -Name 'DefaultContext' | Should -Be 'github.com/github-actions/Organization/PSModule' + It 'Get-GitHubViewer - Gets the logged in context' { + $viewer = Get-GitHubViewer + LogGroup 'Viewer' { + Write-Host ($viewer | Format-List | Out-String) + } + $viewer | Should -Not -BeNullOrEmpty } - It 'Set-GitHubDefaultContext - Can swap context to another using pipeline - String' { - Write-Verbose (Get-GitHubContext -ListAvailable | Out-String) -Verbose - { 'github.com/psmodule-user' | Set-GitHubDefaultContext } | Should -Not -Throw - Get-GitHubConfig -Name 'DefaultContext' | Should -Be 'github.com/psmodule-user' + It 'GetGitHubContext - Gets the default context' { + $context = Get-GitHubContext + LogGroup 'Default context' { + Write-Host ($viewer | Format-List | Out-String) + } } - It 'Set-GitHubDefaultContext - Can swap context to another using pipeline - Context object' { - Write-Verbose (Get-GitHubContext -ListAvailable | Out-String) -Verbose - { Get-GitHubContext -Context 'github.com/psmodule-org-app' | Set-GitHubDefaultContext } | Should -Not -Throw - Get-GitHubConfig -Name 'DefaultContext' | Should -Be 'github.com/psmodule-org-app' + It 'GetGitHubContext - List all contexts' { + $contexts = Get-GitHubContext -ListAvailable + LogGroup 'Contexts' { + Write-Host ($contexts | Format-List | Out-String) + } + $contexts.count | Should -BeGreaterOrEqual 1 } - } - Context 'Disconnect' { - It 'Disconnect-GitHubAccount - Can disconnect all context through the pipeline' { - { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } | Should -Not -Throw - Get-GitHubContext -ListAvailable | Should -HaveCount 0 + + It 'Disconnect-GitHubAccount - Disconnects all contexts' { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent -WarningAction SilentlyContinue + (Get-GitHubContext -ListAvailable).count | Should -Be 0 } } } diff --git a/tests/Auth2.Tests.ps1 b/tests/Auth2.Tests.ps1 deleted file mode 100644 index 2673673ba..000000000 --- a/tests/Auth2.Tests.ps1 +++ /dev/null @@ -1,82 +0,0 @@ -#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' } - -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSUseDeclaredVarsMoreThanAssignments', '', - Justification = 'Pester grouping syntax: known issue.' -)] -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingConvertToSecureStringWithPlainText', '', - Justification = 'Used to create a secure string for testing.' -)] -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', - Justification = 'Log outputs to GitHub Actions logs.' -)] -[CmdletBinding()] -param() - -Describe 'Auth' { - $authCases = . "$PSScriptRoot/AuthCases.ps1" - - Context 'As using on ' -ForEach $authCases { - It 'Connect-GitHubAccount - Connects using the provided credentials' { - $context = Connect-GitHubAccount @connectParams -PassThru -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - $context | Should -Not -BeNullOrEmpty - } - if ($AuthType -eq 'APP') { - It 'Connect-GitHubAccount - Connects using the provided credentials' { - $context = Connect-GitHubAccount @connectParams -PassThru -Silent -AutoloadInstallations - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - $context | Should -Not -BeNullOrEmpty - } - It 'Connect-GitHubApp - Connects as a GitHub App to ' { - $contexts = Connect-GitHubApp -PassThru -Silent - LogGroup 'Contexts' { - Write-Host ($contexts | Format-List | Out-String) - } - $contexts | Should -Not -BeNullOrEmpty - } - - It 'Connect-GitHubApp - Connects as a GitHub App to ' { - $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - $context | Should -Not -BeNullOrEmpty - } - } - - It 'Get-GitHubViewer - Gets the logged in context' { - $viewer = Get-GitHubViewer - LogGroup 'Viewer' { - Write-Host ($viewer | Format-List | Out-String) - } - $viewer | Should -Not -BeNullOrEmpty - } - - It 'GetGitHubContext - Gets the default context' { - $context = Get-GitHubContext - LogGroup 'Default context' { - Write-Host ($viewer | Format-List | Out-String) - } - } - - It 'GetGitHubContext - List all contexts' { - $contexts = Get-GitHubContext -ListAvailable - LogGroup 'Contexts' { - Write-Host ($contexts | Format-List | Out-String) - } - $contexts.count | Should -BeGreaterThan 2 - } - - It 'Disconnect-GitHubAccount - Disconnects all contexts' { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent -WarningAction SilentlyContinue - (Get-GitHubContext -ListAvailable).count | Should -Be 0 - } - } -} From c0d308ebce3b07b6cfbfed085c66068cb9ba5085 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 19:25:46 +0100 Subject: [PATCH 18/60] =?UTF-8?q?=F0=9F=A9=B9=20[Feature]:=20Add=20Switch-?= =?UTF-8?q?GitHubContext=20function=20to=20set=20the=20default=20GitHub=20?= =?UTF-8?q?context=20and=20update=20tests=20accordingly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...tHubDefaultContext.ps1 => Switch-GitHubContext.ps1} | 5 +++-- tests/Auth.Tests.ps1 | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) rename src/functions/public/Auth/Context/{Set-GitHubDefaultContext.ps1 => Switch-GitHubContext.ps1} (87%) diff --git a/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 b/src/functions/public/Auth/Context/Switch-GitHubContext.ps1 similarity index 87% rename from src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 rename to src/functions/public/Auth/Context/Switch-GitHubContext.ps1 index a55946141..0f887eb0a 100644 --- a/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 +++ b/src/functions/public/Auth/Context/Switch-GitHubContext.ps1 @@ -1,4 +1,4 @@ -function Set-GitHubDefaultContext { +function Switch-GitHubContext { <# .SYNOPSIS Set the default context. @@ -7,8 +7,9 @@ Set the default context for the GitHub module. .EXAMPLE - Set-GitHubDefaultContext -Context 'github.com/Octocat' + Switch-GitHubContext -Context 'github.com/Octocat' #> + [Alias('Set-GitHubDefaultContext')] [CmdletBinding(SupportsShouldProcess)] param( # The context to run the command in. Used to get the details for the API call. diff --git a/tests/Auth.Tests.ps1 b/tests/Auth.Tests.ps1 index 1aa232129..9511550dc 100644 --- a/tests/Auth.Tests.ps1 +++ b/tests/Auth.Tests.ps1 @@ -26,6 +26,7 @@ Describe 'Auth' { } $context | Should -Not -BeNullOrEmpty } + It 'Connect-GitHubAccount - Connects using the provided credentials - Double' { $context = Connect-GitHubAccount @connectParams -PassThru -Silent $context = Connect-GitHubAccount @connectParams -PassThru -Silent @@ -34,6 +35,7 @@ Describe 'Auth' { } $context | Should -Not -BeNullOrEmpty } + It 'Connect-GitHubAccount - Connects using the provided credentials - Relog' { Disconnect-GitHub -Silent $context = Connect-GitHubAccount @connectParams -PassThru -Silent @@ -42,6 +44,14 @@ Describe 'Auth' { } $context | Should -Not -BeNullOrEmpty } + + It 'Switch-GitHubContext - Sets the default context' { + $context = Get-GitHubContext + Switch-GitHubContext -Context $context + $context = Get-GitHubContext + $context | Should -Not -BeNullOrEmpty + } + if ($AuthType -eq 'APP') { It 'Connect-GitHubAccount - Connects using the provided credentials + AutoloadInstallations' { $context = Connect-GitHubAccount @connectParams -PassThru -Silent -AutoloadInstallations From 764cece33183df01fd32a055e6ff0a9b67679758 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 19:32:38 +0100 Subject: [PATCH 19/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20Connec?= =?UTF-8?q?t-GitHubApp=20invocation=20to=20include=20Silent=20parameter=20?= =?UTF-8?q?and=20enhance=20test=20coverage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Auth/Connect-GitHubAccount.ps1 | 2 +- tests/Auth.Tests.ps1 | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index 738944c73..5c478a5f0 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -309,7 +309,7 @@ if ($authType -eq 'App' -and $AutoloadInstallations) { Write-Verbose 'Loading GitHub App Installation contexts...' - Connect-GitHubApp + Connect-GitHubApp -Silent:$Silent } } catch { diff --git a/tests/Auth.Tests.ps1 b/tests/Auth.Tests.ps1 index 9511550dc..f4bf0fc6d 100644 --- a/tests/Auth.Tests.ps1 +++ b/tests/Auth.Tests.ps1 @@ -60,6 +60,7 @@ Describe 'Auth' { } $context | Should -Not -BeNullOrEmpty } + It 'Connect-GitHubApp - Connects as a GitHub App to ' { $contexts = Connect-GitHubApp -PassThru -Silent LogGroup 'Contexts' { From ae8a13a28dc70964b56221074fff48ba98eb6baa Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 19:39:26 +0100 Subject: [PATCH 20/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20unnece?= =?UTF-8?q?ssary=20blank=20line=20in=20Auth.Tests.ps1=20to=20improve=20cod?= =?UTF-8?q?e=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Auth.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Auth.Tests.ps1 b/tests/Auth.Tests.ps1 index f4bf0fc6d..3fad9e276 100644 --- a/tests/Auth.Tests.ps1 +++ b/tests/Auth.Tests.ps1 @@ -60,7 +60,7 @@ Describe 'Auth' { } $context | Should -Not -BeNullOrEmpty } - + It 'Connect-GitHubApp - Connects as a GitHub App to ' { $contexts = Connect-GitHubApp -PassThru -Silent LogGroup 'Contexts' { From 8ce8afead6aa72abdd76e4f52427d2e6d68cdad5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 20:04:24 +0100 Subject: [PATCH 21/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20Discon?= =?UTF-8?q?nect-GitHubAccount=20to=20conditionally=20display=20warnings=20?= =?UTF-8?q?based=20on=20Silent=20parameter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Auth/Disconnect-GitHubAccount.ps1 | 6 ++++-- tests/Auth.Tests.ps1 | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 index 7a67f2c43..566609deb 100644 --- a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 @@ -47,8 +47,10 @@ $isDefaultContext = $contextItem.Name -eq $script:GitHub.Config.DefaultContext if ($isDefaultContext) { Remove-GitHubConfig -Name 'DefaultContext' - Write-Warning 'There is no longer a default context!' - Write-Warning "Please set a new default context using 'Set-GitHubDefaultContext -Name '" + if (-not $Silent) { + Write-Warning 'There is no longer a default context!' + Write-Warning "Please set a new default context using 'Set-GitHubDefaultContext -Name '" + } } if (-not $Silent) { diff --git a/tests/Auth.Tests.ps1 b/tests/Auth.Tests.ps1 index 3fad9e276..c0af40f33 100644 --- a/tests/Auth.Tests.ps1 +++ b/tests/Auth.Tests.ps1 @@ -105,7 +105,7 @@ Describe 'Auth' { } It 'Disconnect-GitHubAccount - Disconnects all contexts' { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent -WarningAction SilentlyContinue + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent (Get-GitHubContext -ListAvailable).count | Should -Be 0 } } From 3bacabbb942edf55952ab3d59b767596059b56ec Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 21:58:05 +0100 Subject: [PATCH 22/60] =?UTF-8?q?=F0=9F=A9=B9=20[Refactor]:=20Move=20AuthC?= =?UTF-8?q?ases=20to=20Data=20directory=20and=20update=20test=20scripts=20?= =?UTF-8?q?for=20improved=20organization=20and=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/API.Tests.ps1 | 592 +++++++++++---------------------- tests/Auth.Tests.ps1 | 11 +- tests/{ => Data}/AuthCases.ps1 | 1 + tests/TEMPLATE.ps1 | 96 ++---- 4 files changed, 238 insertions(+), 462 deletions(-) rename tests/{ => Data}/AuthCases.ps1 (98%) diff --git a/tests/API.Tests.ps1 b/tests/API.Tests.ps1 index 2fa51c1df..8a483c372 100644 --- a/tests/API.Tests.ps1 +++ b/tests/API.Tests.ps1 @@ -15,411 +15,225 @@ [CmdletBinding()] param() -Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'API' { - It 'Invoke-GitHubAPI - Gets the rate limits directly (USER_FG_PAT)' { - { - $rateLimit = Invoke-GitHubAPI -ApiEndpoint '/rate_limit' - Write-Verbose ($rateLimit | Format-Table | Out-String) -Verbose - } | Should -Not -Throw - } - } - Context 'GraphQL' { - It 'Invoke-GitHubGraphQLQuery - Gets the viewer directly (USER_FG_PAT)' { - { - $viewer = Invoke-GitHubGraphQLQuery -Query 'query { viewer { login } }' - Write-Verbose ($viewer | Format-Table | Out-String) -Verbose - } | Should -Not -Throw - } - } - Context 'Meta' { - It 'Get-GitHubRoot - Gets the GitHub API Root (USER_FG_PAT)' { - $root = Get-GitHubRoot - Write-Verbose ($root | Format-Table | Out-String) -Verbose - $root | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubApiVersion - Gets all API versions (USER_FG_PAT)' { - $apiVersion = Get-GitHubApiVersion - Write-Verbose ($apiVersion | Format-Table | Out-String) -Verbose - $apiVersion | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubMeta - Gets GitHub meta information (USER_FG_PAT)' { - $meta = Get-GitHubMeta - Write-Verbose ($meta | Format-Table | Out-String) -Verbose - $meta | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubOctocat - Gets the Octocat (USER_FG_PAT)' { - $octocat = Get-GitHubOctocat - Write-Verbose ($octocat | Format-Table | Out-String) -Verbose - $octocat | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubZen - Gets the Zen of GitHub (USER_FG_PAT)' { - $zen = Get-GitHubZen - Write-Verbose ($zen | Format-Table | Out-String) -Verbose - $zen | Should -Not -BeNullOrEmpty - } - } - Context 'Rate-Limit' { - It 'Get-GitHubRateLimit - Gets the rate limit status for the authenticated user (USER_FG_PAT)' { - { Get-GitHubRateLimit } | Should -Not -Throw - } - } - Context 'License' { - It 'Get-GitHubLicense - Gets a list of all popular license templates (USER_FG_PAT)' { - { Get-GitHubLicense } | Should -Not -Throw - } - It 'Get-GitHubLicense - Gets a spesific license (USER_FG_PAT)' { - { Get-GitHubLicense -Name 'mit' } | Should -Not -Throw - } - It 'Get-GitHubLicense - Gets a license from a repository (USER_FG_PAT)' { - { Get-GitHubLicense -Owner 'PSModule' -Repository 'GitHub' } | Should -Not -Throw - } - } - Context 'GitIgnore' { - It 'Get-GitHubGitignore - Gets a list of all gitignore templates names (USER_FG_PAT)' { - { Get-GitHubGitignore } | Should -Not -Throw - } - It 'Get-GitHubGitignore - Gets a gitignore template (USER_FG_PAT)' { - { Get-GitHubGitignore -Name 'VisualStudio' } | Should -Not -Throw - } - } - Context 'Markdown' { - It 'Get-GitHubMarkdown - Gets the rendered markdown for provided text (USER_FG_PAT)' { - { Get-GitHubMarkdown -Text 'Hello, World!' } | Should -Not -Throw - } - It 'Get-GitHubMarkdown - Gets the rendered markdown for provided text using GitHub Formated Markdown (USER_FG_PAT)' { - { Get-GitHubMarkdown -Text 'Hello, World!' -Mode gfm } | Should -Not -Throw - } - It 'Get-GitHubMarkdownRaw - Gets the raw rendered markdown for provided text (USER_FG_PAT)' { - { Get-GitHubMarkdownRaw -Text 'Hello, World!' } | Should -Not -Throw - } - } +BeforeAll { + # DEFAULTS ACCROSS ALL TESTS } -Describe 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'API' { - It 'Invoke-GitHubAPI - Gets the rate limits directly (ORG_FG_PAT)' { - { - $rateLimit = Invoke-GitHubAPI -ApiEndpoint '/rate_limit' - Write-Verbose ($rateLimit | Format-Table | Out-String) -Verbose - } | Should -Not -Throw - } - } - Context 'GraphQL' { - It 'Invoke-GitHubGraphQLQuery - Gets the viewer directly (ORG_FG_PAT)' { - { - $viewer = Invoke-GitHubGraphQLQuery -Query 'query { viewer { login } }' - Write-Verbose ($viewer | Format-Table | Out-String) -Verbose - } | Should -Not -Throw - } - } - Context 'Meta' { - It 'Get-GitHubRoot - Gets the GitHub API Root (ORG_FG_PAT)' { - $root = Get-GitHubRoot - Write-Verbose ($root | Format-Table | Out-String) -Verbose - $root | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubApiVersion - Gets all API versions (ORG_FG_PAT)' { - $apiVersion = Get-GitHubApiVersion - Write-Verbose ($apiVersion | Format-Table | Out-String) -Verbose - $apiVersion | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubMeta - Gets GitHub meta information (ORG_FG_PAT)' { - $meta = Get-GitHubMeta - Write-Verbose ($meta | Format-Table | Out-String) -Verbose - $meta | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubOctocat - Gets the Octocat (ORG_FG_PAT)' { - $octocat = Get-GitHubOctocat - Write-Verbose ($octocat | Format-Table | Out-String) -Verbose - $octocat | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubZen - Gets the Zen of GitHub (ORG_FG_PAT)' { - $zen = Get-GitHubZen - Write-Verbose ($zen | Format-Table | Out-String) -Verbose - $zen | Should -Not -BeNullOrEmpty - } - } - Context 'Rate-Limit' { - It 'Get-GitHubRateLimit - Gets the rate limit status for the authenticated user (ORG_FG_PAT)' { - { Get-GitHubRateLimit } | Should -Not -Throw - } - } - Context 'License' { - It 'Get-GitHubLicense - Gets a list of all popular license templates (ORG_FG_PAT)' { - { Get-GitHubLicense } | Should -Not -Throw - } - It 'Get-GitHubLicense - Gets a spesific license (ORG_FG_PAT)' { - { Get-GitHubLicense -Name 'mit' } | Should -Not -Throw - } - It 'Get-GitHubLicense - Gets a license from a repository (ORG_FG_PAT)' { - { Get-GitHubLicense -Owner 'PSModule' -Repository 'GitHub' } | Should -Not -Throw - } - } - Context 'GitIgnore' { - It 'Get-GitHubGitignore - Gets a list of all gitignore templates names (ORG_FG_PAT)' { - { Get-GitHubGitignore } | Should -Not -Throw - } - It 'Get-GitHubGitignore - Gets a gitignore template (ORG_FG_PAT)' { - { Get-GitHubGitignore -Name 'VisualStudio' } | Should -Not -Throw - } - } - Context 'Markdown' { - It 'Get-GitHubMarkdown - Gets the rendered markdown for provided text (ORG_FG_PAT)' { - { Get-GitHubMarkdown -Text 'Hello, World!' } | Should -Not -Throw - } - It 'Get-GitHubMarkdown - Gets the rendered markdown for provided text using GitHub Formated Markdown (ORG_FG_PAT)' { - { Get-GitHubMarkdown -Text 'Hello, World!' -Mode gfm } | Should -Not -Throw - } - It 'Get-GitHubMarkdownRaw - Gets the raw rendered markdown for provided text (ORG_FG_PAT)' { - { Get-GitHubMarkdownRaw -Text 'Hello, World!' } | Should -Not -Throw - } - } -} +Describe 'Template' { + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" -Describe 'As a user - Classic PAT token (PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'API' { - It 'Invoke-GitHubAPI - Gets the rate limits directly (PAT)' { - { - $rateLimit = Invoke-GitHubAPI -ApiEndpoint '/rate_limit' - Write-Verbose ($rateLimit | Format-Table | Out-String) -Verbose - } | Should -Not -Throw - } - } - Context 'GraphQL' { - It 'Invoke-GitHubGraphQLQuery - Gets the viewer directly (PAT)' { - { - $viewer = Invoke-GitHubGraphQLQuery -Query 'query { viewer { login } }' - Write-Verbose ($viewer | Format-Table | Out-String) -Verbose - } | Should -Not -Throw - } - } - Context 'Meta' { - It 'Get-GitHubRoot - Gets the GitHub API Root (PAT)' { - $root = Get-GitHubRoot - Write-Verbose ($root | Format-Table | Out-String) -Verbose - $root | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubApiVersion - Gets all API versions (PAT)' { - $apiVersion = Get-GitHubApiVersion - Write-Verbose ($apiVersion | Format-Table | Out-String) -Verbose - $apiVersion | Should -Not -BeNullOrEmpty + Context 'As using on ' -ForEach $authCases { + BeforeAll { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + $context | Should -Not -BeNullOrEmpty } - It 'Get-GitHubMeta - Gets GitHub meta information (PAT)' { - $meta = Get-GitHubMeta - Write-Verbose ($meta | Format-Table | Out-String) -Verbose - $meta | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubOctocat - Gets the Octocat (PAT)' { - $octocat = Get-GitHubOctocat - Write-Verbose ($octocat | Format-Table | Out-String) -Verbose - $octocat | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubZen - Gets the Zen of GitHub (PAT)' { - $zen = Get-GitHubZen - Write-Verbose ($zen | Format-Table | Out-String) -Verbose - $zen | Should -Not -BeNullOrEmpty - } - } - Context 'Rate-Limit' { - It 'Get-GitHubRateLimit - Gets the rate limit status for the authenticated user (PAT)' { - { Get-GitHubRateLimit } | Should -Not -Throw - } - } - Context 'License' { - It 'Get-GitHubLicense - Gets a list of all popular license templates (PAT)' { - { Get-GitHubLicense } | Should -Not -Throw - } - It 'Get-GitHubLicense - Gets a spesific license (PAT)' { - { Get-GitHubLicense -Name 'mit' } | Should -Not -Throw - } - It 'Get-GitHubLicense - Gets a license from a repository (PAT)' { - { Get-GitHubLicense -Owner 'PSModule' -Repository 'GitHub' } | Should -Not -Throw - } - } - Context 'GitIgnore' { - It 'Get-GitHubGitignore - Gets a list of all gitignore templates names (PAT)' { - { Get-GitHubGitignore } | Should -Not -Throw - } - It 'Get-GitHubGitignore - Gets a gitignore template (PAT)' { - { Get-GitHubGitignore -Name 'VisualStudio' } | Should -Not -Throw - } - } - Context 'Markdown' { - It 'Get-GitHubMarkdown - Gets the rendered markdown for provided text (PAT)' { - { Get-GitHubMarkdown -Text 'Hello, World!' } | Should -Not -Throw - } - It 'Get-GitHubMarkdown - Gets the rendered markdown for provided text using GitHub Formated Markdown (PAT)' { - { Get-GitHubMarkdown -Text 'Hello, World!' -Mode gfm } | Should -Not -Throw - } - It 'Get-GitHubMarkdownRaw - Gets the raw rendered markdown for provided text (PAT)' { - { Get-GitHubMarkdownRaw -Text 'Hello, World!' } | Should -Not -Throw - } - } -} -Describe 'As GitHub Actions (GHA)' { - BeforeAll { - Connect-GitHubAccount - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'API' { - It 'Invoke-GitHubAPI - Gets the rate limits directly (GHA)' { - { - $rateLimit = Invoke-GitHubAPI -ApiEndpoint '/rate_limit' - Write-Verbose ($rateLimit | Format-Table | Out-String) -Verbose - } | Should -Not -Throw - } - } - Context 'GraphQL' { - It 'Invoke-GitHubGraphQLQuery - Gets the viewer directly (GHA)' { - { - $viewer = Invoke-GitHubGraphQLQuery -Query 'query { viewer { login } }' - Write-Verbose ($viewer | Format-Table | Out-String) -Verbose - } | Should -Not -Throw - } - } - Context 'Git' { - It "Get-GitHubGitConfig gets the 'local' (default) Git configuration (GHA)" { - $gitConfig = Get-GitHubGitConfig - Write-Verbose ($gitConfig | Format-List | Out-String) -Verbose - $gitConfig | Should -Not -BeNullOrEmpty - } - It "Get-GitHubGitConfig gets the 'global' Git configuration (GHA)" { - git config --global advice.pushfetchfirst false - $gitConfig = Get-GitHubGitConfig -Scope 'global' - Write-Verbose ($gitConfig | Format-List | Out-String) -Verbose - $gitConfig | Should -Not -BeNullOrEmpty - } - It "Get-GitHubGitConfig gets the 'system' Git configuration (GHA)" { - $gitConfig = Get-GitHubGitConfig -Scope 'system' - Write-Verbose ($gitConfig | Format-List | Out-String) -Verbose - $gitConfig | Should -Not -BeNullOrEmpty - } - It 'Set-GitHubGitConfig sets the Git configuration (GHA)' { - { Set-GitHubGitConfig } | Should -Not -Throw - $gitConfig = Get-GitHubGitConfig -Scope 'global' - Write-Verbose ($gitConfig | Format-List | Out-String) -Verbose + # Tests for APP goes here + if ($AuthType -eq 'APP') { + It 'Invoke-GitHubAPI - Gets the app details' { + { + $app = Invoke-GitHubAPI -ApiEndpoint '/app' + LogGroup 'App' { + Write-Host ($app | Format-Table | Out-String) + } + } | Should -Not -Throw + } - $gitConfig | Should -Not -BeNullOrEmpty - $gitConfig.'user.name' | Should -Not -BeNullOrEmpty - $gitConfig.'user.email' | Should -Not -BeNullOrEmpty - } - } - Context 'Meta' { - It 'Get-GitHubRoot - Gets the GitHub API Root (GHA)' { - $root = Get-GitHubRoot - Write-Verbose ($root | Format-Table | Out-String) -Verbose - $root | Should -Not -BeNullOrEmpty + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + $context | Should -Not -BeNullOrEmpty + } } - It 'Get-GitHubApiVersion - Gets all API versions (GHA)' { - $apiVersion = Get-GitHubApiVersion - Write-Verbose ($apiVersion | Format-Table | Out-String) -Verbose - $apiVersion | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubMeta - Gets GitHub meta information (GHA)' { - $meta = Get-GitHubMeta - Write-Verbose ($meta | Format-Table | Out-String) -Verbose - $meta | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubOctocat - Gets the Octocat (GHA)' { - $octocat = Get-GitHubOctocat - Write-Verbose ($octocat | Format-Table | Out-String) -Verbose - $octocat | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubZen - Gets the Zen of GitHub (GHA)' { - $zen = Get-GitHubZen - Write-Verbose ($zen | Format-Table | Out-String) -Verbose - $zen | Should -Not -BeNullOrEmpty - } - } - Context 'Rate-Limit' { - It 'Get-GitHubRateLimit - Gets the rate limit status for the authenticated user (GHA)' { - { Get-GitHubRateLimit } | Should -Not -Throw - } - } - Context 'License' { - It 'Get-GitHubLicense - Gets a list of all popular license templates (GHA)' { - { Get-GitHubLicense } | Should -Not -Throw - } - It 'Get-GitHubLicense - Gets a spesific license (GHA)' { - { Get-GitHubLicense -Name 'mit' } | Should -Not -Throw - } - It 'Get-GitHubLicense - Gets a license from a repository (GHA)' { - { Get-GitHubLicense -Owner 'PSModule' -Repository 'GitHub' } | Should -Not -Throw + + # Tests for runners goes here + if ($Type -eq 'GitHub Actions') {} + + # Tests for IAT UAT and PAT goes here + Context 'API' { + It 'Invoke-GitHubAPI - Gets the rate limits directly using APIEndpoint' { + { + $rateLimit = Invoke-GitHubAPI -ApiEndpoint '/rate_limit' + LogGroup 'RateLimit' { + Write-Host ($rateLimit | Format-Table | Out-String) + } + } | Should -Not -Throw + } + + It 'Invoke-GitHubAPI - Gets the rate limits directly using Uri' { + { + $rateLimit = Invoke-GitHubAPI -Uri ($context.ApiBaseUri + '/rate_limit') + LogGroup 'RateLimit' { + Write-Host ($rateLimit | Format-Table | Out-String) + } + } | Should -Not -Throw + } + + It 'Invoke-GitHubGraphQLQuery - Gets the viewer' { + { + $viewer = Invoke-GitHubGraphQLQuery -Query 'query { viewer { login } }' + LogGroup 'Viewer' { + Write-Host ($viewer | Format-Table | Out-String) + } + } | Should -Not -Throw + } } - } - Context 'GitIgnore' { - It 'Get-GitHubGitignore - Gets a list of all gitignore templates names (GHA)' { - { Get-GitHubGitignore } | Should -Not -Throw + + Context 'Meta' { + It 'Get-GitHubRoot - Gets the GitHub API Root' { + $root = Get-GitHubRoot + LogGroup 'Root' { + Write-Host ($root | Format-Table | Out-String) + } + $root | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubApiVersion - Gets all API versions' { + $apiVersion = Get-GitHubApiVersion + LogGroup 'ApiVersion' { + Write-Host ($apiVersion | Format-Table | Out-String) + } + $apiVersion | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubMeta - Gets GitHub meta information' { + $meta = Get-GitHubMeta + LogGroup 'Meta' { + Write-Host ($meta | Format-Table | Out-String) + } + $meta | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubOctocat - Gets the Octocat' { + $octocat = Get-GitHubOctocat + LogGroup 'Octocat' { + Write-Host ($octocat | Format-Table | Out-String) + } + $octocat | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubZen - Gets the Zen of GitHub' { + $zen = Get-GitHubZen + LogGroup 'Zen' { + Write-Host ($zen | Format-Table | Out-String) + } + $zen | Should -Not -BeNullOrEmpty + } } - It 'Get-GitHubGitignore - Gets a gitignore template (GHA)' { - { Get-GitHubGitignore -Name 'VisualStudio' } | Should -Not -Throw + + Context 'Rate-Limit' { + It 'Get-GitHubRateLimit - Gets the rate limit status for the authenticated user' { + $rateLimit = Get-GitHubRateLimit + LogGroup 'RateLimit' { + Write-Host ($rateLimit | Format-Table | Out-String) + } + $rateLimit | Should -Not -BeNullOrEmpty + } } - } - Context 'Markdown' { - It 'Get-GitHubMarkdown - Gets the rendered markdown for provided text (GHA)' { - { Get-GitHubMarkdown -Text 'Hello, World!' } | Should -Not -Throw + + Context 'License' { + It 'Get-GitHubLicense - Gets a list of all popular license templates' { + $licenseList = Get-GitHubLicense + LogGroup 'Licenses' { + Write-Host ($licenseList | Format-Table | Out-String) + } + $licenseList | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubLicense - Gets a spesific license' { + $mitLicense = Get-GitHubLicense -Name 'mit' + LogGroup 'MIT License' { + Write-Host ($mitLicense | Format-Table | Out-String) + } + $mitLicense | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubLicense - Gets a license from a repository' { + $githubLicense = Get-GitHubLicense -Owner 'PSModule' -Repository 'GitHub' + LogGroup 'GitHub License' { + Write-Host ($githubLicense | Format-Table | Out-String) + } + $githubLicense | Should -Not -BeNullOrEmpty + } } - It 'Get-GitHubMarkdown - Gets the rendered markdown for provided text using GitHub Formated Markdown (GHA)' { - { Get-GitHubMarkdown -Text 'Hello, World!' -Mode gfm } | Should -Not -Throw + + Context 'GitIgnore' { + It 'Get-GitHubGitignore - Gets a list of all gitignore templates names' { + $gitIgnoreList = Get-GitHubGitignore + LogGroup 'GitIgnoreList' { + Write-Host ($gitIgnoreList | Format-Table | Out-String) + } + $gitIgnoreList | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubGitignore - Gets a gitignore template' { + $vsGitIgnore = Get-GitHubGitignore -Name 'VisualStudio' + LogGroup 'Visual Studio GitIgnore' { + Write-Host ($vsGitIgnore | Format-Table | Out-String) + } + $vsGitIgnore | Should -Not -BeNullOrEmpty + } } - It 'Get-GitHubMarkdownRaw - Gets the raw rendered markdown for provided text (GHA)' { - { Get-GitHubMarkdownRaw -Text 'Hello, World!' } | Should -Not -Throw + + Context 'Markdown' { + It 'Get-GitHubMarkdown - Gets the rendered markdown for provided text' { + $markdown = Get-GitHubMarkdown -Text 'Hello, World!' + LogGroup 'Markdown' { + Write-Host ($markdown | Format-Table | Out-String) + } + $markdown | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubMarkdown - Gets the rendered markdown for provided text using GitHub Formated Markdown' { + $gfmMarkdown = Get-GitHubMarkdown -Text 'Hello, World!' -Mode gfm + LogGroup 'GFM Markdown' { + Write-Host ($gfmMarkdown | Format-Table | Out-String) + } + $gfmMarkdown | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubMarkdownRaw - Gets the raw rendered markdown for provided text' { + $rawMarkdown = Get-GitHubMarkdownRaw -Text 'Hello, World!' + LogGroup 'Raw Markdown' { + Write-Host ($rawMarkdown | Format-Table | Out-String) + } + $rawMarkdown | Should -Not -BeNullOrEmpty + } } - } -} -Describe 'As a GitHub App - Enterprise (APP_ENT)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'API' { - It 'Can be called directly to get ratelimits (APP_ENT)' { - { - $app = Invoke-GitHubAPI -ApiEndpoint '/app' - Write-Verbose ($app | Format-Table | Out-String) -Verbose - } | Should -Not -Throw + Context 'Git' { + It "Get-GitHubGitConfig gets the 'local' (default) Git configuration" { + $gitConfig = Get-GitHubGitConfig + LogGroup 'GitConfig' { + Write-Host ($gitConfig | Format-List | Out-String) + } + $gitConfig | Should -Not -BeNullOrEmpty + } + It "Get-GitHubGitConfig gets the 'global' Git configuration" { + git config --global advice.pushfetchfirst false + $gitConfig = Get-GitHubGitConfig -Scope 'global' + LogGroup 'GitConfig - Global' { + Write-Host ($gitConfig | Format-List | Out-String) + } + $gitConfig | Should -Not -BeNullOrEmpty + } + It "Get-GitHubGitConfig gets the 'system' Git configuration" { + $gitConfig = Get-GitHubGitConfig -Scope 'system' + LogGroup 'GitConfig - System' { + Write-Host ($gitConfig | Format-List | Out-String) + } + $gitConfig | Should -Not -BeNullOrEmpty + } + It 'Set-GitHubGitConfig sets the Git configuration' { + { Set-GitHubGitConfig } | Should -Not -Throw + $gitConfig = Get-GitHubGitConfig -Scope 'global' + LogGroup 'GitConfig - Global' { + Write-Host ($gitConfig | Format-List | Out-String) + } + $gitConfig | Should -Not -BeNullOrEmpty + $gitConfig.'user.name' | Should -Not -BeNullOrEmpty + $gitConfig.'user.email' | Should -Not -BeNullOrEmpty + } } } } -Describe 'As a GitHub App - Organization (APP_ORG)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'API' { - It 'Can be called directly to get ratelimits (APP_ENT)' { - { - $app = Invoke-GitHubAPI -ApiEndpoint '/app' - Write-Verbose ($app | Format-Table | Out-String) -Verbose - } | Should -Not -Throw - } - } +AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } diff --git a/tests/Auth.Tests.ps1 b/tests/Auth.Tests.ps1 index c0af40f33..76af5b283 100644 --- a/tests/Auth.Tests.ps1 +++ b/tests/Auth.Tests.ps1 @@ -16,7 +16,7 @@ param() Describe 'Auth' { - $authCases = . "$PSScriptRoot/AuthCases.ps1" + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" Context 'As using on ' -ForEach $authCases { It 'Connect-GitHubAccount - Connects using the provided credentials' { @@ -52,6 +52,7 @@ Describe 'Auth' { $context | Should -Not -BeNullOrEmpty } + # Tests for APP goes here if ($AuthType -eq 'APP') { It 'Connect-GitHubAccount - Connects using the provided credentials + AutoloadInstallations' { $context = Connect-GitHubAccount @connectParams -PassThru -Silent -AutoloadInstallations @@ -78,6 +79,10 @@ Describe 'Auth' { } } + # Tests for runners goes here + if ($Type -eq 'GitHub Actions') {} + + # Tests for IAT UAT and PAT goes here It 'Connect-GitHubAccount - Connects to GitHub CLI on runners' { [string]::IsNullOrEmpty($(gh auth token)) | Should -Be $false } @@ -110,3 +115,7 @@ Describe 'Auth' { } } } + +AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent +} diff --git a/tests/AuthCases.ps1 b/tests/Data/AuthCases.ps1 similarity index 98% rename from tests/AuthCases.ps1 rename to tests/Data/AuthCases.ps1 index 6a445b94d..574ca9b0c 100644 --- a/tests/AuthCases.ps1 +++ b/tests/Data/AuthCases.ps1 @@ -35,6 +35,7 @@ Case = 'GITHUB_TOKEN' Target = 'this repository (GitHub)' Owner = 'PSModule' + Repo = 'GitHub' ConnectParams = @{ Token = $env:GITHUB_TOKEN } diff --git a/tests/TEMPLATE.ps1 b/tests/TEMPLATE.ps1 index 69ef37347..3df117a16 100644 --- a/tests/TEMPLATE.ps1 +++ b/tests/TEMPLATE.ps1 @@ -18,83 +18,35 @@ param() BeforeAll { # DEFAULTS ACCROSS ALL TESTS } -Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT - $owner = 'psmodule-user' - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'TEMPLATE' { - # TESTS HERE - } -} -Describe 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT - $owner = 'psmodule-test-org2' - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'TEMPLATE' { - # TESTS HERE - } -} +Describe 'Template' { + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" -Describe 'As a user - Classic PAT token (PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_PAT - $owner = 'psmodule-user' - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'TEMPLATE' { - # TESTS HERE - } -} + Context 'As using on ' -ForEach $authCases { + BeforeAll { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } -Describe 'As GitHub Actions (GHA)' { - BeforeAll { - Connect-GitHubAccount - $owner = 'PSModule' - $repo = 'GitHub' - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'TEMPLATE' { - # TESTS HERE - } -} + # Tests for APP goes here + if ($AuthType -eq 'APP') { + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } + } -Describe 'As a GitHub App - Enterprise (APP_ENT)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY - $owner = 'psmodule-test-org3' - Connect-GitHubApp -Organization $owner -Default - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'TEMPLATE' { - # TESTS HERE + # Tests for runners goes here + if ($Type -eq 'GitHub Actions') {} + + # Tests for IAT UAT and PAT goes here } } -Describe 'As a GitHub App - Organization (APP_ORG)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY - $owner = 'psmodule-test-org' - Connect-GitHubApp -Organization $owner -Default - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'TEMPLATE' { - # TESTS HERE - } +AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } From 7197bd47e8f3fd6992cc864621e2abcf7b21dad6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 22:18:10 +0100 Subject: [PATCH 23/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Simplify=20Set-?= =?UTF-8?q?GitHubContext=20by=20removing=20redundant=20AuthType=20check=20?= =?UTF-8?q?for=20IAT=20and=20ensuring=20Git=20configuration=20is=20set=20f?= =?UTF-8?q?or=20all=20non-APP=20contexts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/private/Auth/Context/Set-GitHubContext.ps1 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/functions/private/Auth/Context/Set-GitHubContext.ps1 b/src/functions/private/Auth/Context/Set-GitHubContext.ps1 index 5659517ae..a81d9906d 100644 --- a/src/functions/private/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/private/Auth/Context/Set-GitHubContext.ps1 @@ -149,10 +149,8 @@ function Set-GitHubContext { Set-GitHubDefaultContext -Context $contextObj['Name'] } if ($script:GitHub.EnvironmentType -eq 'GHA') { - if ($contextObj['AuthType'] -eq 'IAT') { - Set-GitHubGitConfig -Context $contextObj['Name'] - } if ($contextObj['AuthType'] -ne 'APP') { + Set-GitHubGitConfig -Context $contextObj['Name'] Connect-GitHubCli -Context $contextObj } } From c8e1f9f52407d486e79161803a1b04b511a7944b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 22:31:11 +0100 Subject: [PATCH 24/60] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20Assert?= =?UTF-8?q?-GitHubContext=20to=20support=20multiple=20AuthType=20values=20?= =?UTF-8?q?(IAT,=20PAT,=20UAT)=20for=20improved=20flexibility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Git/Set-GitHubGitConfig.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Git/Set-GitHubGitConfig.ps1 b/src/functions/public/Git/Set-GitHubGitConfig.ps1 index 22d2e1fa3..d0246c3d4 100644 --- a/src/functions/public/Git/Set-GitHubGitConfig.ps1 +++ b/src/functions/public/Git/Set-GitHubGitConfig.ps1 @@ -28,7 +28,7 @@ $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType IAT + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { From 5e707dae6f1fa1e2718e14406a868baac8cd3806 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 23:08:08 +0100 Subject: [PATCH 25/60] =?UTF-8?q?=F0=9F=A9=B9=20[Refactor]:=20Streamline?= =?UTF-8?q?=20Emoji=20tests=20by=20consolidating=20contexts=20and=20enhanc?= =?UTF-8?q?ing=20structure=20for=20better=20readability=20and=20maintainab?= =?UTF-8?q?ility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Apps.Tests.ps1 | 202 ++++++++++++++++++++--------------------- tests/Emojis.Tests.ps1 | 116 ++++++++--------------- 2 files changed, 137 insertions(+), 181 deletions(-) diff --git a/tests/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 index 7b6735e7b..40b8b82fc 100644 --- a/tests/Apps.Tests.ps1 +++ b/tests/Apps.Tests.ps1 @@ -14,115 +14,115 @@ )] [CmdletBinding()] param() +BeforeAll { + # DEFAULTS ACCROSS ALL TESTS +} -Describe 'As a GitHub App - Enterprise (APP_ENT)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Apps' { - Context 'GitHub Apps' { - It 'Can get a JWT for the app (APP_ENT)' { - $jwt = Get-GitHubAppJSONWebToken -ClientId $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY - Write-Verbose ($jwt | Format-Table | Out-String) -Verbose - $jwt | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubApp - Can get app details (APP_ENT)' { - $app = Get-GitHubApp - Write-Verbose ($app | Format-Table | Out-String) -Verbose - $app | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubAppInstallation - Can get app installations (APP_ENT)' { - $installations = Get-GitHubAppInstallation - Write-Verbose ($installations | Format-Table | Out-String) -Verbose - $installations | Should -Not -BeNullOrEmpty - } - It 'New-GitHubAppInstallationAccessToken - Can get app installation access tokens (APP_ENT)' { - $installations = Get-GitHubAppInstallation - $installations | ForEach-Object { - $token = New-GitHubAppInstallationAccessToken -InstallationID $_.id - Write-Verbose ($token | Format-Table | Out-String) -Verbose - $token | Should -Not -BeNullOrEmpty - } - } - } - Context 'Webhooks' { - It 'Can get the webhook configuration (APP_ENT)' { - $webhooks = Get-GitHubAppWebhookConfiguration - Write-Verbose ($webhooks | Format-Table | Out-String) -Verbose - $webhooks | Should -Not -BeNullOrEmpty - } - It 'Can update the webhook configuration (APP_ENT)' { - { Update-GitHubAppWebhookConfiguration -ContentType 'form' } | Should -Not -Throw - { Update-GitHubAppWebhookConfiguration -ContentType 'json' } | Should -Not -Throw - } - It 'Can get webhook deliveries (APP_ENT)' { - $deliveries = Get-GitHubAppWebhookDelivery - Write-Verbose ($deliveries | Format-Table | Out-String) -Verbose - $deliveries | Should -Not -BeNullOrEmpty - } - It 'Can redeliver a webhook delivery (APP_ENT)' { - $deliveries = Get-GitHubAppWebhookDelivery | Select-Object -First 1 - { Invoke-GitHubAppWebhookReDelivery -ID $deliveries.id } | Should -Not -Throw +Describe 'Apps' { + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" + + Context 'As using on ' -ForEach $authCases { + BeforeAll { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) } } - } -} -Describe 'As a GitHub App - Organization (APP_ORG)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Apps' { - Context 'GitHub Apps' { - It 'Can get a JWT for the app (APP_ORG)' { - $jwt = Get-GitHubAppJSONWebToken -ClientId $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY - Write-Verbose ($jwt | Format-Table | Out-String) -Verbose - $jwt | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubApp - Can get app details (APP_ORG)' { - $app = Get-GitHubApp - Write-Verbose ($app | Format-Table | Out-String) -Verbose - $app | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubAppInstallation - Can get app installations (APP_ORG)' { - $installations = Get-GitHubAppInstallation - Write-Verbose ($installations | Format-Table | Out-String) -Verbose - $installations | Should -Not -BeNullOrEmpty - } - It 'New-GitHubAppInstallationAccessToken - Can get app installation access tokens (APP_ORG)' { - $installations = Get-GitHubAppInstallation - $installations | ForEach-Object { - $token = New-GitHubAppInstallationAccessToken -InstallationID $_.id - Write-Verbose ($token | Format-Table | Out-String) -Verbose - $token | Should -Not -BeNullOrEmpty + # Tests for APP goes here + if ($AuthType -eq 'APP') { + Context 'GitHub Apps' { + It 'Get-GitHubApp - Can get app details' { + $app = Get-GitHubApp + LgGroup 'App' { + Write-Host ($app | Format-Table | Out-String) + } + $app | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubAppJSONWebToken - Can get a JWT for the app' { + $jwt = Get-GitHubAppJSONWebToken @connectParams + LogGroup 'JWT' { + Write-Host ($jwt | Format-Table | Out-String) + } + $jwt | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubAppInstallation - Can get app installations' { + $installations = Get-GitHubAppInstallation + LogGroup 'Installations' { + Write-Host ($installations | Format-Table | Out-String) + } + $installations | Should -Not -BeNullOrEmpty + } + It 'New-GitHubAppInstallationAccessToken - Can get app installation access tokens' { + $installations = Get-GitHubAppInstallation + $installations | ForEach-Object { + $token = New-GitHubAppInstallationAccessToken -InstallationID $_.id + LogGroup 'Token' { + Write-Host ($token | Format-Table | Out-String) + } + $token | Should -Not -BeNullOrEmpty + } } } - } - Context 'Webhooks' { - It 'Can get the webhook configuration (APP_ORG)' { - $webhooks = Get-GitHubAppWebhookConfiguration - Write-Verbose ($webhooks | Format-Table | Out-String) -Verbose - $webhooks | Should -Not -BeNullOrEmpty - } - It 'Can update the webhook configuration (APP_ORG)' { - { Update-GitHubAppWebhookConfiguration -ContentType 'form' } | Should -Not -Throw - { Update-GitHubAppWebhookConfiguration -ContentType 'json' } | Should -Not -Throw - } - It 'Can get webhook deliveries (APP_ORG)' { - $deliveries = Get-GitHubAppWebhookDelivery - Write-Verbose ($deliveries | Format-Table | Out-String) -Verbose - $deliveries | Should -Not -BeNullOrEmpty + + Context 'Webhooks' { + It 'Get-GitHubAppWebhookConfiguration - Can get the webhook configuration' { + $webhookConfig = Get-GitHubAppWebhookConfiguration + LogGroup 'Webhook config' { + Write-Host ($webhookConfig | Format-Table | Out-String) + } + $webhookConfig | Should -Not -BeNullOrEmpty + } + + It 'Update-GitHubAppWebhookConfiguration - Can update the webhook configuration' { + { Update-GitHubAppWebhookConfiguration -ContentType 'form' } | Should -Not -Throw + $webhookConfig = Get-GitHubAppWebhookConfiguration + LogGroup 'Webhook config - form' { + Write-Host ($webhookConfig | Format-Table | Out-String) + } + { Update-GitHubAppWebhookConfiguration -ContentType 'json' } | Should -Not -Throw + $webhookConfig = Get-GitHubAppWebhookConfiguration + LogGroup 'Webhook config - json' { + Write-Host ($webhookConfig | Format-Table | Out-String) + } + } + + It 'Get-GitHubAppWebhookDelivery - Can get webhook deliveries' { + $deliveries = Get-GitHubAppWebhookDelivery + LogGroup 'Deliveries' { + Write-Host ($deliveries | Format-Table | Out-String) + } + $deliveries | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubAppWebhookDelivery - Can redeliver a webhook delivery' { + $deliveries = Get-GitHubAppWebhookDelivery | Select-Object -First 1 + LogGroup 'Delivery - redeliver' { + Write-Host ($deliveries | Format-Table | Out-String) + } + { Invoke-GitHubAppWebhookReDelivery -ID $deliveries.id } | Should -Not -Throw + LogGroup 'Delivery - redeliver' { + Write-Host ($deliveries | Format-Table | Out-String) + } + } } - It 'Can redeliver a webhook delivery (APP_ORG)' { - $deliveries = Get-GitHubAppWebhookDelivery | Select-Object -First 1 - { Invoke-GitHubAppWebhookReDelivery -ID $deliveries.id } | Should -Not -Throw + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } } } + + # Tests for runners goes here + if ($Type -eq 'GitHub Actions') {} + + # Tests for IAT UAT and PAT goes here } } + +AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent +} diff --git a/tests/Emojis.Tests.ps1 b/tests/Emojis.Tests.ps1 index a3ff81fa7..b00e580af 100644 --- a/tests/Emojis.Tests.ps1 +++ b/tests/Emojis.Tests.ps1 @@ -15,99 +15,55 @@ [CmdletBinding()] param() -Describe 'Emoji' { - Context 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } +BeforeAll { + # DEFAULTS ACCROSS ALL TESTS +} - It 'Get-GitHubEmoji - Gets a list of all emojis' { - { Get-GitHubEmoji } | Should -Not -Throw - } - It 'Get-GitHubEmoji - Downloads all emojis' { - { Get-GitHubEmoji -Path $Home } | Should -Not -Throw - } - } +Describe 'Template' { + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" - Context 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { + Context 'As using on ' -ForEach $authCases { BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - It 'Get-GitHubEmoji - Gets a list of all emojis' { - { Get-GitHubEmoji } | Should -Not -Throw - } - It 'Get-GitHubEmoji - Downloads all emojis' { - { Get-GitHubEmoji -Path $Home } | Should -Not -Throw + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } } - } - Context 'As a user - Classic PAT token (PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - It 'Get-GitHubEmoji - Gets a list of all emojis' { - { Get-GitHubEmoji } | Should -Not -Throw - } - It 'Get-GitHubEmoji - Downloads all emojis' { - { Get-GitHubEmoji -Path $Home } | Should -Not -Throw + # Tests for APP goes here + if ($AuthType -eq 'APP') { + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } } - } + # Tests for runners goes here + if ($Type -eq 'GitHub Actions') {} - Context 'As GitHub Actions (GHA)' { - BeforeAll { - Connect-GitHubAccount - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } + # Tests for IAT UAT and PAT goes here It 'Get-GitHubEmoji - Gets a list of all emojis' { - { Get-GitHubEmoji } | Should -Not -Throw - } - It 'Get-GitHubEmoji - Downloads all emojis' { - { Get-GitHubEmoji -Path $Home } | Should -Not -Throw - } - - } - - Context 'As a GitHub App - Enterprise (APP_ENT)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY - Connect-GitHubApp -Organization 'psmodule-test-org3' -Default - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - It 'Get-GitHubEmoji - Gets a list of all emojis' { - { Get-GitHubEmoji } | Should -Not -Throw + { + $emojies = Get-GitHubEmoji + LogGroup 'Emojies' { + Write-Host ($emojies | Format-Table | Out-String) + } + } | Should -Not -Throw + $emojies| Should -Not -BeNullOrEmpty } It 'Get-GitHubEmoji - Downloads all emojis' { { Get-GitHubEmoji -Path $Home } | Should -Not -Throw + LogGroup 'Emojies' { + $emojies = Get-ChildItem -Path $Home -File + Write-Host ($emojies | Format-Table | Out-String) + } + $emojies | Should -Not -BeNullOrEmpty } } +} - Context 'As a GitHub App - Organization (APP_ORG)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY - Connect-GitHubApp -Organization 'psmodule-test-org' -Default - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - It 'Get-GitHubEmoji - Gets a list of all emojis (APP_ORG)' { - { Get-GitHubEmoji } | Should -Not -Throw - } - It 'Get-GitHubEmoji - Downloads all emojis (APP_ORG)' { - { Get-GitHubEmoji -Path $Home } | Should -Not -Throw - } - } +AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } From 389528141fa48060894eebf536b0929e24a2d637 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 23:14:06 +0100 Subject: [PATCH 26/60] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Correct=20log=20f?= =?UTF-8?q?unction=20name=20and=20update=20test=20description=20for=20clar?= =?UTF-8?q?ity=20in=20Apps=20and=20Emojis=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Apps.Tests.ps1 | 2 +- tests/Emojis.Tests.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 index 40b8b82fc..1639323ed 100644 --- a/tests/Apps.Tests.ps1 +++ b/tests/Apps.Tests.ps1 @@ -34,7 +34,7 @@ Describe 'Apps' { Context 'GitHub Apps' { It 'Get-GitHubApp - Can get app details' { $app = Get-GitHubApp - LgGroup 'App' { + LogGroup 'App' { Write-Host ($app | Format-Table | Out-String) } $app | Should -Not -BeNullOrEmpty diff --git a/tests/Emojis.Tests.ps1 b/tests/Emojis.Tests.ps1 index b00e580af..aa7046253 100644 --- a/tests/Emojis.Tests.ps1 +++ b/tests/Emojis.Tests.ps1 @@ -19,7 +19,7 @@ BeforeAll { # DEFAULTS ACCROSS ALL TESTS } -Describe 'Template' { +Describe 'Emojies' { $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" Context 'As using on ' -ForEach $authCases { From 7aa46dfc973528aac2620f9e9adffc14174a9df1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 23:16:53 +0100 Subject: [PATCH 27/60] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Correct=20formatt?= =?UTF-8?q?ing=20in=20Emojis=20test=20to=20enhance=20readability=20and=20m?= =?UTF-8?q?aintain=20consistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Emojis.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Emojis.Tests.ps1 b/tests/Emojis.Tests.ps1 index aa7046253..5b240d829 100644 --- a/tests/Emojis.Tests.ps1 +++ b/tests/Emojis.Tests.ps1 @@ -51,7 +51,7 @@ Describe 'Emojies' { Write-Host ($emojies | Format-Table | Out-String) } } | Should -Not -Throw - $emojies| Should -Not -BeNullOrEmpty + $emojies | Should -Not -BeNullOrEmpty } It 'Get-GitHubEmoji - Downloads all emojis' { { Get-GitHubEmoji -Path $Home } | Should -Not -Throw From 14796d85f4ba257bb361e817ce90f91c95ff4ed5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 23:26:41 +0100 Subject: [PATCH 28/60] =?UTF-8?q?=F0=9F=A9=B9=20[Refactor]:=20Simplify=20E?= =?UTF-8?q?moji=20tests=20by=20removing=20unnecessary=20code=20blocks=20fo?= =?UTF-8?q?r=20improved=20readability=20and=20maintainability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Emojis.Tests.ps1 | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/Emojis.Tests.ps1 b/tests/Emojis.Tests.ps1 index 5b240d829..daee4e525 100644 --- a/tests/Emojis.Tests.ps1 +++ b/tests/Emojis.Tests.ps1 @@ -45,16 +45,14 @@ Describe 'Emojies' { # Tests for IAT UAT and PAT goes here It 'Get-GitHubEmoji - Gets a list of all emojis' { - { - $emojies = Get-GitHubEmoji - LogGroup 'Emojies' { - Write-Host ($emojies | Format-Table | Out-String) - } - } | Should -Not -Throw + $emojies = Get-GitHubEmoji + LogGroup 'Emojies' { + Write-Host ($emojies | Format-Table | Out-String) + } $emojies | Should -Not -BeNullOrEmpty } It 'Get-GitHubEmoji - Downloads all emojis' { - { Get-GitHubEmoji -Path $Home } | Should -Not -Throw + Get-GitHubEmoji -Path $Home LogGroup 'Emojies' { $emojies = Get-ChildItem -Path $Home -File Write-Host ($emojies | Format-Table | Out-String) From 9abd6a4d011bf609ff4466801011e6eb7fef5cb2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 23:42:40 +0100 Subject: [PATCH 29/60] --- tests/Environments.Tests.ps1 | 341 ++++++++++------------------------- 1 file changed, 98 insertions(+), 243 deletions(-) diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 index 6c628b108..ea66f5d53 100644 --- a/tests/Environments.Tests.ps1 +++ b/tests/Environments.Tests.ps1 @@ -22,262 +22,117 @@ BeforeAll { } Describe 'Environments' { + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" - Context 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { + Context 'As using on ' -ForEach $authCases { BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT - $owner = 'psmodule-user' + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } $guid = [guid]::NewGuid().ToString() $repo = "$repoSuffix-$guid" New-GitHubRepository -Name $repo -AllowSquashMerge } - AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - It 'Get-GitHubEnvironment - should return an empty list when no environments exist' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo - $result | Should -BeNullOrEmpty - } - It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName - $result | Should -BeNullOrEmpty - } - It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' { - $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -WaitTimer 10 - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be $environmentName - $result.ProtectionRules.wait_timer | Should -Be 10 - } - It 'Get-GitHubEnvironment - should retrieve the environment that was created' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be $environmentName - } - It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' { - $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be "$environmentName/$os" - } - It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be "$environmentName/$os" - } - It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' { - { - Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false - } | Should -Not -Throw - } - It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - $result | Should -BeNullOrEmpty - } - It 'Get-GitHubEnvironment - should list one remaining environment' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo - $result.Count | Should -Be 1 - } - It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' { - { Remove-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -Confirm:$false } | Should -Not -Throw - } - It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName - $result | Should -BeNullOrEmpty - } - } - Context 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT - $owner = 'psmodule-test-org2' - $guid = [guid]::NewGuid().ToString() - $repo = "$repoSuffix-$guid" - New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge - } AfterAll { Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - It 'Get-GitHubEnvironment - should return an empty list when no environments exist' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo - $result | Should -BeNullOrEmpty - } - It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName - $result | Should -BeNullOrEmpty - } - It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' { - $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -WaitTimer 10 - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be $environmentName - $result.ProtectionRules.wait_timer | Should -Be 10 - } - It 'Get-GitHubEnvironment - should retrieve the environment that was created' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be $environmentName - } - It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' { - $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be "$environmentName/$os" - } - It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be "$environmentName/$os" - } - It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' { - { - Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false - } | Should -Not -Throw - } - It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - $result | Should -BeNullOrEmpty } - It 'Get-GitHubEnvironment - should list one remaining environment' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo - $result.Count | Should -Be 1 - } - It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' { - { Remove-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -Confirm:$false } | Should -Not -Throw - } - It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName - $result | Should -BeNullOrEmpty - } - } - Context 'As a user - Classic PAT token (PAT)' -Skip {} - - Context 'As GitHub Actions (GHA)' -Skip {} - - Context 'As a GitHub App - Enterprise (APP_ENT)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY - $owner = 'psmodule-test-org3' - $guid = [guid]::NewGuid().ToString() - $repo = "$repoSuffix-$guid" - Connect-GitHubApp -Organization $owner -Default - New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge - } - AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - It 'Get-GitHubEnvironment - should return an empty list when no environments exist' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo - $result | Should -BeNullOrEmpty - } - It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName - $result | Should -BeNullOrEmpty - } - It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' { - $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -WaitTimer 10 - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be $environmentName - $result.ProtectionRules.wait_timer | Should -Be 10 - } - It 'Get-GitHubEnvironment - should retrieve the environment that was created' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be $environmentName - } - It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' { - $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be "$environmentName/$os" + # Tests for APP goes here + if ($AuthType -eq 'APP') { + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } } - It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be "$environmentName/$os" - } - It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' { - { - Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false - } | Should -Not -Throw - } - It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - $result | Should -BeNullOrEmpty - } - It 'Get-GitHubEnvironment - should list one remaining environment' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo - $result.Count | Should -Be 1 - } - It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' { - { Remove-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -Confirm:$false } | Should -Not -Throw - } - It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName - $result | Should -BeNullOrEmpty - } - } - Context 'As a GitHub App - Organization (APP_ORG)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY - $owner = 'psmodule-test-org' - $guid = [guid]::NewGuid().ToString() - $repo = "$repoSuffix-$guid" - Connect-GitHubApp -Organization $owner -Default - New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge - } - AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - It 'Get-GitHubEnvironment - should return an empty list when no environments exist' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo - $result | Should -BeNullOrEmpty - } - It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName - $result | Should -BeNullOrEmpty - } - It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' { - $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -WaitTimer 10 - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be $environmentName - $result.ProtectionRules.wait_timer | Should -Be 10 - } - It 'Get-GitHubEnvironment - should retrieve the environment that was created' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be $environmentName - } - It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' { - $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be "$environmentName/$os" - } - It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be "$environmentName/$os" - } - It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' { - { - Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false - } | Should -Not -Throw - } - It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - $result | Should -BeNullOrEmpty - } - It 'Get-GitHubEnvironment - should list one remaining environment' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo - $result.Count | Should -Be 1 - } - It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' { - { Remove-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -Confirm:$false } | Should -Not -Throw - } - It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName - $result | Should -BeNullOrEmpty + # Tests for runners goes here + if ($Type -ne 'GitHub Actions') { + # Tests for IAT UAT and PAT goes here + It 'Get-GitHubEnvironment - should return an empty list when no environments exist' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo + LogGroup "Environment" { + Write-Host ($result | Format-Table | Out-String) + } + $result | Should -BeNullOrEmpty + } + It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + LogGroup 'Environment' { + Write-Host ($result | Format-Table | Out-String) + } + $result | Should -BeNullOrEmpty + } + It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' { + $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -WaitTimer 10 + LogGroup 'Environment' { + Write-Host ($result | Format-List | Out-String) + } + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType [GitHubEnvironment] + $result.Name | Should -Be $environmentName + $result.ProtectionRules.wait_timer | Should -Be 10 + } + It 'Get-GitHubEnvironment - should retrieve the environment that was created' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + LogGroup 'Environment' { + Write-Host ($result | Format-List | Out-String) + } + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $environmentName + } + It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' { + $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" + LogGroup 'Environment' { + Write-Host ($result | Format-List | Out-String) + } + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be "$environmentName/$os" + } + It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" + LogGroup 'Environment' { + Write-Host ($result | Format-Table | Out-String) + } + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be "$environmentName/$os" + } + It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' { + { + Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false + } | Should -Not -Throw + } + It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" + LogGroup 'Environment' { + Write-Host ($result | Format-Table | Out-String) + } + $result | Should -BeNullOrEmpty + } + It 'Get-GitHubEnvironment - should list one remaining environment' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo + LogGroup 'Environment' { + Write-Host ($result | Format-Table | Out-String) + } + $result.Count | Should -Be 1 + } + It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' { + { Remove-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -Confirm:$false } | Should -Not -Throw + } + It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + LogGroup 'Environment' { + Write-Host ($result | Format-Table | Out-String) + } + $result | Should -BeNullOrEmpty + } } } } + +AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent +} From af4ff252b0ddb48f16bf1b08d39001cb53c1531c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Mar 2025 00:25:30 +0100 Subject: [PATCH 30/60] =?UTF-8?q?=F0=9F=A9=B9=20[Add]:=20Introduce=20new?= =?UTF-8?q?=20test=20for=20New-GitHubRepository=20to=20validate=20behavior?= =?UTF-8?q?=20for=20different=20user=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Environments.Tests.ps1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 index ea66f5d53..6dac2e4b2 100644 --- a/tests/Environments.Tests.ps1 +++ b/tests/Environments.Tests.ps1 @@ -32,7 +32,6 @@ Describe 'Environments' { } $guid = [guid]::NewGuid().ToString() $repo = "$repoSuffix-$guid" - New-GitHubRepository -Name $repo -AllowSquashMerge } AfterAll { @@ -52,6 +51,13 @@ Describe 'Environments' { # Tests for runners goes here if ($Type -ne 'GitHub Actions') { # Tests for IAT UAT and PAT goes here + It 'Prep - New-GitHubRepository' { + if ($type -eq 'a user') { + New-GitHubRepository -Name $repo -AllowSquashMerge + } else { + New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge + } + } It 'Get-GitHubEnvironment - should return an empty list when no environments exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo LogGroup "Environment" { From 495a79fb5420c08bef91105d0f63257b575aac0f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Mar 2025 00:34:22 +0100 Subject: [PATCH 31/60] =?UTF-8?q?=F0=9F=A9=B9=20[Enhance]:=20Add=20OwnerTy?= =?UTF-8?q?pe=20property=20to=20authentication=20cases=20for=20improved=20?= =?UTF-8?q?clarity=20in=20user=20and=20organization=20identification?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Data/AuthCases.ps1 | 6 ++++++ tests/Environments.Tests.ps1 | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/Data/AuthCases.ps1 b/tests/Data/AuthCases.ps1 index 574ca9b0c..3aeefead5 100644 --- a/tests/Data/AuthCases.ps1 +++ b/tests/Data/AuthCases.ps1 @@ -5,6 +5,7 @@ Case = 'Fine-grained PAT token' Target = 'it self (user account)' Owner = 'psmodule-user' + OwnerType = 'user' ConnectParams = @{ Token = $env:TEST_USER_USER_FG_PAT } @@ -15,6 +16,7 @@ Case = 'Fine-grained PAT token' Target = 'organization account' Owner = 'psmodule-test-org2' + OwnerType = 'organization' ConnectParams = @{ Token = $env:TEST_USER_ORG_FG_PAT } @@ -25,6 +27,7 @@ Case = 'Classic PAT token' Target = 'user account' Owner = 'psmodule-user' + OwnerType = 'user' ConnectParams = @{ Token = $env:TEST_USER_PAT } @@ -36,6 +39,7 @@ Target = 'this repository (GitHub)' Owner = 'PSModule' Repo = 'GitHub' + OwnerType = 'organization' ConnectParams = @{ Token = $env:GITHUB_TOKEN } @@ -46,6 +50,7 @@ Case = 'PEM + IAT' Target = 'organization account' Owner = 'psmodule-test-org3' + OwnerType = 'organization' ConnectParams = @{ ClientID = $env:TEST_APP_ENT_CLIENT_ID PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY @@ -60,6 +65,7 @@ Case = 'PEM + IAT' Target = 'organization account' Owner = 'psmodule-test-org' + OwnerType = 'organization' ConnectParams = @{ ClientID = $env:TEST_APP_ORG_CLIENT_ID PrivateKey = $env:TEST_APP_ORG_PRIVATE_KEY diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 index 6dac2e4b2..822e13dc3 100644 --- a/tests/Environments.Tests.ps1 +++ b/tests/Environments.Tests.ps1 @@ -52,7 +52,7 @@ Describe 'Environments' { if ($Type -ne 'GitHub Actions') { # Tests for IAT UAT and PAT goes here It 'Prep - New-GitHubRepository' { - if ($type -eq 'a user') { + if ($OwnerType -eq 'user') { New-GitHubRepository -Name $repo -AllowSquashMerge } else { New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge From 6ee2eb81325b932f3cec09cf56596cc75bb62bf7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Mar 2025 01:01:16 +0100 Subject: [PATCH 32/60] =?UTF-8?q?=F0=9F=A9=B9=20[Refactor]:=20Streamline?= =?UTF-8?q?=20repository=20access=20tests=20by=20consolidating=20user=20ac?= =?UTF-8?q?count=20scenarios=20and=20enhancing=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Repositories.Tests.ps1 | 135 +++++++++++++++-------------------- tests/User.Tests.ps1 | 130 ++++++++------------------------- 2 files changed, 87 insertions(+), 178 deletions(-) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 9776e8fc1..29d6e7653 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -15,96 +15,77 @@ [CmdletBinding()] param() -Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Repository' { +Describe 'Template' { + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" + + Context 'As using on ' -ForEach $authCases { + BeforeAll { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } + + # Tests for APP goes here + if ($AuthType -eq 'APP') { + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } + } + + # Tests for runners goes here + if ($Type -eq 'GitHub Actions') {} + + # Tests for IAT UAT and PAT goes here + It "Get-GitHubRepository - Gets the authenticated user's repositories (USER_FG_PAT)" { - { Get-GitHubRepository } | Should -Not -Throw + $repo = Get-GitHubRepository + LogGroup 'Repository' { + Write-Host ($repo | Format-Table | Out-String) + } + $repo | Should -Not -BeNullOrEmpty } It "Get-GitHubRepository - Gets the authenticated user's public repositories (USER_FG_PAT)" { - { Get-GitHubRepository -Type 'public' } | Should -Not -Throw + $repo = Get-GitHubRepository -Type 'public' + LogGroup 'Repository' { + Write-Host ($repo | Format-Table | Out-String) + } + $repo | Should -Not -BeNullOrEmpty } It 'Get-GitHubRepository - Gets the public repos where the authenticated user is owner (USER_FG_PAT)' { - { Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' } | Should -Not -Throw + $repo = Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' + LogGroup 'Repository' { + Write-Host ($repo | Format-Table | Out-String) + } + $repo | Should -Not -BeNullOrEmpty } It 'Get-GitHubRepository - Gets a specific repository (USER_FG_PAT)' { - { Get-GitHubRepository -Owner 'PSModule' -Name 'GitHub' } | Should -Not -Throw + $repo = Get-GitHubRepository -Owner 'PSModule' -Name 'GitHub' + LogGroup 'Repository' { + Write-Host ($repo | Format-Table | Out-String) + } + $repo | Should -Not -BeNullOrEmpty } It 'Get-GitHubRepository - Gets all repositories from a organization (USER_FG_PAT)' { - { Get-GitHubRepository -Owner 'PSModule' } | Should -Not -Throw + $repo = Get-GitHubRepository -Owner 'PSModule' + LogGroup 'Repository' { + Write-Host ($repo | Format-Table | Out-String) + } + $repo | Should -Not -BeNullOrEmpty } It 'Get-GitHubRepository - Gets all repositories from a user (USER_FG_PAT)' { - { Get-GitHubRepository -Username 'MariusStorhaug' } | Should -Not -Throw - } - } -} - -Describe 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Repository' { - It "Get-GitHubRepository - Gets the authenticated user's repositories (ORG_FG_PAT)" { - { Get-GitHubRepository } | Should -Not -Throw - } - It "Get-GitHubRepository - Gets the authenticated user's public repositories (ORG_FG_PAT)" { - { Get-GitHubRepository -Type 'public' } | Should -Not -Throw - } - It 'Get-GitHubRepository - Gets the public repos where the authenticated user is owner (ORG_FG_PAT)' { - { Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' } | Should -Not -Throw - } - It 'Get-GitHubRepository - Gets a specific repository (ORG_FG_PAT)' { - { Get-GitHubRepository -Owner 'PSModule' -Name 'GitHub' } | Should -Not -Throw - } - It 'Get-GitHubRepository - Gets all repositories from a organization (ORG_FG_PAT)' { - { Get-GitHubRepository -Owner 'PSModule' } | Should -Not -Throw - } - It 'Get-GitHubRepository - Gets all repositories from a user (ORG_FG_PAT)' { - { Get-GitHubRepository -Username 'MariusStorhaug' } | Should -Not -Throw + $repo = Get-GitHubRepository -Username 'MariusStorhaug' + LogGroup 'Repository' { + Write-Host ($repo | Format-Table | Out-String) + } + $repo | Should -Not -BeNullOrEmpty } } } -Describe 'As a user - Classic PAT token (PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } -} - -Describe 'As GitHub Actions (GHA)' { - BeforeAll { - Connect-GitHubAccount - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } -} - -Describe 'As a GitHub App - Enterprise (APP_ENT)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } -} - -Describe 'As a GitHub App - Organization (APP_ORG)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } +AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } diff --git a/tests/User.Tests.ps1 b/tests/User.Tests.ps1 index 0e92b0637..19e5e26a6 100644 --- a/tests/User.Tests.ps1 +++ b/tests/User.Tests.ps1 @@ -15,84 +15,40 @@ [CmdletBinding()] param() -Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'User' { - It 'Get-GitHubUser - Gets the authenticated user (USER_FG_PAT)' { - { Get-GitHubUser } | Should -Not -Throw - } - It 'Get-GitHubUser - Get the specified user (USER_FG_PAT)' { - { Get-GitHubUser -Username 'Octocat' } | Should -Not -Throw - } - It 'Update-GitHubUser - Can set configuration on a user (USER_FG_PAT)' { - $guid = (New-Guid).Guid - $user = Get-GitHubUser - { Update-GitHubUser -Name 'Octocat' } | Should -Not -Throw - { Update-GitHubUser -Blog 'https://psmodule.io' } | Should -Not -Throw - { Update-GitHubUser -TwitterUsername 'PSModule' } | Should -Not -Throw - { Update-GitHubUser -Company 'PSModule' } | Should -Not -Throw - { Update-GitHubUser -Location 'USA' } | Should -Not -Throw - { Update-GitHubUser -Bio 'I love programming' } | Should -Not -Throw - $tmpUser = Get-GitHubUser - $tmpUser.name | Should -Be 'Octocat' - $tmpUser.blog | Should -Be 'https://psmodule.io' - $tmpUser.twitter_username | Should -Be 'PSModule' - $tmpUser.company | Should -Be 'PSModule' - $tmpUser.location | Should -Be 'USA' - $tmpUser.bio | Should -Be 'I love programming' - } - Context 'Email' { - It 'Get-GitHubUserEmail - Gets all email addresses for the authenticated user (USER_FG_PAT)' { - { Get-GitHubUserEmail } | Should -Not -Throw - } - It 'Add/Remove-GitHubUserEmail - Adds and removes an email to the authenticated user (USER_FG_PAT)' { - $email = (New-Guid).Guid + '@psmodule.io' - { Add-GitHubUserEmail -Email $email } | Should -Not -Throw - (Get-GitHubUserEmail).email | Should -Contain $email - { Remove-GitHubUserEmail -Email $email } | Should -Not -Throw - (Get-GitHubUserEmail).email | Should -Not -Contain $email +Context 'User' { + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" + + Context 'As using on ' -ForEach $authCases { + BeforeAll { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) } } - } -} -Describe 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'User' { - It 'Get-GitHubUser - Gets the authenticated user (ORG_FG_PAT)' { - { Get-GitHubUser } | Should -Not -Throw + # Tests for APP goes here + if ($AuthType -eq 'APP') { + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } } - It 'Get-GitHubUser - Get the specified user (ORG_FG_PAT)' { + + # Tests for runners goes here + if ($Type -eq 'GitHub Actions') {} + + # Tests for IAT UAT and PAT goes here + It 'Get-GitHubUser - Get the specified user' { { Get-GitHubUser -Username 'Octocat' } | Should -Not -Throw } - } -} -Describe 'As a user - Classic PAT token (PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'User' { - It 'Get-GitHubUser - Gets the authenticated user (PAT)' { + if ($OwnerType -eq 'user') + It 'Get-GitHubUser - Gets the authenticated user' { { Get-GitHubUser } | Should -Not -Throw } - It 'Get-GitHubUser - Get the specified user (PAT)' { - { Get-GitHubUser -Username 'Octocat' } | Should -Not -Throw - } - It 'Update-GitHubUser - Can set configuration on a user (PAT)' { + It 'Update-GitHubUser - Can set configuration on a user' { $guid = (New-Guid).Guid $user = Get-GitHubUser { Update-GitHubUser -Name 'Octocat' } | Should -Not -Throw @@ -110,10 +66,10 @@ Describe 'As a user - Classic PAT token (PAT)' { $tmpUser.bio | Should -Be 'I love programming' } Context 'Email' { - It 'Get-GitHubUserEmail - Gets all email addresses for the authenticated user (PAT)' { + It 'Get-GitHubUserEmail - Gets all email addresses for the authenticated user' { { Get-GitHubUserEmail } | Should -Not -Throw } - It 'Add/Remove-GitHubUserEmail - Adds and removes an email to the authenticated user (PAT)' { + It 'Add/Remove-GitHubUserEmail - Adds and removes an email to the authenticated user' { $email = (New-Guid).Guid + '@psmodule.io' { Add-GitHubUserEmail -Email $email } | Should -Not -Throw (Get-GitHubUserEmail).email | Should -Contain $email @@ -124,34 +80,6 @@ Describe 'As a user - Classic PAT token (PAT)' { } } -Describe 'As GitHub Actions (GHA)' { - BeforeAll { - Connect-GitHubAccount - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'User' { - It 'Get-GitHubUser - Get the specified user (GHA)' { - { Get-GitHubUser -Username 'Octocat' } | Should -Not -Throw - } - } -} - -Describe 'As a GitHub App - Enterprise (APP_ENT)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } -} - -Describe 'As a GitHub App - Organization (APP_ORG)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } +AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } From 4503824a9ce4da48564cf3321dc467d3e92c5610 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Mar 2025 09:07:38 +0100 Subject: [PATCH 33/60] =?UTF-8?q?=F0=9F=A9=B9=20[Refactor]:=20Add=20AfterA?= =?UTF-8?q?ll=20cleanup=20to=20disconnect=20GitHub=20accounts=20in=20multi?= =?UTF-8?q?ple=20test=20files=20for=20improved=20resource=20management?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/API.Tests.ps1 | 3 +++ tests/Apps.Tests.ps1 | 8 ++++---- tests/Auth.Tests.ps1 | 8 ++++---- tests/Emojis.Tests.ps1 | 8 ++++---- tests/Environments.Tests.ps1 | 8 +++----- tests/Repositories.Tests.ps1 | 8 ++++---- tests/TEMPLATE.ps1 | 8 ++++---- tests/User.Tests.ps1 | 7 +++---- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/API.Tests.ps1 b/tests/API.Tests.ps1 index 8a483c372..f99cbc1a7 100644 --- a/tests/API.Tests.ps1 +++ b/tests/API.Tests.ps1 @@ -30,6 +30,9 @@ Describe 'Template' { } $context | Should -Not -BeNullOrEmpty } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + } # Tests for APP goes here if ($AuthType -eq 'APP') { diff --git a/tests/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 index 1639323ed..d6227d80f 100644 --- a/tests/Apps.Tests.ps1 +++ b/tests/Apps.Tests.ps1 @@ -29,6 +29,10 @@ Describe 'Apps' { } } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + } + # Tests for APP goes here if ($AuthType -eq 'APP') { Context 'GitHub Apps' { @@ -122,7 +126,3 @@ Describe 'Apps' { # Tests for IAT UAT and PAT goes here } } - -AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent -} diff --git a/tests/Auth.Tests.ps1 b/tests/Auth.Tests.ps1 index 76af5b283..2feca40a9 100644 --- a/tests/Auth.Tests.ps1 +++ b/tests/Auth.Tests.ps1 @@ -19,6 +19,10 @@ Describe 'Auth' { $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" Context 'As using on ' -ForEach $authCases { + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + } + It 'Connect-GitHubAccount - Connects using the provided credentials' { $context = Connect-GitHubAccount @connectParams -PassThru -Silent LogGroup 'Context' { @@ -115,7 +119,3 @@ Describe 'Auth' { } } } - -AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent -} diff --git a/tests/Emojis.Tests.ps1 b/tests/Emojis.Tests.ps1 index daee4e525..c0c549ff5 100644 --- a/tests/Emojis.Tests.ps1 +++ b/tests/Emojis.Tests.ps1 @@ -29,6 +29,10 @@ Describe 'Emojies' { Write-Host ($context | Format-List | Out-String) } } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + } + # Tests for APP goes here if ($AuthType -eq 'APP') { @@ -61,7 +65,3 @@ Describe 'Emojies' { } } } - -AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent -} diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 index 822e13dc3..11406844a 100644 --- a/tests/Environments.Tests.ps1 +++ b/tests/Environments.Tests.ps1 @@ -36,8 +36,10 @@ Describe 'Environments' { AfterAll { Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } + # Tests for APP goes here if ($AuthType -eq 'APP') { It 'Connect-GitHubApp - Connects as a GitHub App to ' { @@ -60,7 +62,7 @@ Describe 'Environments' { } It 'Get-GitHubEnvironment - should return an empty list when no environments exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo - LogGroup "Environment" { + LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) } $result | Should -BeNullOrEmpty @@ -138,7 +140,3 @@ Describe 'Environments' { } } } - -AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent -} diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 29d6e7653..e09d459a1 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -25,6 +25,10 @@ Describe 'Template' { Write-Host ($context | Format-List | Out-String) } } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + } + # Tests for APP goes here if ($AuthType -eq 'APP') { @@ -85,7 +89,3 @@ Describe 'Template' { } } } - -AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent -} diff --git a/tests/TEMPLATE.ps1 b/tests/TEMPLATE.ps1 index 3df117a16..56d415d8a 100644 --- a/tests/TEMPLATE.ps1 +++ b/tests/TEMPLATE.ps1 @@ -29,6 +29,10 @@ Describe 'Template' { Write-Host ($context | Format-List | Out-String) } } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + } + # Tests for APP goes here if ($AuthType -eq 'APP') { @@ -46,7 +50,3 @@ Describe 'Template' { # Tests for IAT UAT and PAT goes here } } - -AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent -} diff --git a/tests/User.Tests.ps1 b/tests/User.Tests.ps1 index 19e5e26a6..5882a50a4 100644 --- a/tests/User.Tests.ps1 +++ b/tests/User.Tests.ps1 @@ -25,6 +25,9 @@ Context 'User' { Write-Host ($context | Format-List | Out-String) } } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + } # Tests for APP goes here if ($AuthType -eq 'APP') { @@ -79,7 +82,3 @@ Context 'User' { } } } - -AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent -} From a5644a618b2c59ba69fe05e2334f62142d554368 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Mar 2025 10:25:20 +0100 Subject: [PATCH 34/60] =?UTF-8?q?=F0=9F=A9=B9=20[Refactor]:=20Improve=20te?= =?UTF-8?q?st=20structure=20for=20Get-GitHubUser=20and=20email=20managemen?= =?UTF-8?q?t=20by=20consolidating=20related=20assertions=20and=20enhancing?= =?UTF-8?q?=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/User.Tests.ps1 | 57 ++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/tests/User.Tests.ps1 b/tests/User.Tests.ps1 index 5882a50a4..12b022ec8 100644 --- a/tests/User.Tests.ps1 +++ b/tests/User.Tests.ps1 @@ -47,37 +47,38 @@ Context 'User' { { Get-GitHubUser -Username 'Octocat' } | Should -Not -Throw } - if ($OwnerType -eq 'user') - It 'Get-GitHubUser - Gets the authenticated user' { - { Get-GitHubUser } | Should -Not -Throw - } - It 'Update-GitHubUser - Can set configuration on a user' { - $guid = (New-Guid).Guid - $user = Get-GitHubUser - { Update-GitHubUser -Name 'Octocat' } | Should -Not -Throw - { Update-GitHubUser -Blog 'https://psmodule.io' } | Should -Not -Throw - { Update-GitHubUser -TwitterUsername 'PSModule' } | Should -Not -Throw - { Update-GitHubUser -Company 'PSModule' } | Should -Not -Throw - { Update-GitHubUser -Location 'USA' } | Should -Not -Throw - { Update-GitHubUser -Bio 'I love programming' } | Should -Not -Throw - $tmpUser = Get-GitHubUser - $tmpUser.name | Should -Be 'Octocat' - $tmpUser.blog | Should -Be 'https://psmodule.io' - $tmpUser.twitter_username | Should -Be 'PSModule' - $tmpUser.company | Should -Be 'PSModule' - $tmpUser.location | Should -Be 'USA' - $tmpUser.bio | Should -Be 'I love programming' - } - Context 'Email' { - It 'Get-GitHubUserEmail - Gets all email addresses for the authenticated user' { - { Get-GitHubUserEmail } | Should -Not -Throw + if ($OwnerType -eq 'user') { + It 'Get-GitHubUser - Gets the authenticated user' { + { Get-GitHubUser } | Should -Not -Throw + } + It 'Update-GitHubUser - Can set configuration on a user' { + $guid = (New-Guid).Guid + $user = Get-GitHubUser + { Update-GitHubUser -Name 'Octocat' } | Should -Not -Throw + { Update-GitHubUser -Blog 'https://psmodule.io' } | Should -Not -Throw + { Update-GitHubUser -TwitterUsername 'PSModule' } | Should -Not -Throw + { Update-GitHubUser -Company 'PSModule' } | Should -Not -Throw + { Update-GitHubUser -Location 'USA' } | Should -Not -Throw + { Update-GitHubUser -Bio 'I love programming' } | Should -Not -Throw + $tmpUser = Get-GitHubUser + $tmpUser.name | Should -Be 'Octocat' + $tmpUser.blog | Should -Be 'https://psmodule.io' + $tmpUser.twitter_username | Should -Be 'PSModule' + $tmpUser.company | Should -Be 'PSModule' + $tmpUser.location | Should -Be 'USA' + $tmpUser.bio | Should -Be 'I love programming' } - It 'Add/Remove-GitHubUserEmail - Adds and removes an email to the authenticated user' { - $email = (New-Guid).Guid + '@psmodule.io' - { Add-GitHubUserEmail -Email $email } | Should -Not -Throw + Context 'Email' { + It 'Get-GitHubUserEmail - Gets all email addresses for the authenticated user' { + { Get-GitHubUserEmail } | Should -Not -Throw + } + It 'Add/Remove-GitHubUserEmail - Adds and removes an email to the authenticated user' { + $email = (New-Guid).Guid + '@psmodule.io' + { Add-GitHubUserEmail -Email $email } | Should -Not -Throw (Get-GitHubUserEmail).email | Should -Contain $email - { Remove-GitHubUserEmail -Email $email } | Should -Not -Throw + { Remove-GitHubUserEmail -Email $email } | Should -Not -Throw (Get-GitHubUserEmail).email | Should -Not -Contain $email + } } } } From 23fdd77b2a46f031f501ecb6dcf92af83d1057f9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Mar 2025 11:40:47 +0100 Subject: [PATCH 35/60] =?UTF-8?q?=F0=9F=A9=B9=20[Refactor]:=20Remove=20red?= =?UTF-8?q?undant=20AfterAll=20cleanup=20from=20multiple=20test=20files=20?= =?UTF-8?q?for=20improved=20clarity=20and=20maintainability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/API.Tests.ps1 | 4 -- tests/Emojis.Tests.ps1 | 1 - tests/Environments.Tests.ps1 | 1 - tests/Repositories.Tests.ps1 | 76 ++++++++++++++++++------------------ tests/TEMPLATE.ps1 | 1 - 5 files changed, 38 insertions(+), 45 deletions(-) diff --git a/tests/API.Tests.ps1 b/tests/API.Tests.ps1 index f99cbc1a7..b57f69f68 100644 --- a/tests/API.Tests.ps1 +++ b/tests/API.Tests.ps1 @@ -236,7 +236,3 @@ Describe 'Template' { } } } - -AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent -} diff --git a/tests/Emojis.Tests.ps1 b/tests/Emojis.Tests.ps1 index c0c549ff5..f3da2ff64 100644 --- a/tests/Emojis.Tests.ps1 +++ b/tests/Emojis.Tests.ps1 @@ -33,7 +33,6 @@ Describe 'Emojies' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } - # Tests for APP goes here if ($AuthType -eq 'APP') { It 'Connect-GitHubApp - Connects as a GitHub App to ' { diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 index 11406844a..8295495b7 100644 --- a/tests/Environments.Tests.ps1 +++ b/tests/Environments.Tests.ps1 @@ -39,7 +39,6 @@ Describe 'Environments' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } - # Tests for APP goes here if ($AuthType -eq 'APP') { It 'Connect-GitHubApp - Connects as a GitHub App to ' { diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index e09d459a1..f45789441 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -29,7 +29,6 @@ Describe 'Template' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } - # Tests for APP goes here if ($AuthType -eq 'APP') { It 'Connect-GitHubApp - Connects as a GitHub App to ' { @@ -41,51 +40,52 @@ Describe 'Template' { } # Tests for runners goes here - if ($Type -eq 'GitHub Actions') {} + if ($Type -ne 'GitHub Actions') { - # Tests for IAT UAT and PAT goes here + # Tests for IAT UAT and PAT goes here - It "Get-GitHubRepository - Gets the authenticated user's repositories (USER_FG_PAT)" { - $repo = Get-GitHubRepository - LogGroup 'Repository' { - Write-Host ($repo | Format-Table | Out-String) + It "Get-GitHubRepository - Gets the authenticated user's repositories" { + $repo = Get-GitHubRepository + LogGroup 'Repository' { + Write-Host ($repo | Format-Table | Out-String) + } + $repo | Should -Not -BeNullOrEmpty } - $repo | Should -Not -BeNullOrEmpty - } - It "Get-GitHubRepository - Gets the authenticated user's public repositories (USER_FG_PAT)" { - $repo = Get-GitHubRepository -Type 'public' - LogGroup 'Repository' { - Write-Host ($repo | Format-Table | Out-String) + It "Get-GitHubRepository - Gets the authenticated user's public repositories" { + $repo = Get-GitHubRepository -Type 'public' + LogGroup 'Repository' { + Write-Host ($repo | Format-Table | Out-String) + } + $repo | Should -Not -BeNullOrEmpty } - $repo | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubRepository - Gets the public repos where the authenticated user is owner (USER_FG_PAT)' { - $repo = Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' - LogGroup 'Repository' { - Write-Host ($repo | Format-Table | Out-String) + It 'Get-GitHubRepository - Gets the public repos where the authenticated user is owner' { + $repo = Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' + LogGroup 'Repository' { + Write-Host ($repo | Format-Table | Out-String) + } + $repo | Should -Not -BeNullOrEmpty } - $repo | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubRepository - Gets a specific repository (USER_FG_PAT)' { - $repo = Get-GitHubRepository -Owner 'PSModule' -Name 'GitHub' - LogGroup 'Repository' { - Write-Host ($repo | Format-Table | Out-String) + It 'Get-GitHubRepository - Gets a specific repository' { + $repo = Get-GitHubRepository -Owner 'PSModule' -Name 'GitHub' + LogGroup 'Repository' { + Write-Host ($repo | Format-Table | Out-String) + } + $repo | Should -Not -BeNullOrEmpty } - $repo | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubRepository - Gets all repositories from a organization (USER_FG_PAT)' { - $repo = Get-GitHubRepository -Owner 'PSModule' - LogGroup 'Repository' { - Write-Host ($repo | Format-Table | Out-String) + It 'Get-GitHubRepository - Gets all repositories from a organization' { + $repo = Get-GitHubRepository -Owner 'PSModule' + LogGroup 'Repository' { + Write-Host ($repo | Format-Table | Out-String) + } + $repo | Should -Not -BeNullOrEmpty } - $repo | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubRepository - Gets all repositories from a user (USER_FG_PAT)' { - $repo = Get-GitHubRepository -Username 'MariusStorhaug' - LogGroup 'Repository' { - Write-Host ($repo | Format-Table | Out-String) + It 'Get-GitHubRepository - Gets all repositories from a user' { + $repo = Get-GitHubRepository -Username 'MariusStorhaug' + LogGroup 'Repository' { + Write-Host ($repo | Format-Table | Out-String) + } + $repo | Should -Not -BeNullOrEmpty } - $repo | Should -Not -BeNullOrEmpty } } } diff --git a/tests/TEMPLATE.ps1 b/tests/TEMPLATE.ps1 index 56d415d8a..0ce26b0a2 100644 --- a/tests/TEMPLATE.ps1 +++ b/tests/TEMPLATE.ps1 @@ -33,7 +33,6 @@ Describe 'Template' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } - # Tests for APP goes here if ($AuthType -eq 'APP') { It 'Connect-GitHubApp - Connects as a GitHub App to ' { From 92b5c97d960e7fd237afc4cce521f85907b038d7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Mar 2025 15:12:56 +0100 Subject: [PATCH 36/60] =?UTF-8?q?=F0=9F=A9=B9=20[Enhance]:=20Add=20BeforeA?= =?UTF-8?q?ll=20setup=20and=20new=20tests=20for=20repository=20creation=20?= =?UTF-8?q?and=20removal=20in=20Repositories.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Repositories.Tests.ps1 | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index f45789441..d5cc910ac 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -15,6 +15,11 @@ [CmdletBinding()] param() +BeforeAll { + $repoSuffix = 'EnvironmentTest' + $environmentName = 'production' + $os = $env:RUNNER_OS +} Describe 'Template' { $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" @@ -43,7 +48,15 @@ Describe 'Template' { if ($Type -ne 'GitHub Actions') { # Tests for IAT UAT and PAT goes here - + It 'New-GitHubRepository - Creates a new repository' { + $guid = [guid]::NewGuid().ToString() + $repo = "$repoSuffix-$guid" + if ($OwnerType -eq 'user') { + New-GitHubRepository -Name $repo -AllowSquashMerge + } else { + New-GitHubRepository -Owner $Owner -Name $repo -AllowSquashMerge + } + } It "Get-GitHubRepository - Gets the authenticated user's repositories" { $repo = Get-GitHubRepository LogGroup 'Repository' { @@ -86,6 +99,9 @@ Describe 'Template' { } $repo | Should -Not -BeNullOrEmpty } + It 'Remove-GitHubRepository - Removes all repositories' { + Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + } } } } From 6d3e55f10e4ceffab401dbefd391e80d21f2c2e8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Mar 2025 20:34:57 +0100 Subject: [PATCH 37/60] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Update=20reposito?= =?UTF-8?q?ry=20name=20generation=20to=20include=20operating=20system=20id?= =?UTF-8?q?entifier=20for=20uniqueness?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Repositories.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index d5cc910ac..ad5eeaf9f 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -50,7 +50,7 @@ Describe 'Template' { # Tests for IAT UAT and PAT goes here It 'New-GitHubRepository - Creates a new repository' { $guid = [guid]::NewGuid().ToString() - $repo = "$repoSuffix-$guid" + $repo = "$repoSuffix-$os-$guid" if ($OwnerType -eq 'user') { New-GitHubRepository -Name $repo -AllowSquashMerge } else { From 5dde2421e23ef5b51cb7b8124dd5f85cd0c45f6f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Mar 2025 20:53:52 +0100 Subject: [PATCH 38/60] =?UTF-8?q?=F0=9F=A9=B9=20[Refactor]:=20Rename=20rep?= =?UTF-8?q?ository=20suffix=20to=20prefix=20and=20standardize=20variable?= =?UTF-8?q?=20usage=20for=20improved=20clarity=20in=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Repositories.Tests.ps1 | 56 ++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index ad5eeaf9f..b88908729 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -16,7 +16,7 @@ param() BeforeAll { - $repoSuffix = 'EnvironmentTest' + $repoPrefix = 'EnvironmentTest' $environmentName = 'production' $os = $env:RUNNER_OS } @@ -29,6 +29,8 @@ Describe 'Template' { LogGroup 'Context' { Write-Host ($context | Format-List | Out-String) } + $guid = [guid]::NewGuid().ToString() + $repo = "$repoPrefix-$os-$guid" } AfterAll { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent @@ -49,8 +51,6 @@ Describe 'Template' { # Tests for IAT UAT and PAT goes here It 'New-GitHubRepository - Creates a new repository' { - $guid = [guid]::NewGuid().ToString() - $repo = "$repoSuffix-$os-$guid" if ($OwnerType -eq 'user') { New-GitHubRepository -Name $repo -AllowSquashMerge } else { @@ -58,25 +58,25 @@ Describe 'Template' { } } It "Get-GitHubRepository - Gets the authenticated user's repositories" { - $repo = Get-GitHubRepository - LogGroup 'Repository' { - Write-Host ($repo | Format-Table | Out-String) + $repos = Get-GitHubRepository + LogGroup 'Repositories' { + Write-Host ($repos | Format-Table | Out-String) } - $repo | Should -Not -BeNullOrEmpty + $repos | Should -Not -BeNullOrEmpty } It "Get-GitHubRepository - Gets the authenticated user's public repositories" { - $repo = Get-GitHubRepository -Type 'public' - LogGroup 'Repository' { - Write-Host ($repo | Format-Table | Out-String) + $repos = Get-GitHubRepository -Type 'public' + LogGroup 'Repositories' { + Write-Host ($repos | Format-Table | Out-String) } - $repo | Should -Not -BeNullOrEmpty + $repos | Should -Not -BeNullOrEmpty } It 'Get-GitHubRepository - Gets the public repos where the authenticated user is owner' { - $repo = Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' - LogGroup 'Repository' { - Write-Host ($repo | Format-Table | Out-String) + $repos = Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' + LogGroup 'Repositories' { + Write-Host ($repos | Format-Table | Out-String) } - $repo | Should -Not -BeNullOrEmpty + $repos | Should -Not -BeNullOrEmpty } It 'Get-GitHubRepository - Gets a specific repository' { $repo = Get-GitHubRepository -Owner 'PSModule' -Name 'GitHub' @@ -86,21 +86,29 @@ Describe 'Template' { $repo | Should -Not -BeNullOrEmpty } It 'Get-GitHubRepository - Gets all repositories from a organization' { - $repo = Get-GitHubRepository -Owner 'PSModule' - LogGroup 'Repository' { - Write-Host ($repo | Format-Table | Out-String) + $repos = Get-GitHubRepository -Owner 'PSModule' + LogGroup 'Repositories' { + Write-Host ($repos | Format-Table | Out-String) } - $repo | Should -Not -BeNullOrEmpty + $repos | Should -Not -BeNullOrEmpty } It 'Get-GitHubRepository - Gets all repositories from a user' { - $repo = Get-GitHubRepository -Username 'MariusStorhaug' - LogGroup 'Repository' { - Write-Host ($repo | Format-Table | Out-String) + $repos = Get-GitHubRepository -Username 'MariusStorhaug' + LogGroup 'Repositories' { + Write-Host ($repos | Format-Table | Out-String) } - $repo | Should -Not -BeNullOrEmpty + $repos | Should -Not -BeNullOrEmpty } It 'Remove-GitHubRepository - Removes all repositories' { - Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + if ($OwnerType -eq 'user') { + $repos = Get-GitHubRepository -Name $repo + } else { + $repos = Get-GitHubRepository -Owner $Owner -Name $repo + } + LogGroup 'Repositories' { + Write-Host ($repos | Format-Table | Out-String) + } + $repos | Remove-GitHubRepository -Confirm:$false } } } From 87570e0630d88a70612875cfea0284eed9156340 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Mar 2025 20:56:41 +0100 Subject: [PATCH 39/60] =?UTF-8?q?=F0=9F=A9=B9=20[Enhance]:=20Update=20para?= =?UTF-8?q?meter=20attributes=20in=20Remove-GitHubRepository=20to=20suppor?= =?UTF-8?q?t=20pipeline=20input=20for=20improved=20usability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/Remove-GitHubRepository.ps1 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/functions/public/Repositories/Repositories/Remove-GitHubRepository.ps1 b/src/functions/public/Repositories/Repositories/Remove-GitHubRepository.ps1 index 60d15a822..61673dc4c 100644 --- a/src/functions/public/Repositories/Repositories/Remove-GitHubRepository.ps1 +++ b/src/functions/public/Repositories/Repositories/Remove-GitHubRepository.ps1 @@ -20,13 +20,19 @@ [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] [Alias('Organization')] [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] [string] $Name, # The context to run the command in. Used to get the details for the API call. From 86b9fff13979098e2713cae45bc254082dbc008e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Mar 2025 21:06:12 +0100 Subject: [PATCH 40/60] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Update=20Get-GitH?= =?UTF-8?q?ubRepository=20call=20to=20use=20Username=20parameter=20for=20a?= =?UTF-8?q?ccurate=20repository=20retrieval?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Repositories.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index b88908729..6f1acead4 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -101,7 +101,7 @@ Describe 'Template' { } It 'Remove-GitHubRepository - Removes all repositories' { if ($OwnerType -eq 'user') { - $repos = Get-GitHubRepository -Name $repo + $repos = Get-GitHubRepository -Username $Owner -Name $repo } else { $repos = Get-GitHubRepository -Owner $Owner -Name $repo } From 197cb326b89a98638de9c19bd5b1398191511ded Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Mar 2025 21:18:10 +0100 Subject: [PATCH 41/60] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Replace=20Context?= =?UTF-8?q?=20with=20Get-Context=20in=20tests=20and=20simplify=20repositor?= =?UTF-8?q?y=20retrieval=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Repositories.Tests.ps1 | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 6f1acead4..c39e4b268 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -23,7 +23,7 @@ BeforeAll { Describe 'Template' { $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" - Context 'As using on ' -ForEach $authCases { + Get-Context 'As using on ' -ForEach $authCases { BeforeAll { $context = Connect-GitHubAccount @connectParams -PassThru -Silent LogGroup 'Context' { @@ -100,11 +100,7 @@ Describe 'Template' { $repos | Should -Not -BeNullOrEmpty } It 'Remove-GitHubRepository - Removes all repositories' { - if ($OwnerType -eq 'user') { - $repos = Get-GitHubRepository -Username $Owner -Name $repo - } else { - $repos = Get-GitHubRepository -Owner $Owner -Name $repo - } + $repos = Get-GitHubRepository -Username $Owner -Name $repo LogGroup 'Repositories' { Write-Host ($repos | Format-Table | Out-String) } From a7a89261988f477a09a969a902bd9ff8c722537b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Mar 2025 21:27:26 +0100 Subject: [PATCH 42/60] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Replace=20Get-Con?= =?UTF-8?q?text=20with=20Context=20in=20tests=20for=20improved=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Repositories.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index c39e4b268..1319818c6 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -23,7 +23,7 @@ BeforeAll { Describe 'Template' { $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" - Get-Context 'As using on ' -ForEach $authCases { + Context 'As using on ' -ForEach $authCases { BeforeAll { $context = Connect-GitHubAccount @connectParams -PassThru -Silent LogGroup 'Context' { From 5fbeb7da6a6a56cf020c806782bde17711b885b9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Mar 2025 21:33:11 +0100 Subject: [PATCH 43/60] [Fix]: Update Get-GitHubRepository call to use Owner parameter for accurate repository retrieval --- tests/Repositories.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 1319818c6..8244661be 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -100,7 +100,7 @@ Describe 'Template' { $repos | Should -Not -BeNullOrEmpty } It 'Remove-GitHubRepository - Removes all repositories' { - $repos = Get-GitHubRepository -Username $Owner -Name $repo + $repos = Get-GitHubRepository -Owner $Owner -Name $repo LogGroup 'Repositories' { Write-Host ($repos | Format-Table | Out-String) } From d9ee7e3c0a437d0bfb71ce8f5c1ddb73e1ef2dac Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Mar 2025 21:43:43 +0100 Subject: [PATCH 44/60] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Update=20test=20o?= =?UTF-8?q?utput=20formatting=20in=20Get-GitHubRepository=20tests=20from?= =?UTF-8?q?=20Format-Table=20to=20Format-List=20for=20improved=20readabili?= =?UTF-8?q?ty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Repositories.Tests.ps1 | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 8244661be..6e795e320 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -60,51 +60,53 @@ Describe 'Template' { It "Get-GitHubRepository - Gets the authenticated user's repositories" { $repos = Get-GitHubRepository LogGroup 'Repositories' { - Write-Host ($repos | Format-Table | Out-String) + Write-Host ($repos | Format-List | Out-String) } $repos | Should -Not -BeNullOrEmpty } It "Get-GitHubRepository - Gets the authenticated user's public repositories" { $repos = Get-GitHubRepository -Type 'public' LogGroup 'Repositories' { - Write-Host ($repos | Format-Table | Out-String) + Write-Host ($repos | Format-List | Out-String) } $repos | Should -Not -BeNullOrEmpty } It 'Get-GitHubRepository - Gets the public repos where the authenticated user is owner' { $repos = Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' LogGroup 'Repositories' { - Write-Host ($repos | Format-Table | Out-String) + Write-Host ($repos | Format-List | Out-String) } $repos | Should -Not -BeNullOrEmpty } It 'Get-GitHubRepository - Gets a specific repository' { $repo = Get-GitHubRepository -Owner 'PSModule' -Name 'GitHub' LogGroup 'Repository' { - Write-Host ($repo | Format-Table | Out-String) + Write-Host ($repo | Format-List | Out-String) } $repo | Should -Not -BeNullOrEmpty } It 'Get-GitHubRepository - Gets all repositories from a organization' { $repos = Get-GitHubRepository -Owner 'PSModule' LogGroup 'Repositories' { - Write-Host ($repos | Format-Table | Out-String) + Write-Host ($repos | Format-List | Out-String) } $repos | Should -Not -BeNullOrEmpty } It 'Get-GitHubRepository - Gets all repositories from a user' { $repos = Get-GitHubRepository -Username 'MariusStorhaug' LogGroup 'Repositories' { - Write-Host ($repos | Format-Table | Out-String) + Write-Host ($repos | Format-List | Out-String) } $repos | Should -Not -BeNullOrEmpty } It 'Remove-GitHubRepository - Removes all repositories' { $repos = Get-GitHubRepository -Owner $Owner -Name $repo LogGroup 'Repositories' { - Write-Host ($repos | Format-Table | Out-String) + Write-Host ($repos | Format-List | Out-String) + } + $repos | ForEach-Object { + Remove-GitHubRepository -Owner $_.owner.login -Name $_.name -Confirm:$false } - $repos | Remove-GitHubRepository -Confirm:$false } } } From d2d487787d4e6e3748283aeb3ff11d90b51a8e6a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Mar 2025 22:08:42 +0100 Subject: [PATCH 45/60] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Replace=20Get-Con?= =?UTF-8?q?text=20with=20Context=20in=20tests=20for=20improved=20clarity?= =?UTF-8?q?=20and=20ensure=20repository=20retrieval=20checks=20for=20non-e?= =?UTF-8?q?mpty=20results?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Repositories.Tests.ps1 | 38 +++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 6e795e320..4466e0f55 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -23,7 +23,7 @@ BeforeAll { Describe 'Template' { $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" - Context 'As using on ' -ForEach $authCases { + Get-Context 'As using on ' -ForEach $authCases { BeforeAll { $context = Connect-GitHubAccount @connectParams -PassThru -Silent LogGroup 'Context' { @@ -57,26 +57,28 @@ Describe 'Template' { New-GitHubRepository -Owner $Owner -Name $repo -AllowSquashMerge } } - It "Get-GitHubRepository - Gets the authenticated user's repositories" { - $repos = Get-GitHubRepository - LogGroup 'Repositories' { - Write-Host ($repos | Format-List | Out-String) + if ($OwnerType -eq 'user') { + It "Get-GitHubRepository - Gets the authenticated user's repositories" { + $repos = Get-GitHubRepository + LogGroup 'Repositories' { + Write-Host ($repos | Format-List | Out-String) + } + $repos | Should -Not -BeNullOrEmpty } - $repos | Should -Not -BeNullOrEmpty - } - It "Get-GitHubRepository - Gets the authenticated user's public repositories" { - $repos = Get-GitHubRepository -Type 'public' - LogGroup 'Repositories' { - Write-Host ($repos | Format-List | Out-String) + It "Get-GitHubRepository - Gets the authenticated user's public repositories" { + $repos = Get-GitHubRepository -Type 'public' + LogGroup 'Repositories' { + Write-Host ($repos | Format-List | Out-String) + } + $repos | Should -Not -BeNullOrEmpty } - $repos | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubRepository - Gets the public repos where the authenticated user is owner' { - $repos = Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' - LogGroup 'Repositories' { - Write-Host ($repos | Format-List | Out-String) + It 'Get-GitHubRepository - Gets the public repos where the authenticated user is owner' { + $repos = Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' + LogGroup 'Repositories' { + Write-Host ($repos | Format-List | Out-String) + } + $repos | Should -Not -BeNullOrEmpty } - $repos | Should -Not -BeNullOrEmpty } It 'Get-GitHubRepository - Gets a specific repository' { $repo = Get-GitHubRepository -Owner 'PSModule' -Name 'GitHub' From 0298d62c19ad6bdd8f6615f7115147db012f8d8e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 09:05:11 +0100 Subject: [PATCH 46/60] [Fix]: Update repository prefix in tests for consistency and clarity --- tests/Repositories.Tests.ps1 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 4466e0f55..4a7df3db3 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -16,10 +16,10 @@ param() BeforeAll { - $repoPrefix = 'EnvironmentTest' - $environmentName = 'production' + $repoPrefix = 'RepositoryTest' $os = $env:RUNNER_OS } + Describe 'Template' { $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" @@ -46,9 +46,7 @@ Describe 'Template' { } } - # Tests for runners goes here if ($Type -ne 'GitHub Actions') { - # Tests for IAT UAT and PAT goes here It 'New-GitHubRepository - Creates a new repository' { if ($OwnerType -eq 'user') { From d1d95aac54daaa61a4c42a5a4c613df42399f622 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 09:07:12 +0100 Subject: [PATCH 47/60] [Fix]: Replace Get-Context with Context in template tests for improved clarity --- tests/Repositories.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 4a7df3db3..382abe83c 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -23,7 +23,7 @@ BeforeAll { Describe 'Template' { $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" - Get-Context 'As using on ' -ForEach $authCases { + Context 'As using on ' -ForEach $authCases { BeforeAll { $context = Connect-GitHubAccount @connectParams -PassThru -Silent LogGroup 'Context' { From 970bff31068dc4b6fcea3f887320b60796a165b6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 09:44:59 +0100 Subject: [PATCH 48/60] [Fix]: Add test to verify Get-GitHubRepository returns no repositories after removal --- tests/Repositories.Tests.ps1 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 382abe83c..372063be1 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -108,6 +108,17 @@ Describe 'Template' { Remove-GitHubRepository -Owner $_.owner.login -Name $_.name -Confirm:$false } } + It 'Get-GitHubRepository - Gets none repositories after removal' { + if ($OwnerType -eq 'user') { + $repos = Get-GitHubRepository -Username $Owner + } else { + $repos = Get-GitHubRepository -Owner $Owner + } + LogGroup 'Repositories' { + Write-Host ($repos | Format-List | Out-String) + } + $repos | Should -BeNullOrEmpty + } } } } From 917942dc465d39826cf11b2c2952722a36f5feb1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 09:46:03 +0100 Subject: [PATCH 49/60] [Fix]: Remove SkipTest comments for Get-GitHubRepository, New-GitHubRepository, and Remove-GitHubRepository functions to indicate readiness for future tests --- .../public/Repositories/Repositories/Get-GitHubRepository.ps1 | 2 -- .../public/Repositories/Repositories/New-GitHubRepository.ps1 | 2 -- .../Repositories/Repositories/Remove-GitHubRepository.ps1 | 2 -- 3 files changed, 6 deletions(-) diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepository.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepository.ps1 index e8c55d0fa..185abd0a4 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepository.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepository.ps1 @@ -253,5 +253,3 @@ filter Get-GitHubRepository { Write-Debug "[$stackPath] - End" } } - -#SkipTest:FunctionTest:Will add a test for this function in a future PR diff --git a/src/functions/public/Repositories/Repositories/New-GitHubRepository.ps1 b/src/functions/public/Repositories/Repositories/New-GitHubRepository.ps1 index e7951ff8c..e037532e6 100644 --- a/src/functions/public/Repositories/Repositories/New-GitHubRepository.ps1 +++ b/src/functions/public/Repositories/Repositories/New-GitHubRepository.ps1 @@ -443,5 +443,3 @@ filter New-GitHubRepository { Write-Debug "[$stackPath] - End" } } - -#SkipTest:FunctionTest:Will add a test for this function in a future PR diff --git a/src/functions/public/Repositories/Repositories/Remove-GitHubRepository.ps1 b/src/functions/public/Repositories/Repositories/Remove-GitHubRepository.ps1 index 61673dc4c..7b4456d55 100644 --- a/src/functions/public/Repositories/Repositories/Remove-GitHubRepository.ps1 +++ b/src/functions/public/Repositories/Repositories/Remove-GitHubRepository.ps1 @@ -66,5 +66,3 @@ Write-Debug "[$stackPath] - End" } } - -#SkipTest:FunctionTest:Will add a test for this function in a future PR From 83c3ad26706e765f8672819a6ce10d77f67029f7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 10:44:07 +0100 Subject: [PATCH 50/60] [Fix]: Remove commented-out test runners in User.Tests and add Organizations.Tests for GitHub organization functionalities --- tests/Organization.Tests.ps1 | 231 ---------------------------------- tests/Organizations.Tests.ps1 | 108 ++++++++++++++++ tests/User.Tests.ps1 | 3 - 3 files changed, 108 insertions(+), 234 deletions(-) delete mode 100644 tests/Organization.Tests.ps1 create mode 100644 tests/Organizations.Tests.ps1 diff --git a/tests/Organization.Tests.ps1 b/tests/Organization.Tests.ps1 deleted file mode 100644 index 7270407f4..000000000 --- a/tests/Organization.Tests.ps1 +++ /dev/null @@ -1,231 +0,0 @@ -#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' } - -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSUseDeclaredVarsMoreThanAssignments', '', - Justification = 'Pester grouping syntax: known issue.' -)] -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingConvertToSecureStringWithPlainText', '', - Justification = 'Used to create a secure string for testing.' -)] -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', - Justification = 'Log outputs to GitHub Actions logs.' -)] -[CmdletBinding()] -param() - -Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } -} - -Describe 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Organization' { - It 'Get-GitHubOrganization - Gets the organizations for the authenticated user (ORG_FG_PAT)' { - { Get-GitHubOrganization } | Should -Not -Throw - } - It 'Get-GitHubOrganization - Gets a specific organization (ORG_FG_PAT)' { - { Get-GitHubOrganization -Organization 'psmodule-test-org2' } | Should -Not -Throw - } - It "Get-GitHubOrganization - List public organizations for the user 'psmodule-user'. (ORG_FG_PAT)" { - { Get-GitHubOrganization -Username 'psmodule-user' } | Should -Not -Throw - } - It 'Get-GitHubOrganizationMember - Gets the members of a specific organization (ORG_FG_PAT)' { - $members = Get-GitHubOrganizationMember -Organization 'psmodule-test-org2' - $members.login | Should -Contain 'psmodule-user' - } - It 'Update-GitHubOrganization - Sets the organization configuration (ORG_FG_PAT)' { - { Update-GitHubOrganization -Organization 'psmodule-test-org2' -Company 'ABC' } | Should -Not -Throw - { - $email = (New-Guid).Guid + '@psmodule.io' - Update-GitHubOrganization -Organization 'psmodule-test-org2' -BillingEmail $email - } | Should -Not -Throw - { - $email = (New-Guid).Guid + '@psmodule.io' - Update-GitHubOrganization -Organization 'psmodule-test-org2' -Email $email - } | Should -Not -Throw - { - Update-GitHubOrganization -Organization 'psmodule-test-org2' -TwitterUsername 'PSModule' - } | Should -Not -Throw - { Update-GitHubOrganization -Organization 'psmodule-test-org2' -Location 'USA' } | Should -Not -Throw - { Update-GitHubOrganization -Organization 'psmodule-test-org2' -Description 'Test Organization' } | Should -Not -Throw - { Update-GitHubOrganization -Organization 'psmodule-test-org2' -DefaultRepositoryPermission read } | Should -Not -Throw - { Update-GitHubOrganization -Organization 'psmodule-test-org2' -MembersCanCreateRepositories $true } | Should -Not -Throw - { Update-GitHubOrganization -Organization 'psmodule-test-org2' -Blog 'https://psmodule.io' } | Should -Not -Throw - } - It 'New-GitHubOrganizationInvitation - Invites a user to an organization (ORG_FG_PAT)' { - { - $email = (New-Guid).Guid + '@psmodule.io' - New-GitHubOrganizationInvitation -Organization 'psmodule-test-org2' -Email $email -Role 'admin' - } | Should -Not -Throw - } - It 'Get-GitHubOrganizationPendingInvitation - Gets the pending invitations for a specific organization (ORG_FG_PAT)' { - { Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org2' } | Should -Not -Throw - { Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org2' -Role 'admin' } | Should -Not -Throw - { Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org2' -InvitationSource 'member' } | Should -Not -Throw - } - It 'Remove-GitHubOrganizationInvitation - Removes a user invitation from an organization (ORG_FG_PAT)' { - { - $invitation = Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org2' | Select-Object -First 1 - Remove-GitHubOrganizationInvitation -Organization 'psmodule-test-org2' -ID $invitation.id - } | Should -Not -Throw - } - } -} - -Describe 'As a user - Classic PAT token (PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_PAT - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Organization' { - It 'Get-GitHubOrganization - Gets the organizations for the authenticated user (PAT)' { - { Get-GitHubOrganization } | Should -Not -Throw - } - It 'Get-GitHubOrganization - Gets a specific organization (PAT)' { - { Get-GitHubOrganization -Organization 'psmodule-test-org2' } | Should -Not -Throw - } - It "Get-GitHubOrganization - List public organizations for the user 'psmodule-user'. (PAT)" { - { Get-GitHubOrganization -Username 'psmodule-user' } | Should -Not -Throw - } - It 'Get-GitHubOrganizationMember - Gets the members of a specific organization (PAT)' { - $members = Get-GitHubOrganizationMember -Organization 'psmodule-test-org2' - $members.login | Should -Contain 'psmodule-user' - } - } -} - -Describe 'As GitHub Actions (GHA)' { - BeforeAll { - Connect-GitHubAccount - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } -} - -Describe 'As a GitHub App - Enterprise (APP_ENT)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Organization' { - BeforeAll { - Connect-GitHubApp -Organization 'psmodule-test-org3' -Default - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - It 'Get-GitHubOrganization - Gets a specific organization (APP_ENT)' { - { Get-GitHubOrganization -Organization 'psmodule-test-org3' } | Should -Not -Throw - } - It 'Get-GitHubAppInstallation - Gets the GitHub App installations on the organization (APP_ENT)' { - $installations = Get-GitHubAppInstallation -Organization 'psmodule-test-org3' - Write-Verbose ($installations | Format-Table | Out-String) -Verbose - $installations | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubOrganizationMember - Gets the members of a specific organization (APP_ENT)' { - $members = Get-GitHubOrganizationMember -Organization 'psmodule-test-org3' - $members.login | Should -Contain 'MariusStorhaug' - } - It 'Update-GitHubOrganization - Sets the organization configuration (APP_ENT)' { - { Update-GitHubOrganization -Organization 'psmodule-test-org3' -Company 'ABC' } | Should -Not -Throw - { - $email = (New-Guid).Guid + '@psmodule.io' - Update-GitHubOrganization -Organization 'psmodule-test-org3' -BillingEmail $email - } | Should -Not -Throw - { - $email = (New-Guid).Guid + '@psmodule.io' - Update-GitHubOrganization -Organization 'psmodule-test-org3' -Email $email - } | Should -Not -Throw - { - Update-GitHubOrganization -Organization 'psmodule-test-org3' -TwitterUsername 'PSModule' - } | Should -Not -Throw - { Update-GitHubOrganization -Organization 'psmodule-test-org3' -Location 'USA' } | Should -Not -Throw - { Update-GitHubOrganization -Organization 'psmodule-test-org3' -Description 'Test Organization' } | Should -Not -Throw - { Update-GitHubOrganization -Organization 'psmodule-test-org3' -DefaultRepositoryPermission read } | Should -Not -Throw - { Update-GitHubOrganization -Organization 'psmodule-test-org3' -MembersCanCreateRepositories $true } | Should -Not -Throw - { Update-GitHubOrganization -Organization 'psmodule-test-org3' -Blog 'https://psmodule.io' } | Should -Not -Throw - } - } -} - -Describe 'As a GitHub App - Organization (APP_ORG)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Organization' { - BeforeAll { - Connect-GitHubApp -Organization 'psmodule-test-org' -Default - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - It 'Get-GitHubOrganization - Gets a specific organization (APP_ORG)' { - { Get-GitHubOrganization -Organization 'psmodule-test-org' } | Should -Not -Throw - } - It 'Get-GitHubAppInstallation - Gets the GitHub App installations on the organization (APP_ORG)' { - $installations = Get-GitHubAppInstallation -Organization 'psmodule-test-org' - Write-Verbose ($installations | Format-Table | Out-String) -Verbose - $installations | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubOrganizationMember - Gets the members of a specific organization (APP_ORG)' { - $members = Get-GitHubOrganizationMember -Organization 'psmodule-test-org' - $members.login | Should -Contain 'MariusStorhaug' - } - It 'Update-GitHubOrganization - Sets the organization configuration (APP_ORG)' { - { Update-GitHubOrganization -Organization 'psmodule-test-org' -Company 'ABC' } | Should -Not -Throw - { - $email = (New-Guid).Guid + '@psmodule.io' - Update-GitHubOrganization -Organization 'psmodule-test-org' -BillingEmail $email - } | Should -Not -Throw - { - $email = (New-Guid).Guid + '@psmodule.io' - Update-GitHubOrganization -Organization 'psmodule-test-org' -Email $email - } | Should -Not -Throw - { - Update-GitHubOrganization -Organization 'psmodule-test-org' -TwitterUsername 'PSModule' - } | Should -Not -Throw - { Update-GitHubOrganization -Organization 'psmodule-test-org' -Location 'USA' } | Should -Not -Throw - { Update-GitHubOrganization -Organization 'psmodule-test-org' -Description 'Test Organization' } | Should -Not -Throw - { Update-GitHubOrganization -Organization 'psmodule-test-org' -DefaultRepositoryPermission read } | Should -Not -Throw - { Update-GitHubOrganization -Organization 'psmodule-test-org' -MembersCanCreateRepositories $true } | Should -Not -Throw - { Update-GitHubOrganization -Organization 'psmodule-test-org' -Blog 'https://psmodule.io' } | Should -Not -Throw - } - It 'New-GitHubOrganizationInvitation - Invites a user to an organization (APP_ORG)' { - { - $email = (New-Guid).Guid + '@psmodule.io' - New-GitHubOrganizationInvitation -Organization 'psmodule-test-org' -Email $email -Role 'admin' - } | Should -Not -Throw - } - It 'Get-GitHubOrganizationPendingInvitation - Gets the pending invitations for a specific organization (APP_ORG)' { - { Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org' } | Should -Not -Throw - { Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org' -Role 'admin' } | Should -Not -Throw - { Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org' -InvitationSource 'member' } | Should -Not -Throw - } - It 'Remove-GitHubOrganizationInvitation - Removes a user invitation from an organization (APP_ORG)' { - { - $invitation = Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org' | Select-Object -First 1 - Remove-GitHubOrganizationInvitation -Organization 'psmodule-test-org' -ID $invitation.id - } | Should -Not -Throw - } - } -} diff --git a/tests/Organizations.Tests.ps1 b/tests/Organizations.Tests.ps1 new file mode 100644 index 000000000..4bad4a3f2 --- /dev/null +++ b/tests/Organizations.Tests.ps1 @@ -0,0 +1,108 @@ +#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' } + +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', '', + Justification = 'Pester grouping syntax: known issue.' +)] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingConvertToSecureStringWithPlainText', '', + Justification = 'Used to create a secure string for testing.' +)] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', + Justification = 'Log outputs to GitHub Actions logs.' +)] +[CmdletBinding()] +param() + + +BeforeAll { + # DEFAULTS ACCROSS ALL TESTS +} + +Describe 'Organizations' { + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" + + Context 'As using on ' -ForEach $authCases { + BeforeAll { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + } + + # Tests for APP goes here + if ($AuthType -eq 'APP') { + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } + } + + # Tests for runners goes here + if ($Type -eq 'GitHub Actions') {} + + It 'Get-GitHubOrganization - Gets a specific organization' { + { Get-GitHubOrganization -Organization 'psmodule-test-org2' } | Should -Not -Throw + } + It "Get-GitHubOrganization - List public organizations for the user 'psmodule-user'" { + { Get-GitHubOrganization -Username 'psmodule-user' } | Should -Not -Throw + } + It 'Get-GitHubOrganizationMember - Gets the members of a specific organization' { + $members = Get-GitHubOrganizationMember -Organization 'psmodule-test-org2' + $members.login | Should -Contain 'psmodule-user' + } + + # Tests for IAT UAT and PAT goes here + if ($OwnerType -eq 'user') { + It 'Get-GitHubOrganization - Gets the organizations for the authenticated user' { + { Get-GitHubOrganization } | Should -Not -Throw + } + } + + if ($OwnerType -eq 'organization') { + It 'Update-GitHubOrganization - Sets the organization configuration' { + { Update-GitHubOrganization -Organization $owner -Company 'ABC' } | Should -Not -Throw + { + $email = (New-Guid).Guid + '@psmodule.io' + Update-GitHubOrganization -Organization $owner -BillingEmail $email + } | Should -Not -Throw + { + $email = (New-Guid).Guid + '@psmodule.io' + Update-GitHubOrganization -Organization $owner -Email $email + } | Should -Not -Throw + { Update-GitHubOrganization -Organization $owner -TwitterUsername 'PSModule' } | Should -Not -Throw + { Update-GitHubOrganization -Organization $owner -Location 'USA' } | Should -Not -Throw + { Update-GitHubOrganization -Organization $owner -Description 'Test Organization' } | Should -Not -Throw + { Update-GitHubOrganization -Organization $owner -DefaultRepositoryPermission read } | Should -Not -Throw + { Update-GitHubOrganization -Organization $owner -MembersCanCreateRepositories $true } | Should -Not -Throw + { Update-GitHubOrganization -Organization $owner -Blog 'https://psmodule.io' } | Should -Not -Throw + } + } + + Context 'Invitations' { + It 'New-GitHubOrganizationInvitation - Invites a user to an organization' { + { + $email = (New-Guid).Guid + '@psmodule.io' + New-GitHubOrganizationInvitation -Organization $owner -Email $email -Role 'admin' + } | Should -Not -Throw + } + It 'Get-GitHubOrganizationPendingInvitation - Gets the pending invitations for a specific organization' { + { Get-GitHubOrganizationPendingInvitation -Organization $owner } | Should -Not -Throw + { Get-GitHubOrganizationPendingInvitation -Organization $owner -Role 'admin' } | Should -Not -Throw + { Get-GitHubOrganizationPendingInvitation -Organization $owner -InvitationSource 'member' } | Should -Not -Throw + } + It 'Remove-GitHubOrganizationInvitation - Removes a user invitation from an organization' { + { + $invitation = Get-GitHubOrganizationPendingInvitation -Organization $owner | Select-Object -First 1 + Remove-GitHubOrganizationInvitation -Organization $owner -ID $invitation.id + } | Should -Not -Throw + } + } + } +} diff --git a/tests/User.Tests.ps1 b/tests/User.Tests.ps1 index 12b022ec8..061e086d1 100644 --- a/tests/User.Tests.ps1 +++ b/tests/User.Tests.ps1 @@ -39,9 +39,6 @@ Context 'User' { } } - # Tests for runners goes here - if ($Type -eq 'GitHub Actions') {} - # Tests for IAT UAT and PAT goes here It 'Get-GitHubUser - Get the specified user' { { Get-GitHubUser -Username 'Octocat' } | Should -Not -Throw From 246234e9ec540a666e07ed267d565a596e936e1c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 10:56:59 +0100 Subject: [PATCH 51/60] Fix: Rename variable for repository prefix to improve clarity and consistency in tests --- tests/Repositories.Tests.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 372063be1..6f648d357 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -16,7 +16,7 @@ param() BeforeAll { - $repoPrefix = 'RepositoryTest' + $testPrefix = 'RepositoryTest' $os = $env:RUNNER_OS } @@ -30,7 +30,8 @@ Describe 'Template' { Write-Host ($context | Format-List | Out-String) } $guid = [guid]::NewGuid().ToString() - $repo = "$repoPrefix-$os-$guid" + $repoPrefix = "$testPrefix-$os" + $repo = "$repoPrefix-$guid" } AfterAll { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent @@ -110,9 +111,9 @@ Describe 'Template' { } It 'Get-GitHubRepository - Gets none repositories after removal' { if ($OwnerType -eq 'user') { - $repos = Get-GitHubRepository -Username $Owner + $repos = Get-GitHubRepository -Username $Owner | Where-Object { $_.name -like "$repoPrefix*" } } else { - $repos = Get-GitHubRepository -Owner $Owner + $repos = Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoPrefix*" } } LogGroup 'Repositories' { Write-Host ($repos | Format-List | Out-String) From ebd9bca6eeebfb63ac0a4fd2d2a9c6b79e5ac63e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 11:22:53 +0100 Subject: [PATCH 52/60] Fix: Update tests for Get-GitHubOrganization to ensure valid organization retrieval and improve logging --- tests/Organizations.Tests.ps1 | 94 ++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/tests/Organizations.Tests.ps1 b/tests/Organizations.Tests.ps1 index 4bad4a3f2..1209ffafc 100644 --- a/tests/Organizations.Tests.ps1 +++ b/tests/Organizations.Tests.ps1 @@ -47,15 +47,19 @@ Describe 'Organizations' { # Tests for runners goes here if ($Type -eq 'GitHub Actions') {} - It 'Get-GitHubOrganization - Gets a specific organization' { - { Get-GitHubOrganization -Organization 'psmodule-test-org2' } | Should -Not -Throw + It "Get-GitHubOrganization - Gets a specific organization 'PSModule'" { + $organization = Get-GitHubOrganization -Organization 'PSModule' + LogGroup 'Organization' { + Write-Host ($organization | Format-Table | Out-String) + } + $organization | Should -Not -BeNullOrEmpty } It "Get-GitHubOrganization - List public organizations for the user 'psmodule-user'" { - { Get-GitHubOrganization -Username 'psmodule-user' } | Should -Not -Throw - } - It 'Get-GitHubOrganizationMember - Gets the members of a specific organization' { - $members = Get-GitHubOrganizationMember -Organization 'psmodule-test-org2' - $members.login | Should -Contain 'psmodule-user' + $organizations = Get-GitHubOrganization -Username 'psmodule-user' + LogGroup 'Organization' { + Write-Host ($organizations | Format-Table | Out-String) + } + $organizations | Should -Not -BeNullOrEmpty } # Tests for IAT UAT and PAT goes here @@ -65,44 +69,44 @@ Describe 'Organizations' { } } - if ($OwnerType -eq 'organization') { - It 'Update-GitHubOrganization - Sets the organization configuration' { - { Update-GitHubOrganization -Organization $owner -Company 'ABC' } | Should -Not -Throw - { - $email = (New-Guid).Guid + '@psmodule.io' - Update-GitHubOrganization -Organization $owner -BillingEmail $email - } | Should -Not -Throw - { - $email = (New-Guid).Guid + '@psmodule.io' - Update-GitHubOrganization -Organization $owner -Email $email - } | Should -Not -Throw - { Update-GitHubOrganization -Organization $owner -TwitterUsername 'PSModule' } | Should -Not -Throw - { Update-GitHubOrganization -Organization $owner -Location 'USA' } | Should -Not -Throw - { Update-GitHubOrganization -Organization $owner -Description 'Test Organization' } | Should -Not -Throw - { Update-GitHubOrganization -Organization $owner -DefaultRepositoryPermission read } | Should -Not -Throw - { Update-GitHubOrganization -Organization $owner -MembersCanCreateRepositories $true } | Should -Not -Throw - { Update-GitHubOrganization -Organization $owner -Blog 'https://psmodule.io' } | Should -Not -Throw - } - } + # if ($OwnerType -eq 'organization') { + # It 'Update-GitHubOrganization - Sets the organization configuration' { + # { Update-GitHubOrganization -Organization $owner -Company 'ABC' } | Should -Not -Throw + # { + # $email = (New-Guid).Guid + '@psmodule.io' + # Update-GitHubOrganization -Organization $owner -BillingEmail $email + # } | Should -Not -Throw + # { + # $email = (New-Guid).Guid + '@psmodule.io' + # Update-GitHubOrganization -Organization $owner -Email $email + # } | Should -Not -Throw + # { Update-GitHubOrganization -Organization $owner -TwitterUsername 'PSModule' } | Should -Not -Throw + # { Update-GitHubOrganization -Organization $owner -Location 'USA' } | Should -Not -Throw + # { Update-GitHubOrganization -Organization $owner -Description 'Test Organization' } | Should -Not -Throw + # { Update-GitHubOrganization -Organization $owner -DefaultRepositoryPermission read } | Should -Not -Throw + # { Update-GitHubOrganization -Organization $owner -MembersCanCreateRepositories $true } | Should -Not -Throw + # { Update-GitHubOrganization -Organization $owner -Blog 'https://psmodule.io' } | Should -Not -Throw + # } + # } - Context 'Invitations' { - It 'New-GitHubOrganizationInvitation - Invites a user to an organization' { - { - $email = (New-Guid).Guid + '@psmodule.io' - New-GitHubOrganizationInvitation -Organization $owner -Email $email -Role 'admin' - } | Should -Not -Throw - } - It 'Get-GitHubOrganizationPendingInvitation - Gets the pending invitations for a specific organization' { - { Get-GitHubOrganizationPendingInvitation -Organization $owner } | Should -Not -Throw - { Get-GitHubOrganizationPendingInvitation -Organization $owner -Role 'admin' } | Should -Not -Throw - { Get-GitHubOrganizationPendingInvitation -Organization $owner -InvitationSource 'member' } | Should -Not -Throw - } - It 'Remove-GitHubOrganizationInvitation - Removes a user invitation from an organization' { - { - $invitation = Get-GitHubOrganizationPendingInvitation -Organization $owner | Select-Object -First 1 - Remove-GitHubOrganizationInvitation -Organization $owner -ID $invitation.id - } | Should -Not -Throw - } - } + # Context 'Invitations' { + # It 'New-GitHubOrganizationInvitation - Invites a user to an organization' { + # { + # $email = (New-Guid).Guid + '@psmodule.io' + # New-GitHubOrganizationInvitation -Organization $owner -Email $email -Role 'admin' + # } | Should -Not -Throw + # } + # It 'Get-GitHubOrganizationPendingInvitation - Gets the pending invitations for a specific organization' { + # { Get-GitHubOrganizationPendingInvitation -Organization $owner } | Should -Not -Throw + # { Get-GitHubOrganizationPendingInvitation -Organization $owner -Role 'admin' } | Should -Not -Throw + # { Get-GitHubOrganizationPendingInvitation -Organization $owner -InvitationSource 'member' } | Should -Not -Throw + # } + # It 'Remove-GitHubOrganizationInvitation - Removes a user invitation from an organization' { + # { + # $invitation = Get-GitHubOrganizationPendingInvitation -Organization $owner | Select-Object -First 1 + # Remove-GitHubOrganizationInvitation -Organization $owner -ID $invitation.id + # } | Should -Not -Throw + # } + # } } } From 4394e9e56d32a3d1bd54c14b9c32ff5d22b6a3ef Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 11:37:11 +0100 Subject: [PATCH 53/60] Fix: Remove redundant owner assignment in Get-GitHubOrganization for improved clarity --- src/functions/public/Organization/Get-GitHubOrganization.ps1 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/functions/public/Organization/Get-GitHubOrganization.ps1 b/src/functions/public/Organization/Get-GitHubOrganization.ps1 index c715eac9e..124ff0416 100644 --- a/src/functions/public/Organization/Get-GitHubOrganization.ps1 +++ b/src/functions/public/Organization/Get-GitHubOrganization.ps1 @@ -81,11 +81,6 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" } process { From b53d7b82fbd2919409cf14a27e1ccd6e75cd6244 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 12:34:50 +0100 Subject: [PATCH 54/60] Fix: Remove unnecessary piping in Get-GitHubOrganization for improved performance --- src/functions/public/Organization/Get-GitHubOrganization.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Organization/Get-GitHubOrganization.ps1 b/src/functions/public/Organization/Get-GitHubOrganization.ps1 index 124ff0416..64813db0e 100644 --- a/src/functions/public/Organization/Get-GitHubOrganization.ps1 +++ b/src/functions/public/Organization/Get-GitHubOrganization.ps1 @@ -95,7 +95,7 @@ Get-GitHubAllOrganization -Since $Since -PerPage $PerPage -Context $Context } default { - Get-GitHubMyOrganization -PerPage $PerPage -Context $Context | Get-GitHubOrganizationByName -Context $Context + Get-GitHubMyOrganization -PerPage $PerPage -Context $Context } } } From 83037222196816aff5c08697e0d4c87e14326ce0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 12:53:28 +0100 Subject: [PATCH 55/60] Fix: Uncomment organization configuration tests in Organizations.Tests for improved coverage --- tests/Organizations.Tests.ps1 | 38 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/tests/Organizations.Tests.ps1 b/tests/Organizations.Tests.ps1 index 1209ffafc..650d51760 100644 --- a/tests/Organizations.Tests.ps1 +++ b/tests/Organizations.Tests.ps1 @@ -69,25 +69,25 @@ Describe 'Organizations' { } } - # if ($OwnerType -eq 'organization') { - # It 'Update-GitHubOrganization - Sets the organization configuration' { - # { Update-GitHubOrganization -Organization $owner -Company 'ABC' } | Should -Not -Throw - # { - # $email = (New-Guid).Guid + '@psmodule.io' - # Update-GitHubOrganization -Organization $owner -BillingEmail $email - # } | Should -Not -Throw - # { - # $email = (New-Guid).Guid + '@psmodule.io' - # Update-GitHubOrganization -Organization $owner -Email $email - # } | Should -Not -Throw - # { Update-GitHubOrganization -Organization $owner -TwitterUsername 'PSModule' } | Should -Not -Throw - # { Update-GitHubOrganization -Organization $owner -Location 'USA' } | Should -Not -Throw - # { Update-GitHubOrganization -Organization $owner -Description 'Test Organization' } | Should -Not -Throw - # { Update-GitHubOrganization -Organization $owner -DefaultRepositoryPermission read } | Should -Not -Throw - # { Update-GitHubOrganization -Organization $owner -MembersCanCreateRepositories $true } | Should -Not -Throw - # { Update-GitHubOrganization -Organization $owner -Blog 'https://psmodule.io' } | Should -Not -Throw - # } - # } + if ($OwnerType -eq 'organization') { + It 'Update-GitHubOrganization - Sets the organization configuration' { + { Update-GitHubOrganization -Organization $owner -Company 'ABC' } | Should -Not -Throw + { + $email = (New-Guid).Guid + '@psmodule.io' + Update-GitHubOrganization -Organization $owner -BillingEmail $email + } | Should -Not -Throw + { + $email = (New-Guid).Guid + '@psmodule.io' + Update-GitHubOrganization -Organization $owner -Email $email + } | Should -Not -Throw + { Update-GitHubOrganization -Organization $owner -TwitterUsername 'PSModule' } | Should -Not -Throw + { Update-GitHubOrganization -Organization $owner -Location 'USA' } | Should -Not -Throw + { Update-GitHubOrganization -Organization $owner -Description 'Test Organization' } | Should -Not -Throw + { Update-GitHubOrganization -Organization $owner -DefaultRepositoryPermission read } | Should -Not -Throw + { Update-GitHubOrganization -Organization $owner -MembersCanCreateRepositories $true } | Should -Not -Throw + { Update-GitHubOrganization -Organization $owner -Blog 'https://psmodule.io' } | Should -Not -Throw + } + } # Context 'Invitations' { # It 'New-GitHubOrganizationInvitation - Invites a user to an organization' { From 0e6c498a4cfd074e452ce4a1d7e4028842d8ca1f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 13:11:44 +0100 Subject: [PATCH 56/60] Fix: Enhance organization invitation tests for improved coverage and validation --- tests/Organizations.Tests.ps1 | 42 ++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/tests/Organizations.Tests.ps1 b/tests/Organizations.Tests.ps1 index 650d51760..8620bfbb0 100644 --- a/tests/Organizations.Tests.ps1 +++ b/tests/Organizations.Tests.ps1 @@ -69,7 +69,7 @@ Describe 'Organizations' { } } - if ($OwnerType -eq 'organization') { + if ($OwnerType -eq 'organization' -and $Type -ne 'GitHub Actions') { It 'Update-GitHubOrganization - Sets the organization configuration' { { Update-GitHubOrganization -Organization $owner -Company 'ABC' } | Should -Not -Throw { @@ -89,24 +89,26 @@ Describe 'Organizations' { } } - # Context 'Invitations' { - # It 'New-GitHubOrganizationInvitation - Invites a user to an organization' { - # { - # $email = (New-Guid).Guid + '@psmodule.io' - # New-GitHubOrganizationInvitation -Organization $owner -Email $email -Role 'admin' - # } | Should -Not -Throw - # } - # It 'Get-GitHubOrganizationPendingInvitation - Gets the pending invitations for a specific organization' { - # { Get-GitHubOrganizationPendingInvitation -Organization $owner } | Should -Not -Throw - # { Get-GitHubOrganizationPendingInvitation -Organization $owner -Role 'admin' } | Should -Not -Throw - # { Get-GitHubOrganizationPendingInvitation -Organization $owner -InvitationSource 'member' } | Should -Not -Throw - # } - # It 'Remove-GitHubOrganizationInvitation - Removes a user invitation from an organization' { - # { - # $invitation = Get-GitHubOrganizationPendingInvitation -Organization $owner | Select-Object -First 1 - # Remove-GitHubOrganizationInvitation -Organization $owner -ID $invitation.id - # } | Should -Not -Throw - # } - # } + if ($Owner -in 'psmodule-test-org', 'psmodule-test-org2') { + Context 'Invitations' { + It 'New-GitHubOrganizationInvitation - Invites a user to an organization' { + { + $email = (New-Guid).Guid + '@psmodule.io' + New-GitHubOrganizationInvitation -Organization $owner -Email $email -Role 'admin' + } | Should -Not -Throw + } + It 'Get-GitHubOrganizationPendingInvitation - Gets the pending invitations for a specific organization' { + { Get-GitHubOrganizationPendingInvitation -Organization $owner } | Should -Not -Throw + { Get-GitHubOrganizationPendingInvitation -Organization $owner -Role 'admin' } | Should -Not -Throw + { Get-GitHubOrganizationPendingInvitation -Organization $owner -InvitationSource 'member' } | Should -Not -Throw + } + It 'Remove-GitHubOrganizationInvitation - Removes a user invitation from an organization' { + { + $invitation = Get-GitHubOrganizationPendingInvitation -Organization $owner | Select-Object -First 1 + Remove-GitHubOrganizationInvitation -Organization $owner -ID $invitation.id + } | Should -Not -Throw + } + } + } } } From cbdb021add4b16b85cbed7d3ffcbca1021ed1417 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 13:48:28 +0100 Subject: [PATCH 57/60] Fix: Add test for Get-GitHubOrganizationMember to validate member retrieval --- tests/Organizations.Tests.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Organizations.Tests.ps1 b/tests/Organizations.Tests.ps1 index 8620bfbb0..f34cd010e 100644 --- a/tests/Organizations.Tests.ps1 +++ b/tests/Organizations.Tests.ps1 @@ -61,6 +61,13 @@ Describe 'Organizations' { } $organizations | Should -Not -BeNullOrEmpty } + It 'Get-GitHubOrganizationMember - Gets the members of a specific organization' { + $members = Get-GitHubOrganizationMember -Organization $owner + LogGroup 'Members' { + Write-Host ($members | Format-Table | Out-String) + } + $members | Should -Not -BeNullOrEmpty + } # Tests for IAT UAT and PAT goes here if ($OwnerType -eq 'user') { From 51fb494344591142bc0d2b2a93c02f545a6aeea5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 13:54:45 +0100 Subject: [PATCH 58/60] Fix: Add test for Get-GitHubOrganization to validate retrieval of authenticated user's organizations --- tests/Organizations.Tests.ps1 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/Organizations.Tests.ps1 b/tests/Organizations.Tests.ps1 index f34cd010e..17cce1dba 100644 --- a/tests/Organizations.Tests.ps1 +++ b/tests/Organizations.Tests.ps1 @@ -61,6 +61,15 @@ Describe 'Organizations' { } $organizations | Should -Not -BeNullOrEmpty } + if ($OwnerType -ne 'user') { + It "Get-GitHubOrganization - Gets the authenticated user's organizations" { + $organizations = Get-GitHubOrganization + LogGroup 'Organization' { + Write-Host ($organizations | Format-Table | Out-String) + } + $organizations | Should -Not -BeNullOrEmpty + } + } It 'Get-GitHubOrganizationMember - Gets the members of a specific organization' { $members = Get-GitHubOrganizationMember -Organization $owner LogGroup 'Members' { From d2f459677233f6e02ce9277a48b2d5b80ac4832f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 14:01:08 +0100 Subject: [PATCH 59/60] Fix: Update organization tests to correctly validate member retrieval based on owner type --- tests/Organizations.Tests.ps1 | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/tests/Organizations.Tests.ps1 b/tests/Organizations.Tests.ps1 index 17cce1dba..794134294 100644 --- a/tests/Organizations.Tests.ps1 +++ b/tests/Organizations.Tests.ps1 @@ -61,21 +61,14 @@ Describe 'Organizations' { } $organizations | Should -Not -BeNullOrEmpty } - if ($OwnerType -ne 'user') { - It "Get-GitHubOrganization - Gets the authenticated user's organizations" { - $organizations = Get-GitHubOrganization - LogGroup 'Organization' { - Write-Host ($organizations | Format-Table | Out-String) + if ($OwnerType -eq 'user') { + It 'Get-GitHubOrganizationMember - Gets the members of a specific organization' { + $members = Get-GitHubOrganizationMember -Organization $owner + LogGroup 'Members' { + Write-Host ($members | Format-Table | Out-String) } - $organizations | Should -Not -BeNullOrEmpty - } - } - It 'Get-GitHubOrganizationMember - Gets the members of a specific organization' { - $members = Get-GitHubOrganizationMember -Organization $owner - LogGroup 'Members' { - Write-Host ($members | Format-Table | Out-String) + $members | Should -Not -BeNullOrEmpty } - $members | Should -Not -BeNullOrEmpty } # Tests for IAT UAT and PAT goes here From 247ef8f4c5d5f71bcc1f1cce28b26a158f55408e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 14:23:35 +0100 Subject: [PATCH 60/60] Fix: Correct condition in organization member retrieval test to ensure accurate validation --- tests/Organizations.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Organizations.Tests.ps1 b/tests/Organizations.Tests.ps1 index 794134294..d272a6862 100644 --- a/tests/Organizations.Tests.ps1 +++ b/tests/Organizations.Tests.ps1 @@ -61,7 +61,7 @@ Describe 'Organizations' { } $organizations | Should -Not -BeNullOrEmpty } - if ($OwnerType -eq 'user') { + if ($OwnerType -ne 'user') { It 'Get-GitHubOrganizationMember - Gets the members of a specific organization' { $members = Get-GitHubOrganizationMember -Organization $owner LogGroup 'Members' {