Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions azuredevops-pihole-pester-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,34 @@ steps:
foreach ($file in $changedFiles) {
if ($runFullSuite) { break }

if ($file -match '^PiHoleShell/Private/' -or
$file -eq 'PiHoleShell/PiHoleShell.psm1' -or
if ($file -eq 'PiHoleShell/PiHoleShell.psm1') {
# A pure addition to the export list can't break any existing, already-
# passing test, so only fall back to the full suite when an existing
# export was actually removed. Comparing whole diff lines doesn't work
# here since several exports share one line - adding a new function to
# an existing category's line shows as that whole line being removed
# and re-added, even though nothing already there was dropped. Instead,
# extract the quoted names from just the removed lines and just the
# added lines and compare those sets: a name that reappears in the
# added lines was only reformatted, not actually removed.
$manifestDiff = git diff "origin/$targetBranch...HEAD" -- $file
if ($LASTEXITCODE -ne 0) { throw "git diff failed for '$file'" }

$removedLines = ($manifestDiff | Where-Object { $_ -match '^-' -and $_ -notmatch '^---' }) -join "`n"
$addedLines = ($manifestDiff | Where-Object { $_ -match '^\+' -and $_ -notmatch '^\+\+\+' }) -join "`n"
$removedNames = [regex]::Matches($removedLines, "'([A-Za-z0-9-]+)'") | ForEach-Object { $_.Groups[1].Value }
$addedNames = [regex]::Matches($addedLines, "'([A-Za-z0-9-]+)'") | ForEach-Object { $_.Groups[1].Value }

$trulyRemoved = $removedNames | Where-Object { $_ -notin $addedNames }
if ($trulyRemoved) {
Write-Host "Export(s) removed from $file ($($trulyRemoved -join ', ')) - running the full suite"
$runFullSuite = $true
}
else {
Write-Host "Only additions in $file - no full-suite fallback needed"
}
}
elseif ($file -match '^PiHoleShell/Private/' -or
$file -eq 'PiHoleShell/PiHoleShell.psd1' -or
$file -eq 'PiHoleShell/Public/Authentication/Request-PiHoleAuth.ps1' -or
$file -eq 'tests/Initialize-PiHoleTestData.ps1' -or
Expand Down
15 changes: 15 additions & 0 deletions tests/ClientManagement/Update-PiHoleClient.Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Describe 'Update-PiHoleClient (Integration)' -Tag 'Integration' {
It 'updates only the comment, preserving Group' -Skip:(-not $script:ConfigAvailable) {
New-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient -Comment 'original comment' | Out-Null

# The test server takes a moment to make a just-added client queryable/updatable again -
# a real hardware limitation of this Pi Zero W, not a module bug (same settle-time
# reasoning as tools/Update-ExampleOutput.ps1 uses for Lists/Domains/Groups).
Start-Sleep -Seconds 2

$result = Update-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient -Comment 'updated comment'
$result | Format-List | Out-String | Write-Host

Expand All @@ -51,6 +56,8 @@ Describe 'Update-PiHoleClient (Integration)' -Tag 'Integration' {
It 'updates only Group, preserving the current comment' -Skip:(-not $script:ConfigAvailable) {
New-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient -Comment 'keep this comment' | Out-Null

Start-Sleep -Seconds 2

$result = Update-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient -Group $script:TestGroupName
$result | Format-List | Out-String | Write-Host

Expand All @@ -64,6 +71,8 @@ Describe 'Update-PiHoleClient (Integration)' -Tag 'Integration' {
It 'errors when -Group names a group that does not exist' -Skip:(-not $script:ConfigAvailable) {
New-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient | Out-Null

Start-Sleep -Seconds 2

$result = Update-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient -Group 'DefinitelyNotARealGroup' -ErrorVariable errOut -ErrorAction SilentlyContinue
Write-Host "Error ($($errOut.Count) entries, showing last): [$($errOut[-1])]"

Expand All @@ -75,6 +84,8 @@ Describe 'Update-PiHoleClient (Integration)' -Tag 'Integration' {
It 'returns the raw API response when RawOutput is set' -Skip:(-not $script:ConfigAvailable) {
New-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient | Out-Null

Start-Sleep -Seconds 2

$result = Update-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient -Comment 'raw output test' -RawOutput $true
$result | Format-List | Out-String | Write-Host

Expand All @@ -86,6 +97,8 @@ Describe 'Update-PiHoleClient (Integration)' -Tag 'Integration' {
It 'errors when neither Comment nor Group is specified' -Skip:(-not $script:ConfigAvailable) {
New-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient | Out-Null

Start-Sleep -Seconds 2

$result = Update-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient -ErrorVariable errOut -ErrorAction SilentlyContinue

$errOut | Should -Not -BeNullOrEmpty
Expand All @@ -102,6 +115,8 @@ Describe 'Update-PiHoleClient (Integration)' -Tag 'Integration' {
It 'errors when given a bad password' -Skip:(-not $script:ConfigAvailable) {
New-PiHoleClient -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient | Out-Null

Start-Sleep -Seconds 2

$result = Update-PiHoleClient -PiHoleServer $script:PiHoleServer -Password 'definitely-not-the-real-token' -IgnoreSsl $script:PiHoleIgnoreSsl -Client $script:TestClient -Comment 'irrelevant' -ErrorVariable errOut -ErrorAction SilentlyContinue

$errOut | Should -Not -BeNullOrEmpty
Expand Down
Loading