|
| 1 | +Describe 'Invoke-PruneAudit' { |
| 2 | + BeforeAll { |
| 3 | + . "$PSScriptRoot/utils/testing.ps1" |
| 4 | + Import-Module -Scope Local "$PSScriptRoot/utils/framework.mocks.psm1" |
| 5 | + Import-Module -Scope Local "$PSScriptRoot/utils/input.mocks.psm1" |
| 6 | + Import-Module -Scope Local "$PSScriptRoot/utils/query-state.mocks.psm1" |
| 7 | + |
| 8 | + function Initialize-ValidDownstreamBranchNames { |
| 9 | + $upstreams = Select-AllUpstreamBranches |
| 10 | + [string[]]$entries = @() |
| 11 | + foreach ($key in $upstreams.Keys) { |
| 12 | + foreach ($downstream in $upstreams[$key]) { |
| 13 | + if ($downstream -notin $entries) { |
| 14 | + [string[]]$entries = $entries + @($downstream) |
| 15 | + Initialize-AssertValidBranchName $downstream |
| 16 | + } |
| 17 | + } |
| 18 | + } |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + BeforeEach { |
| 23 | + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] |
| 24 | + $fw = Register-Framework |
| 25 | + |
| 26 | + |
| 27 | + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] |
| 28 | + $initialCommits = @{ |
| 29 | + 'rc/2022-07-14' = 'rc/2022-07-14-commitish' |
| 30 | + 'main' = 'main-commitish' |
| 31 | + 'feature/FOO-123' = 'feature/FOO-123-commitish' |
| 32 | + 'feature/XYZ-1-services' = 'feature/XYZ-1-services-commitish' |
| 33 | + 'infra/shared' = 'infra/shared-commitish' |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + function Add-StandardTests() { |
| 38 | + It 'does nothing when no branches are configured' { |
| 39 | + Initialize-SelectBranches @() |
| 40 | + Initialize-AllUpstreamBranches @{} |
| 41 | + |
| 42 | + & $PSScriptRoot/git-tool-audit-prune.ps1 |
| 43 | + $fw.assertDiagnosticOutput | Should -BeNullOrEmpty |
| 44 | + } |
| 45 | + |
| 46 | + It 'does nothing when existing branches are configured correctly' -Pending { |
| 47 | + Initialize-AllUpstreamBranches @{ |
| 48 | + 'rc/2022-07-14' = @("feature/FOO-123") |
| 49 | + 'feature/FOO-123' = @('infra/shared') |
| 50 | + 'infra/shared' = @('main') |
| 51 | + } |
| 52 | + Initialize-ValidDownstreamBranchNames |
| 53 | + |
| 54 | + & $PSScriptRoot/git-tool-audit-prune.ps1 |
| 55 | + $fw.assertDiagnosticOutput | Should -BeNullOrEmpty |
| 56 | + } |
| 57 | + |
| 58 | + It 'does not apply with a dry run' -Pending { |
| 59 | + Initialize-AllUpstreamBranches @{ |
| 60 | + 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") |
| 61 | + 'feature/FOO-123' = @('infra/shared') |
| 62 | + 'infra/shared' = @('main') |
| 63 | + 'feature/XYZ-1-services' = @('infra/shared') # intentionally have an extra configured branch here for removal |
| 64 | + } |
| 65 | + Initialize-ValidDownstreamBranchNames |
| 66 | + |
| 67 | + & $PSScriptRoot/git-tool-audit-prune.ps1 -dryRun |
| 68 | + $fw.assertDiagnosticOutput | Should -BeNullOrEmpty |
| 69 | + } |
| 70 | + |
| 71 | + It 'prunes configuration of extra branches' -Pending { |
| 72 | + Initialize-AllUpstreamBranches @{ |
| 73 | + 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") |
| 74 | + 'feature/FOO-123' = @('infra/shared') |
| 75 | + 'feature/XYZ-1-services' = @('infra/shared') # intentionally have an extra configured branch here for removal |
| 76 | + 'infra/shared' = @('main') |
| 77 | + } |
| 78 | + Initialize-ValidDownstreamBranchNames |
| 79 | + |
| 80 | + $mock = @( |
| 81 | + # TODO - save |
| 82 | + ) |
| 83 | + |
| 84 | + & $PSScriptRoot/git-tool-audit-prune.ps1 |
| 85 | + $fw.assertDiagnosticOutput | Should -BeNullOrEmpty |
| 86 | + |
| 87 | + Invoke-VerifyMock $mock -Times 1 |
| 88 | + } |
| 89 | + |
| 90 | + It 'consolidates removed branches' -Pending { |
| 91 | + # TODO -setup |
| 92 | + |
| 93 | + $mock = @( |
| 94 | + # TODO: save |
| 95 | + ) |
| 96 | + |
| 97 | + & $PSScriptRoot/git-tool-audit-prune.ps1 |
| 98 | + $fw.assertDiagnosticOutput | Should -BeNullOrEmpty |
| 99 | + |
| 100 | + Invoke-VerifyMock $mock -Times 1 |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + Context 'with no remote' { |
| 105 | + BeforeAll { |
| 106 | + Initialize-ToolConfiguration -noRemote |
| 107 | + Initialize-SelectBranches @( |
| 108 | + 'rc/2022-07-14', |
| 109 | + 'feature/FOO-123', |
| 110 | + 'infra/shared', |
| 111 | + 'main' |
| 112 | + ) |
| 113 | + } |
| 114 | + |
| 115 | + Add-StandardTests |
| 116 | + } |
| 117 | + |
| 118 | + Context 'with remote' { |
| 119 | + BeforeAll { |
| 120 | + Initialize-ToolConfiguration |
| 121 | + Initialize-UpdateGitRemote |
| 122 | + Initialize-SelectBranches @( |
| 123 | + 'rc/2022-07-14', |
| 124 | + 'feature/FOO-123', |
| 125 | + 'infra/shared', |
| 126 | + 'main' |
| 127 | + ) |
| 128 | + } |
| 129 | + |
| 130 | + Add-StandardTests |
| 131 | + } |
| 132 | +} |
0 commit comments