config-central/tests/PortableManifest.Tests.ps1

47 lines
2.5 KiB
PowerShell

Import-Module "$PSScriptRoot/../src/Manifest.psm1" -Force
Describe 'Portable declarations' {
InModuleScope Manifest {
BeforeEach {
$item = [pscustomobject]@{ id = 'presenter'; provider = 'portable'; source = 'gitea'; version = '1.2.3'; update = 'pinned'; url = 'https://example.org/app.zip'; sha256 = ('a' * 64); executable = 'bundle/app.exe' }
}
It 'normalizes portable fields and keeps provider identities separate' {
Assert-ItemList @($item) package test
$items = [ordered]@{}
Add-ManifestItems $items @($item, [pscustomobject]@{ id = 'presenter'; source = 'gitea' }) package
$items.Count | Should -Be 2
$items['portable/gitea/presenter'].executable | Should -Be 'bundle/app.exe'
Add-ManifestItems $items @([pscustomobject]@{ id = 'presenter'; source = 'gitea'; provider = 'portable'; enabled = $false }) package
$items.Count | Should -Be 1
$items.Contains('gitea/presenter') | Should -BeTrue
}
It 'replaces the entire portable item with a later override' {
$items = [ordered]@{}
Add-ManifestItems $items @($item) package
$item.version = '2.0'
Add-ManifestItems $items @($item) package
$items.Count | Should -Be 1
$items['portable/gitea/presenter'].version | Should -Be '2.0'
}
It 'rejects unsafe or unsupported declarations' -ForEach @(
@{ Field = 'executable'; Value = '../app.exe' }
@{ Field = 'executable'; Value = 'C:/app.exe' }
@{ Field = 'executable'; Value = 'con/app.exe' }
@{ Field = 'url'; Value = 'http://example.org/app.zip' }
@{ Field = 'url'; Value = 'https://user:secret@example.org/app.zip' }
@{ Field = 'sha256'; Value = 'bad' }
@{ Field = 'scope'; Value = 'machine' }
@{ Field = 'update'; Value = 'latest' }
@{ Field = 'version'; Value = '../1.0' }
@{ Field = 'provider'; Value = 'script' }
) {
$item | Add-Member -NotePropertyName $Field -NotePropertyValue $Value -Force
{ Assert-ItemList @($item) package test } | Should -Throw
}
It 'rejects duplicate portable entries and WinGet download fields' {
{ Assert-ItemList @($item, $item) package test } | Should -Throw '*Duplicate*'
$item.provider = 'winget'
{ Assert-ItemList @($item) package test } | Should -Throw '*Portable fields*'
}
}
}