|
| 1 | +Describe 'database version selection' -Tag 'Scoop' { |
| 2 | + BeforeAll { |
| 3 | + . "$PSScriptRoot\Scoop-TestLib.ps1" |
| 4 | + . "$PSScriptRoot\..\lib\core.ps1" |
| 5 | + . "$PSScriptRoot\..\lib\versions.ps1" |
| 6 | + . "$PSScriptRoot\..\lib\database.ps1" |
| 7 | + } |
| 8 | + |
| 9 | + It 'chooses the semantically latest row within one result set' { |
| 10 | + $rows = @( |
| 11 | + [pscustomobject]@{ version = '1.0.7' } |
| 12 | + [pscustomobject]@{ version = '1.0.31' } |
| 13 | + ) |
| 14 | + |
| 15 | + (Get-LatestScoopDBRow -Rows $rows).version | Should -Be '1.0.31' |
| 16 | + } |
| 17 | + |
| 18 | + It 'returns the latest semantic version per name and bucket' { |
| 19 | + $result = New-Object System.Data.DataTable |
| 20 | + [void]$result.Columns.Add('name', [string]) |
| 21 | + [void]$result.Columns.Add('version', [string]) |
| 22 | + [void]$result.Columns.Add('bucket', [string]) |
| 23 | + [void]$result.Columns.Add('binary', [string]) |
| 24 | + [void]$result.Rows.Add('copilot-cli', '1.0.7', 'main', 'copilot') |
| 25 | + [void]$result.Rows.Add('copilot-cli', '1.0.31', 'main', 'copilot') |
| 26 | + [void]$result.Rows.Add('zotero', '7.0.9', 'extras', 'zotero') |
| 27 | + [void]$result.Rows.Add('zotero', '7.0.20', 'extras', 'zotero') |
| 28 | + [void]$result.Rows.Add('zotero', '7.0.9', 'he0119', 'zotero') |
| 29 | + [void]$result.Rows.Add('zotero', '7.0.20', 'he0119', 'zotero') |
| 30 | + |
| 31 | + $latest = @(Select-LatestScoopDBRows -Table $result -GroupBy @('name', 'bucket')) |
| 32 | + |
| 33 | + $latest.Count | Should -Be 3 |
| 34 | + (@($latest | Where-Object { $_.name -eq 'copilot-cli' -and $_.bucket -eq 'main' })[0]).version | Should -Be '1.0.31' |
| 35 | + (@($latest | Where-Object { $_.name -eq 'zotero' -and $_.bucket -eq 'extras' })[0]).version | Should -Be '7.0.20' |
| 36 | + (@($latest | Where-Object { $_.name -eq 'zotero' -and $_.bucket -eq 'he0119' })[0]).version | Should -Be '7.0.20' |
| 37 | + } |
| 38 | + |
| 39 | + It 'returns the latest semantic version when no grouping is requested' { |
| 40 | + $result = New-Object System.Data.DataTable |
| 41 | + [void]$result.Columns.Add('name', [string]) |
| 42 | + [void]$result.Columns.Add('version', [string]) |
| 43 | + [void]$result.Columns.Add('bucket', [string]) |
| 44 | + [void]$result.Columns.Add('binary', [string]) |
| 45 | + [void]$result.Rows.Add('zotero', '7.0.9', 'extras', 'zotero') |
| 46 | + [void]$result.Rows.Add('zotero', '7.0.20', 'extras', 'zotero') |
| 47 | + |
| 48 | + $latest = @(Select-LatestScoopDBRows -Table $result) |
| 49 | + |
| 50 | + $latest.Count | Should -Be 1 |
| 51 | + $latest[0].version | Should -Be '7.0.20' |
| 52 | + } |
| 53 | +} |
0 commit comments