45 lines
2.0 KiB
PowerShell
45 lines
2.0 KiB
PowerShell
BeforeAll {
|
|
$messageTokens = $null; $messageErrors = $null
|
|
$messageAst = [System.Management.Automation.Language.Parser]::ParseFile("$PSScriptRoot/../bootstrap.ps1", [ref]$messageTokens, [ref]$messageErrors)
|
|
$messageFn = $messageAst.Find({ param($n) $n -is [System.Management.Automation.Language.FunctionDefinitionAst] -and $n.Name -eq 'Write-ConfigCentralMessage' }, $true)
|
|
. ([scriptblock]::Create($messageFn.Extent.Text))
|
|
|
|
$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
|
|
$LASTEXITCODE | Should -Be 2
|
|
}
|
|
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 }
|
|
}
|
|
}
|