Merged
Conversation
Adds comprehensive unit tests for the Capabilities struct in internal/difc/capabilities.go which previously had 0% test coverage. Tests cover all 8 methods (NewCapabilities, Add, AddAll, Contains, GetAll, Remove, Clear, Count) plus: - Edge cases: empty inputs, nil slices, duplicates, non-existent tags - Post-Clear reuse to verify map is properly re-initialized - Concurrent access to validate RWMutex correctness under race conditions Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive test coverage for the difc.Capabilities struct, which previously had zero test coverage despite being used in production code at internal/server/unified.go:130. The Capabilities struct manages a thread-safe set of DIFC tags using sync.RWMutex, making proper concurrency testing essential for correctness.
Changes:
- Added
internal/difc/capabilities_test.gowith 334 lines of comprehensive tests - Covers all 8 methods of the
Capabilitiesstruct with 10 distinct test functions - Includes both functional tests (basic operations, edge cases) and concurrency tests (thread safety validation)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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:
difc.CapabilitiesFunction Analyzed
internal/difcCapabilities(with 8 methods)internal/difc/capabilities.gosync.RWMutex)Why This Function?
Capabilitiesis used in production atinternal/server/unified.go:130viadifc.NewCapabilities(), but had absolutely zero test coverage. The struct manages a thread-safe set of DIFC tags usingsync.RWMutex, making correctness under concurrent access an important correctness property to validate.Tests Added
New file:
internal/difc/capabilities_test.goTestNewCapabilities— basic construction, empty countTestCapabilities_Add— single tag, duplicate (idempotent), multiple distinct tagsTestCapabilities_AddAll— empty slice, nil slice, single, multiple, duplicatesTestCapabilities_Contains— present, absent, empty capabilities, one-of-many, empty-string tagTestCapabilities_GetAll— empty returns empty slice, all tags returned, deduplicationTestCapabilities_Remove— existing tag, non-existing (no-op), empty capabilities, last tagTestCapabilities_Clear— populated, empty, single-elementTestCapabilities_Count— empty, after add, duplicate add (no change), after remove, after clearTestCapabilities_ClearAndReuse— verifies map is properly re-initialized afterClearTestCapabilities_Concurrency— concurrent adds, reads, and mixed ops via goroutines +sync.WaitGroupCoverage Report
All table-driven tests follow existing patterns from
internal/difc/difc_test.goandinternal/difc/evaluator_test.go, usingtestify/assertandtestify/require.Generated by Test Coverage Improver
Next run will target the next most complex under-tested function