Skip to content

Commit 1300fb4

Browse files
✨ [Refactor]: Simplify repository creation and logging for user and organization owners in test scripts
1 parent 4e9bf57 commit 1300fb4

3 files changed

Lines changed: 13 additions & 17 deletions

File tree

tests/BeforeAll.ps1

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,11 @@ LogGroup 'BeforeAll - Global Test Setup' {
6262
}
6363

6464
# Create extra repositories needed by Secrets/Variables SelectedRepository tests.
65-
foreach ($suffix in 2, 3) {
66-
$extraName = "$repoName-$suffix"
67-
switch ($OwnerType) {
68-
'user' {
69-
New-GitHubRepository -Name $extraName
70-
}
71-
'organization' {
72-
New-GitHubRepository -Organization $Owner -Name $extraName
73-
}
65+
# Only organization owners need them — those tests are skipped for user owners.
66+
if ($OwnerType -eq 'organization') {
67+
foreach ($suffix in 2, 3) {
68+
$extraName = "$repoName-$suffix"
69+
New-GitHubRepository -Organization $Owner -Name $extraName
7470
}
7571
}
7672
}

tests/Secrets.Tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ Describe 'Secrets' {
5050
switch ($OwnerType) {
5151
'user' {
5252
$repo = Get-GitHubRepository -Name $repoName
53-
$repo2 = Get-GitHubRepository -Name "$repoName-2"
54-
$repo3 = Get-GitHubRepository -Name "$repoName-3"
5553
}
5654
'organization' {
5755
Get-GitHubSecret -Owner $Owner | Where-Object { $_.Name -like "$secretName*" } | Remove-GitHubSecret -Confirm:$false
@@ -74,8 +72,10 @@ Describe 'Secrets' {
7472
}
7573
LogGroup "Repository - [$repoName]" {
7674
Write-Host ($repo | Select-Object * | Out-String)
77-
Write-Host ($repo2 | Select-Object * | Out-String)
78-
Write-Host ($repo3 | Select-Object * | Out-String)
75+
if ($OwnerType -eq 'organization') {
76+
Write-Host ($repo2 | Select-Object * | Out-String)
77+
Write-Host ($repo3 | Select-Object * | Out-String)
78+
}
7979
}
8080
}
8181

tests/Variables.Tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ Describe 'Variables' {
5050
switch ($OwnerType) {
5151
'user' {
5252
$repo = Get-GitHubRepository -Name $repoName
53-
$repo2 = Get-GitHubRepository -Name "$repoName-2"
54-
$repo3 = Get-GitHubRepository -Name "$repoName-3"
5553
}
5654
'organization' {
5755
Get-GitHubVariable -Owner $Owner | Where-Object { $_.Name -like "$variableName*" } | Remove-GitHubVariable -Confirm:$false
@@ -73,8 +71,10 @@ Describe 'Variables' {
7371
}
7472
LogGroup "Repository - [$repoName]" {
7573
Write-Host ($repo | Select-Object * | Out-String)
76-
Write-Host ($repo2 | Select-Object * | Out-String)
77-
Write-Host ($repo3 | Select-Object * | Out-String)
74+
if ($OwnerType -eq 'organization') {
75+
Write-Host ($repo2 | Select-Object * | Out-String)
76+
Write-Host ($repo3 | Select-Object * | Out-String)
77+
}
7878
}
7979
}
8080

0 commit comments

Comments
 (0)