|
| 1 | +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( |
| 2 | + 'PSUseDeclaredVarsMoreThanAssignments', |
| 3 | + '', |
| 4 | + Justification = 'The temporary path is assigned before assertions and cleanup.' |
| 5 | +)] |
| 6 | +[CmdletBinding()] |
| 7 | +param() |
| 8 | + |
| 9 | +BeforeAll { |
| 10 | + Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '../src/Helper.psm1') -Force |
| 11 | +} |
| 12 | + |
| 13 | +Describe 'Update-ModuleList' { |
| 14 | + Context 'catalog page at the Modules root' { |
| 15 | + It 'Update-ModuleList - writes the catalog index and repository page to the new Modules paths' { |
| 16 | + $testRoot = Join-Path ([System.IO.Path]::GetTempPath()) ("update-index-test-$([guid]::NewGuid())") |
| 17 | + $modulesPath = Join-Path $testRoot 'docs/content/Modules' |
| 18 | + $catalogIndexPath = Join-Path $modulesPath 'index.md' |
| 19 | + New-Item -ItemType Directory -Path $modulesPath -Force | Out-Null |
| 20 | + Set-Content -Path $catalogIndexPath -Value @( |
| 21 | + '# Modules' |
| 22 | + '' |
| 23 | + '<!-- MODULE_CATALOG_START -->' |
| 24 | + '<!-- MODULE_CATALOG_END -->' |
| 25 | + ) |
| 26 | + |
| 27 | + try { |
| 28 | + Push-Location $testRoot |
| 29 | + InModuleScope Helper { |
| 30 | + Mock Get-RepositoryVersion { '1.2.3' } |
| 31 | + Mock Get-RepositoryReadmeContent { '# Example`nExample module summary.' } |
| 32 | + Mock Get-MarkdownSummary { 'Example module summary.' } |
| 33 | + Mock Get-WorkflowReference { 'v1.2.3' } |
| 34 | + Mock Get-ProcessReferenceStatus { 'up-to-date' } |
| 35 | + Mock Get-OpenItemCount { 0 } |
| 36 | + |
| 37 | + Update-ModuleList -Repos @( |
| 38 | + [pscustomobject]@{ |
| 39 | + Type = 'Module' |
| 40 | + Owner = 'PSModule' |
| 41 | + Name = 'Example' |
| 42 | + Description = 'Example module.' |
| 43 | + DefaultBranch = 'main' |
| 44 | + Stars = 1 |
| 45 | + } |
| 46 | + ) |
| 47 | + } |
| 48 | + |
| 49 | + $catalogContent = Get-Content -Path $catalogIndexPath -Raw |
| 50 | + Test-Path (Join-Path $modulesPath 'Repositories/Example.md') | Should -BeTrue |
| 51 | + $catalogContent | Should -Match '\./Repositories/Example\.md' |
| 52 | + $catalogContent | Should -Match '\.\./assets/images/module-catalog/githubtags\.svg' |
| 53 | + } finally { |
| 54 | + Pop-Location |
| 55 | + Remove-Item -LiteralPath $testRoot -Recurse -Force -ErrorAction SilentlyContinue |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments