[test] Add tests for logger.ObservedURLDomainsLogger#8054
Draft
github-actions[bot] wants to merge 1 commit into
Draft
[test] Add tests for logger.ObservedURLDomainsLogger#8054github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
Adds comprehensive tests for the ObservedURLDomainsLogger type and its public helpers in internal/logger/observed_url_domains_logger.go, which previously had 0% test coverage. Coverage improvement for internal/logger: 93.0% → 97.8% Target functions brought to 100% coverage: - SetURLDomainAuditEnabled - URLDomainAuditEnabled - handleObservedURLDomainsLoggerError - InitObservedURLDomainsLogger - LogDomains - LogObservedURLDomains - Close - CloseObservedURLDomainsLogger Tests cover: - Default and toggled audit-enabled state - Successful logger initialization and teardown lifecycle - Silent fallback when log directory cannot be created - Empty/nil/missing domain inputs - Deduplication within and across LogDomains calls - Accumulation of new domains across multiple calls - Filtering of empty-string domain entries - No-write optimization when nothing changed - Multiple server IDs tracked independently - Sorted JSON output (alphabetical domains per server) - Warning log path when writeToFile fails (directory removed) - Global helper delegation and no-panic when no global logger Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.
Test Coverage Improvement:
ObservedURLDomainsLoggerFunction Analyzed
internal/loggerinternal/logger/observed_url_domains_logger.goWhy This Function?
All public functions in
observed_url_domains_logger.gohad 0% coverage despite being non-trivial: they manage global state, implement a deduplication set with change-detection, perform atomic file writes via a temp-rename pattern, and include silent fallback handling when log directory creation fails. This made them an ideal high-value target for coverage improvement.Tests Added
SetURLDomainAuditEnabled/URLDomainAuditEnabled)LogDomainscallLogDomainscalls (no double-write)writeToFilefails after directory removaluseFallback=true) is a silent no-opCoverage Report
Per-function breakdown (after)
SetURLDomainAuditEnabledURLDomainAuditEnabledhandleObservedURLDomainsLoggerErrorInitObservedURLDomainsLoggerLogDomainsLogObservedURLDomainsCloseCloseObservedURLDomainsLoggersetupObservedURLDomainsLoggerwriteToFileTest Execution
All 24 new tests pass:
Generated by Test Coverage Improver
Next run will target the next most complex under-tested function
Warning
Firewall blocked 6 domains
The following domains were blocked by the firewall during workflow execution:
go.opentelemetry.iogo.yaml.ingolang.orggoogle.golang.orggopkg.inproxy.golang.orgSee Network Configuration for more information.