|
6 | 6 | Tests for GitHubRepositoryForks.ps1 module |
7 | 7 | #> |
8 | 8 |
|
| 9 | +[CmdletBinding()] |
| 10 | +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', |
| 11 | + Justification='Suppress false positives in Pester code blocks')] |
| 12 | +param() |
| 13 | + |
9 | 14 | # This is common test code setup logic for all Pester test files |
10 | 15 | $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent |
11 | 16 | . (Join-Path -Path $moduleRootPath -ChildPath 'Tests\Common.ps1') |
12 | 17 |
|
13 | 18 | try |
14 | 19 | { |
15 | | - Describe 'Creating a new fork for user' { |
16 | | - $originalForks = @(Get-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub) |
| 20 | + # Define Script-scoped, readonly, hidden variables. |
| 21 | + @{ |
| 22 | + upstreamOwnerName = 'microsoft' |
| 23 | + upstreamRepositoryName = 'PowerShellForGitHub' |
| 24 | + }.GetEnumerator() | ForEach-Object { |
| 25 | + Set-Variable -Force -Scope Script -Option ReadOnly -Visibility Private -Name $_.Key -Value $_.Value |
| 26 | + } |
17 | 27 |
|
| 28 | + Describe 'Creating a new fork for user' { |
18 | 29 | Context 'When a new fork is created' { |
19 | | - $repo = New-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub |
20 | | - $newForks = @(Get-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Sort Newest) |
21 | | - |
22 | | - It 'Should have one more fork than before' { |
23 | | - ($newForks.Count - $originalForks.Count) | Should be 1 |
| 30 | + BeforeAll { |
| 31 | + $repo = New-GitHubRepositoryFork -OwnerName $script:upstreamOwnerName -RepositoryName $script:upstreamRepositoryName |
24 | 32 | } |
25 | 33 |
|
26 | | - It 'Should be the latest fork in the list' { |
27 | | - $newForks[0].full_name | Should be "$($script:ownerName)/PowerShellForGitHub" |
| 34 | + AfterAll { |
| 35 | + Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false |
28 | 36 | } |
29 | 37 |
|
30 | | - Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false |
| 38 | + $newForks = @(Get-GitHubRepositoryFork -OwnerName $script:upstreamOwnerName -RepositoryName $script:upstreamRepositoryName -Sort Newest) |
| 39 | + $ourFork = $newForks | Where-Object { $_.owner.login -eq $script:ownerName } |
| 40 | + |
| 41 | + It 'Should be in the list' { |
| 42 | + # Doing this syntax, because due to odd timing with GitHub, it's possible it may |
| 43 | + # think that there's an existing clone out there and so may name this one "...-1" |
| 44 | + $ourFork.full_name.StartsWith("$($script:ownerName)/$script:upstreamRepositoryName") | Should -BeTrue |
| 45 | + } |
31 | 46 | } |
32 | 47 | } |
33 | 48 |
|
34 | 49 | Describe 'Creating a new fork for an org' { |
35 | | - $originalForks = @(Get-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub) |
36 | | - |
37 | 50 | Context 'When a new fork is created' { |
38 | | - $repo = New-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub -OrganizationName $script:organizationName |
39 | | - $newForks = @(Get-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Sort Newest) |
40 | | - |
41 | | - It 'Should have one more fork than before' { |
42 | | - ($newForks.Count - $originalForks.Count) | Should be 1 |
| 51 | + BeforeAll { |
| 52 | + $repo = New-GitHubRepositoryFork -OwnerName $script:upstreamOwnerName -RepositoryName $script:upstreamRepositoryName -OrganizationName $script:organizationName |
43 | 53 | } |
44 | 54 |
|
45 | | - It 'Should be the latest fork in the list' { |
46 | | - $newForks[0].full_name | Should be "$($script:organizationName)/PowerShellForGitHub" |
| 55 | + AfterAll { |
| 56 | + Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false |
47 | 57 | } |
48 | 58 |
|
49 | | - Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false |
| 59 | + $newForks = @(Get-GitHubRepositoryFork -OwnerName $script:upstreamOwnerName -RepositoryName $script:upstreamRepositoryName -Sort Newest) |
| 60 | + $ourFork = $newForks | Where-Object { $_.owner.login -eq $script:organizationName } |
| 61 | + |
| 62 | + It 'Should be in the list' { |
| 63 | + # Doing this syntax, because due to odd timing with GitHub, it's possible it may |
| 64 | + # think that there's an existing clone out there and so may name this one "...-1" |
| 65 | + $ourFork.full_name.StartsWith("$($script:organizationName)/$script:upstreamRepositoryName") | Should -BeTrue |
| 66 | + } |
50 | 67 | } |
51 | 68 | } |
52 | 69 | } |
|
0 commit comments