Skip to content

[test-improver] Improve tests for server hasServerGuardPolicies#3273

Merged
lpcox merged 1 commit intomainfrom
test-improver/has-server-guard-policies-d333f53a9d0ac420
Apr 6, 2026
Merged

[test-improver] Improve tests for server hasServerGuardPolicies#3273
lpcox merged 1 commit intomainfrom
test-improver/has-server-guard-policies-d333f53a9d0ac420

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 6, 2026

Test Improvements: has_server_guard_policies_test.go

File Analyzed

  • Test File: internal/server/has_server_guard_policies_test.go
  • Package: internal/server
  • Lines of Code: 65 → 126 (added 5 new test cases)

Improvements Made

1. Increased Coverage

The function hasServerGuardPolicies iterates cfg.Servers and returns true on the first server that has a non-empty GuardPolicies map, or false if 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:

  • ✅ Added: Empty Servers map (no servers configured → false)
  • ✅ Added: Multiple servers all without guard policies (full iteration, all misses → false)
  • ✅ Added: Multiple servers where only one has guard policies (early return on match → true)
  • ✅ Added: Multiple servers all with guard policies (immediate early return → true)
  • ✅ Added: Mix of servers with/without empty guard-policies maps (confirms {} counts as absent → false)

2. Cleaner Test Structure

  • ✅ Extracted shared allowOnlyPolicy fixture to reduce duplication across test cases
  • ✅ Renamed test cases to follow the <scenario> returns <result> naming convention, making failures self-documenting
  • ✅ Removed redundant custom failure message from assert.Equal (testify already provides clear diffs)

Why These Changes?

hasServerGuardPolicies is 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

Generated by Test Improver · ● 4.4M ·

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>
@lpcox lpcox marked this pull request as ready for review April 6, 2026 14:42
Copilot AI review requested due to automatic review settings April 6, 2026 14:42
@lpcox lpcox merged commit 1d39bf8 into main Apr 6, 2026
3 checks passed
@lpcox lpcox deleted the test-improver/has-server-guard-policies-d333f53a9d0ac420 branch April 6, 2026 14:42
Copy link
Copy Markdown
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 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 allowOnlyPolicy fixture to reduce duplication across test cases.
  • Expanded TestHasServerGuardPolicies with 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

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