Skip to content

[test] Add tests for difc.Capabilities#1135

Merged
lpcox merged 1 commit intomainfrom
test/difc-capabilities-coverage-fefea13fd6bab620
Feb 19, 2026
Merged

[test] Add tests for difc.Capabilities#1135
lpcox merged 1 commit intomainfrom
test/difc-capabilities-coverage-fefea13fd6bab620

Conversation

@github-actions
Copy link
Contributor

Test Coverage Improvement: difc.Capabilities

Function Analyzed

  • Package: internal/difc
  • Struct: Capabilities (with 8 methods)
  • File: internal/difc/capabilities.go
  • Previous Coverage: 0% (no tests existed)
  • New Coverage: ~100% (all branches covered)
  • Complexity: Medium (concurrent access with sync.RWMutex)

Why This Function?

Capabilities is used in production at internal/server/unified.go:130 via difc.NewCapabilities(), but had absolutely zero test coverage. The struct manages a thread-safe set of DIFC tags using sync.RWMutex, making correctness under concurrent access an important correctness property to validate.

Tests Added

New file: internal/difc/capabilities_test.go

  • TestNewCapabilities — basic construction, empty count
  • TestCapabilities_Add — single tag, duplicate (idempotent), multiple distinct tags
  • TestCapabilities_AddAll — empty slice, nil slice, single, multiple, duplicates
  • TestCapabilities_Contains — present, absent, empty capabilities, one-of-many, empty-string tag
  • TestCapabilities_GetAll — empty returns empty slice, all tags returned, deduplication
  • TestCapabilities_Remove — existing tag, non-existing (no-op), empty capabilities, last tag
  • TestCapabilities_Clear — populated, empty, single-element
  • TestCapabilities_Count — empty, after add, duplicate add (no change), after remove, after clear
  • TestCapabilities_ClearAndReuse — verifies map is properly re-initialized after Clear
  • TestCapabilities_Concurrency — concurrent adds, reads, and mixed ops via goroutines + sync.WaitGroup

Coverage Report

Before: 0% (no tests for Capabilities struct)
After:  ~100% (all 8 methods and all branches covered)

All table-driven tests follow existing patterns from internal/difc/difc_test.go and internal/difc/evaluator_test.go, using testify/assert and testify/require.


Generated by Test Coverage Improver
Next run will target the next most complex under-tested function

AI generated by Test Coverage Improver

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>
@lpcox lpcox marked this pull request as ready for review February 19, 2026 23:19
Copilot AI review requested due to automatic review settings February 19, 2026 23:19
@lpcox lpcox merged commit eaeeb3c into main Feb 19, 2026
2 checks passed
@lpcox lpcox deleted the test/difc-capabilities-coverage-fefea13fd6bab620 branch February 19, 2026 23:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.go with 334 lines of comprehensive tests
  • Covers all 8 methods of the Capabilities struct 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants