config-central/tests/Bootstrap.Tests.ps1

40 lines
1.6 KiB
PowerShell

BeforeAll {
$script:bootstrapPath = "$PSScriptRoot/../bootstrap.ps1"
$tokens = $null
$errors = $null
$script:bootstrapAst = [System.Management.Automation.Language.Parser]::ParseFile($bootstrapPath, [ref]$tokens, [ref]$errors)
if ($errors.Count -gt 0) { throw "bootstrap.ps1 does not parse: $($errors[0].Message)" }
$functionAst = $bootstrapAst.Find({
param($node)
$node -is [System.Management.Automation.Language.FunctionDefinitionAst] -and $node.Name -eq 'Find-GitPath'
}, $true)
. ([scriptblock]::Create($functionAst.Extent.Text))
}
Describe 'Bootstrap invocation' {
It 'rejects in-memory execution because elevation requires a script file' {
$source = Get-Content $bootstrapPath -Raw
$bootstrap = [scriptblock]::Create($source)
$previousLocalAppData = $env:LOCALAPPDATA
try {
$env:LOCALAPPDATA = $TestDrive
{ & $bootstrap -Repository 'https://example.invalid/config-central.git' -Machine test } |
Should -Throw '*must be downloaded and run as a file*'
}
finally { $env:LOCALAPPDATA = $previousLocalAppData }
}
It 'finds a fresh machine-scope Git install before PATH refreshes' {
$previousProgramFiles = $env:ProgramFiles
try {
Mock Get-Command { $null } -ParameterFilter { $Name -eq 'git.exe' }
$env:ProgramFiles = $TestDrive
$expected = Join-Path $TestDrive 'Git\cmd\git.exe'
New-Item -ItemType File -Path $expected -Force | Out-Null
Find-GitPath | Should -Be $expected
}
finally { $env:ProgramFiles = $previousProgramFiles }
}
}