config-central/tests/Manifest.Tests.ps1

34 lines
1.7 KiB
PowerShell

BeforeAll {
Import-Module "$PSScriptRoot/../src/Manifest.psm1" -Force
}
Describe 'Manifest resolution' {
It 'resolves the checked-in example in profile order' {
$result = Resolve-MachineManifest -RepositoryRoot "$PSScriptRoot/.." -Machine 'example-desktop'
$result.packages.Count | Should -Be 3
$result.configs.Count | Should -Be 2
$result.packages[0].id | Should -Be 'Git.Git'
}
It 'lets later profiles replace and disable earlier items' {
$root = Join-Path $TestDrive 'repo'
New-Item -ItemType Directory "$root/profiles", "$root/machines" | Out-Null
'{"schemaVersion":1,"name":"one","packages":[{"id":"A.B","source":"winget","update":"latest"}],"configs":[]}' | Set-Content "$root/profiles/one.json"
'{"schemaVersion":1,"name":"two","packages":[{"id":"A.B","source":"winget","enabled":false}],"configs":[]}' | Set-Content "$root/profiles/two.json"
'{"schemaVersion":1,"name":"test","profiles":["one","two"],"packages":[],"configs":[]}' | Set-Content "$root/machines/test.json"
(Resolve-MachineManifest -RepositoryRoot $root -Machine test).packages.Count | Should -Be 0
}
It 'rejects duplicate JSON properties' {
$path = Join-Path $TestDrive 'duplicate.json'
'{"schemaVersion":1,"name":"test","name":"again","packages":[],"configs":[]}' | Set-Content $path
{ Read-ManifestFile -Path $path -Kind profile } | Should -Throw '*Duplicate JSON key*'
}
It 'rejects unknown fields' {
$path = Join-Path $TestDrive 'unknown.json'
'{"schemaVersion":1,"name":"test","surprise":true}' | Set-Content $path
{ Read-ManifestFile -Path $path -Kind profile } | Should -Throw '*Unknown field*'
}
}