test/module/manifest/Get-GitBranchName.Tests.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using module ..\..\.\TestRunnerSupportModule.psm1

Describe "Test Get-GitBranchName" {
    BeforeAll {
        $TestSupportModule = [TestRunnerSupportModule]::new('MockModuleB')
        Set-Variable -Name MockDirectoryPath -Value $TestSupportModule.MockDirectoryPath -Scope Global
    }
    
    AfterAll {
        $TestSupportModule.Teardown()
        Remove-Variable -Name MockDirectoryPath -Scope Global
    }

    Context "Calling on MockModuleB" {
        It "Should return current branch name of master" {
            InModuleScope PowerBolt {
                $SemVer = Get-GitBranchName -Path $MockDirectoryPath
                $SemVer | Should -Be 'master'
            }
        }

        It "Should return branch name of 0.0.1" {
            
            Push-Location
            Set-Location $MockDirectoryPath
            Invoke-Expression -Command 'git checkout -b 0.0.1'

            InModuleScope PowerBolt {
                $SemVer = Get-GitBranchName -Path $MockDirectoryPath
                $SemVer | Should -Be '0.0.1'
            }

            Pop-Location
        } 
    }
}