Skip to content

test: extract shared setup/cleanup for DNS record integration tests - #145

Merged
mikemadeja merged 2 commits into
developfrom
fix/dns-record-test-duplication
Oct 19, 2026
Merged

mikemadeja merged 2 commits into
developfrom
fix/dns-record-test-duplication

Conversation

@mikemadeja

Copy link
Copy Markdown
Owner

Summary

SonarCloud flagged a 31-line duplicated block between Get-PiHoleDnsRecord.Integration.Tests.ps1 and Remove-PiHoleDnsRecord.Integration.Tests.ps1: the header plus the BeforeAll/AfterAll config loading and record cleanup. That came to about 8% duplication on new code, so main's quality gate failed (the limit is 3%).

  • Adds tests/DnsControl/DnsRecordTestHelpers.ps1, which has two functions:
    • Initialize-DnsRecordTest -Hosts ... -CnameRecords ... loads IntegrationConfig.local.ps1 into $script:PiHoleServer/PiHoleToken/PiHoleIgnoreSsl and removes records left over from a previous failed run.
    • Clear-DnsRecordTestData removes the same records. Each AfterAll now calls it.
  • Changes the Add, Get and Remove DNS record test files to use the helper. The Add file wasn't flagged yet, but it had the same pattern. No It blocks changed.

Sonar ignores literal values when matching duplicates, so the helper loads the config itself. If each file still did that inline, the BeforeAll blocks would keep the same shape and could be flagged again.

Test plan

  • All 18 tests in the three DNS record integration test files pass against a live Pi-hole
  • No piholeshell-test records left in dns/hosts or dns/cnameRecords after the run
  • SonarCloud shows new-code duplication for tests/DnsControl below the gate

🤖 Generated with Claude Code

mikemadeja and others added 2 commits October 18, 2026 19:26
SonarCloud flagged the BeforeAll/AfterAll blocks of the Get- and
Remove-PiHoleDnsRecord integration tests as duplicated (8% duplication on
new code, failing the quality gate). Move config loading and record cleanup
into tests/DnsControl/DnsRecordTestHelpers.ps1 and use it from the Add, Get
and Remove test files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@mikemadeja
mikemadeja merged commit 09e5a98 into develop Oct 19, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant