[test-improver] Improve tests for difc sink_server_ids#2064
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
[test-improver] Improve tests for difc sink_server_ids#2064github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
Cover SetSinkServerIDs: nil/empty input clears state, IDs are sorted and deduplicated, whitespace is trimmed, empty strings are skipped, and repeated calls overwrite prior configuration. Cover IsSinkServerID: matching, non-matching, case-sensitivity, empty query, and nil/empty configuration all behave correctly. Add concurrency test to verify mutex protection under parallel reads and writes. 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.
File Analyzed
internal/difc/sink_server_ids_test.go(new)internal/difcImprovements Made
1. Increased Coverage — Previously Zero
sink_server_ids.goexports two public functions (SetSinkServerIDs,IsSinkServerID) with zero test coverage. These functions control which backend server IDs receive DIFC tag snapshot enrichment in RPC JSONL logs — a security-relevant configuration path.2. New Tests Added
TestSetSinkServerIDs(9 table-driven cases)nilinput clears configuration (sets global tonil)[]string{}input clears configuration (same early-exit path)TestSetSinkServerIDs_OverwritesPreviousConfigurationTestSetSinkServerIDs_ClearWithEmpty[]string{}after setting IDs resets tonilTestIsSinkServerID(8 table-driven cases)truefalsefalsefalse"GitHub"does not match"github"TestIsSinkServerID_AfterClearSetSinkServerIDs(nil)TestSetSinkServerIDs_Concurrency3. Test Isolation
Each subtest registers a
t.Cleanuphook that resets the package-levelsinkServerIDsglobal through the same mutex used in production, ensuring tests are fully independent regardless of execution order.Test Execution
Tests use the standard testify patterns established throughout the
internal/difcpackage:assertfor non-fatal checksrequirefor assertions that must pass to continuet.Cleanupfor state teardownWhy These Changes?
sink_server_ids.gohad 0% test coverage despite being a critical security-configuration component: it determines which backend servers receive enriched DIFC tag data in audit logs. The logic has several non-trivial invariants (sort order, deduplication, whitespace trimming, nil-vs-empty-slice distinction in two code paths) that are easy to break silently. These tests lock in all those invariants.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests