config-central/tests/PortableManifest.Tests.ps1

78 lines
4.4 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*'
}
It 'accepts and preserves a complete release discovery declaration' {
$item | Add-Member releaseApi 'https://example.org/gitea/api/v1/repos/owner/project/releases'
$item | Add-Member releaseChannel 'prerelease'
$item | Add-Member assetTemplate 'presenter-v{version}.zip'
$item | Add-Member executableTemplate 'presenter-v{version}/presenter.exe'
$item | Add-Member checksumAsset 'SHA256SUMS'
Assert-ItemList @($item) package test
$items = [ordered]@{}
Add-ManifestItems $items @($item) package
$items['portable/gitea/presenter'].releaseChannel | Should -Be 'prerelease'
$items['portable/gitea/presenter'].assetTemplate | Should -Be 'presenter-v{version}.zip'
}
It 'rejects incomplete or unsafe release discovery declarations' -ForEach @(
@{ Field = 'releaseApi'; Value = 'http://example.org/api/v1/repos/a/b/releases' }
@{ Field = 'releaseApi'; Value = 'https://example.org/not-gitea' }
@{ Field = 'releaseChannel'; Value = 'nightly' }
@{ Field = 'assetTemplate'; Value = '../app-{version}.zip' }
@{ Field = 'assetTemplate'; Value = 'app.zip' }
@{ Field = 'executableTemplate'; Value = '../{version}/app.exe' }
@{ Field = 'checksumAsset'; Value = '../SHA256SUMS' }
) {
$item | Add-Member releaseApi 'https://example.org/api/v1/repos/a/b/releases'
$item | Add-Member releaseChannel 'stable'
$item | Add-Member assetTemplate 'app-{version}.zip'
$item | Add-Member executableTemplate 'app-{version}/app.exe'
$item | Add-Member checksumAsset 'SHA256SUMS'
$item | Add-Member -NotePropertyName $Field -NotePropertyValue $Value -Force
{ Assert-ItemList @($item) package test } | Should -Throw
}
}
}