config-central/tests/Installer.Tests.ps1

43 lines
1.7 KiB
PowerShell

BeforeAll {
$script:installerPath = "$PSScriptRoot/../install.ps1"
$tokens = $null
$errors = $null
$script:installerAst = [System.Management.Automation.Language.Parser]::ParseFile($installerPath, [ref]$tokens, [ref]$errors)
if ($errors.Count -gt 0) { throw "install.ps1 does not parse: $($errors[0].Message)" }
$functionAst = $installerAst.Find({
param($node)
$node -is [System.Management.Automation.Language.FunctionDefinitionAst] -and $node.Name -eq 'Select-ConfigCentralMachine'
}, $true)
. ([scriptblock]::Create($functionAst.Extent.Text))
}
Describe 'One-stop installer machine selection' {
BeforeEach {
$script:Branch = 'main'
$script:previousComputerName = $env:COMPUTERNAME
$env:COMPUTERNAME = 'OFFICE-PC'
}
AfterEach { $env:COMPUTERNAME = $script:previousComputerName }
It 'uses an explicit machine selection' {
Select-ConfigCentralMachine -Requested living-room -Saved office-pc -Available @('living-room', 'office-pc') |
Should -Be 'living-room'
}
It 'reuses the saved machine on subsequent runs' {
Select-ConfigCentralMachine -Requested '' -Saved living-room -Available @('living-room', 'office-pc') |
Should -Be 'living-room'
}
It 'matches the Windows computer name before prompting' {
Select-ConfigCentralMachine -Requested '' -Saved '' -Available @('living-room', 'office-pc') |
Should -Be 'office-pc'
}
It 'automatically selects the only available manifest' {
Select-ConfigCentralMachine -Requested '' -Saved '' -Available @('example-desktop') |
Should -Be 'example-desktop'
}
}