Repository navigation
test: extract shared setup/cleanup for DNS record integration tests - #145
Merged
Merged
Conversation
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>
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
SonarCloud flagged a 31-line duplicated block between
Get-PiHoleDnsRecord.Integration.Tests.ps1andRemove-PiHoleDnsRecord.Integration.Tests.ps1: the header plus theBeforeAll/AfterAllconfig loading and record cleanup. That came to about 8% duplication on new code, so main's quality gate failed (the limit is 3%).tests/DnsControl/DnsRecordTestHelpers.ps1, which has two functions:Initialize-DnsRecordTest -Hosts ... -CnameRecords ...loadsIntegrationConfig.local.ps1into$script:PiHoleServer/PiHoleToken/PiHoleIgnoreSsland removes records left over from a previous failed run.Clear-DnsRecordTestDataremoves the same records. EachAfterAllnow calls it.Itblocks changed.Sonar ignores literal values when matching duplicates, so the helper loads the config itself. If each file still did that inline, the
BeforeAllblocks would keep the same shape and could be flagged again.Test plan
piholeshell-testrecords left indns/hostsordns/cnameRecordsafter the runtests/DnsControlbelow the gate🤖 Generated with Claude Code