- Pester
- June Blender's PesterTDD
- PowerShell Operational Validation Framework
- Kevin Marquette’s PesterInAction
- DoesItScript's PesterDashboard
- Dave Wyatt's Repos
- Microsoft.PowerShell.Archive Examples
- PowerShell DscResources.Tests Examples
- Microsoft PowerShell Tests Examples
Created
May 9, 2016 18:51
-
-
Save gerane/008fccb0b193df6bd7ed64699181004e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function ParseMarkdown | |
{ | |
$MarkdownPath = "$PSScriptRoot\Resources\PesteringSysadmins.md" | |
$Object = [ordered]@{} | |
$Sections = @($Object) | |
switch -regex -file $MarkdownPath | |
{ | |
'^# .*' # Section | |
{ | |
$Name = ($Matches[0] -replace '^# ','').Trim() | |
$Section = [ordered]@{} | |
$Count = $Sections.Count | |
$Sections[$Count - 1][$Name] = $Section | |
} | |
'^## .*' # Topic | |
{ | |
$Topic = ($Matches[0] -replace '^## ','').Trim() | |
if (!$Section[$Topic]) { $Section[$Topic] = [ordered]@{} } | |
} | |
'^\* \[.*' # Entry | |
{ | |
$Entry = ($Matches[0] -replace '^\* ','').Trim() | |
$Parse = $Entry -match '^.*\[(.*)\].*\((.*)\)$' | |
$Description = $Matches[1] | |
$uri = $Matches[2] | |
$Section[$Topic] += @{ $Description = $uri } | |
} | |
} | |
Return $Object | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module Pester | |
$here = Split-Path -Parent $MyInvocation.MyCommand.Path | |
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace('.Tests.', '.') | |
. "$here\$sut" | |
$Markdown = ParseMarkdown | |
Function Test-ResourceLinks ($InputObject) | |
{ | |
Describe 'Testing Resources' { | |
foreach ($Section in $InputObject.Keys) | |
{ | |
foreach ($Topic in $InputObject.$Section.Keys) | |
{ | |
Context "Testing URLs in [$($Section) - $($Topic)]" { | |
foreach ($Entry in $InputObject.$Section.$Topic.Keys) | |
{ | |
$Description = $Entry | |
$Uri = $InputObject.$Section.$Topic.$Description | |
It "[$($Description)] should have a working Url" { | |
Write-Verbose -Message "Testing Uri [$($Uri)]" | |
$Results = Invoke-WebRequest -Uri $Uri -UseBasicParsing | |
$Results.StatusCode | Should Be '200' | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
Test-ResourceLinks -InputObject $Markdown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment