Skip to content

Commit 97fb315

Browse files
⚙️ [Maintenance]: Make public help-link validation reusable
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent c4bbd30 commit 97fb315

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

.github/actions/Test-PSModule/src/tests/SourceCode/PSModule/PSModule.Tests.ps1

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ BeforeDiscovery {
5959

6060
@{
6161
DocumentationPath = $documentationPath
62-
ExpectedLink = "https://psmodule.io/$ModuleName/Functions/$documentationPath/"
63-
FilePath = $_.FullName
62+
FilePath = $_.FullName
6463
}
6564
}
6665
} else {
@@ -361,14 +360,24 @@ Describe 'PSModule - SourceCode tests' {
361360
}
362361
}
363362
It 'Should put the canonical documentation link first for <DocumentationPath> (ID: PublicHelpLink)' -ForEach $publicHelpLinkTestCases {
364-
param($DocumentationPath, $ExpectedLink, $FilePath)
363+
param($DocumentationPath, $FilePath)
365364

366365
$content = Get-Content -Path $FilePath -Raw
367366
$links = [regex]::Matches($content, '(?ms)^\s*\.LINK\s*\r?\n\s*(?<Uri>\S+)')
368367

369368
$links.Count | Should -BeGreaterThan 0 -Because "$DocumentationPath should have a documentation link"
370-
$links[0].Groups['Uri'].Value |
371-
Should -BeExactly $ExpectedLink -Because "$DocumentationPath should put its canonical documentation link first"
369+
$link = $links[0].Groups['Uri'].Value
370+
$parsedLink = $null
371+
[Uri]::TryCreate($link, [UriKind]::Absolute, [ref]$parsedLink) |
372+
Should -BeTrue -Because "$DocumentationPath should use an absolute documentation link"
373+
$parsedLink.Scheme |
374+
Should -BeExactly 'https' -Because "$DocumentationPath should use HTTPS for its documentation link"
375+
$parsedLink.Host |
376+
Should -Not -BeNullOrEmpty -Because "$DocumentationPath should specify a documentation host"
377+
$parsedLink.AbsolutePath |
378+
Should -BeExactly "/$ModuleName/Functions/$DocumentationPath/" -Because "$DocumentationPath should use the canonical documentation path"
379+
$parsedLink.Query | Should -BeNullOrEmpty -Because "$DocumentationPath should not add a query to its documentation link"
380+
$parsedLink.Fragment | Should -BeNullOrEmpty -Because "$DocumentationPath should not add a fragment to its documentation link"
372381
}
373382
It 'All public functions/filters have tests (ID: FunctionTest)' {
374383
$issues = @('')

tests/srcTestRepo/src/functions/public/PSModule/Get-PSModuleTest.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function Get-PSModuleTest {
1717
"Hello, World!"
1818
1919
.LINK
20-
https://psmodule.io/PSModuleTest2/Functions/PSModule/Get-PSModuleTest/
20+
https://docs.example.com/PSModuleTest2/Functions/PSModule/Get-PSModuleTest/
2121
#>
2222
[CmdletBinding()]
2323
param (

tests/srcWithManifestTestRepo/src/functions/public/PSModule/Get-PSModuleTest.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function Get-PSModuleTest {
1717
"Hello, World!"
1818
1919
.LINK
20-
https://psmodule.io/PSModuleTest/Functions/PSModule/Get-PSModuleTest/
20+
https://docs.example.com/PSModuleTest/Functions/PSModule/Get-PSModuleTest/
2121
#>
2222
[CmdletBinding()]
2323
param (

0 commit comments

Comments
 (0)