Conversation
Add 5 new edge case tests covering: - empty Servers map (no servers configured) - multiple servers all without guard policies - multiple servers where only one has guard policies (early return path) - multiple servers all with guard policies - mix of servers with and without empty guard-policies maps Also extract shared policy fixture to reduce duplication, and clarify test case names to describe expected behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves unit test coverage for hasServerGuardPolicies in internal/server by adding additional table-driven scenarios that exercise multi-server iteration and edge cases.
Changes:
- Added a shared
allowOnlyPolicyfixture to reduce duplication across test cases. - Expanded
TestHasServerGuardPolicieswith additional scenarios (empty servers, multi-server combinations, empty policy maps). - Simplified assertions by removing the redundant custom failure message from
assert.Equal.
Show a summary per file
| File | Description |
|---|---|
| internal/server/has_server_guard_policies_test.go | Adds broader table-driven test coverage for hasServerGuardPolicies across empty/multi-server configurations and policy-map edge cases. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 0
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 Improvements:
has_server_guard_policies_test.goFile Analyzed
internal/server/has_server_guard_policies_test.gointernal/serverImprovements Made
1. Increased Coverage
The function
hasServerGuardPoliciesiteratescfg.Serversand returnstrueon the first server that has a non-emptyGuardPoliciesmap, orfalseif none do. The original 3 tests only verified the single-server happy path. New test cases exercise the multi-server iteration logic and boundary conditions:false)false)true)true){}counts as absent →false)2. Cleaner Test Structure
allowOnlyPolicyfixture to reduce duplication across test cases<scenario> returns <result>naming convention, making failures self-documentingassert.Equal(testify already provides clear diffs)Why These Changes?
hasServerGuardPoliciesis used during DIFC auto-detection to decide whether guard enforcement should be enabled. The original 3 tests only covered single-server scenarios, leaving the multi-server iteration and early-return paths entirely untested. Since map iteration order in Go is non-deterministic, the multi-server tests confirm the function is correct regardless of which server is visited first.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests