Commit 1d39bf8
authored
[test-improver] Improve tests for server hasServerGuardPolicies (#3273)
## 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](https://github.com/github/gh-aw-mcpg/actions/runs/24030278829/agentic_workflow)
· ● 4.4M ·
[◷](https://github.com/search?q=repo%3Agithub%2Fgh-aw-mcpg+%22gh-aw-workflow-id%3A+test-improver%22&type=pullrequests)
<!-- gh-aw-agentic-workflow: Test Improver, engine: copilot, model:
auto, id: 24030278829, workflow_id: test-improver, run:
https://github.com/github/gh-aw-mcpg/actions/runs/24030278829 -->
<!-- gh-aw-workflow-id: test-improver -->1 file changed
+73
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
11 | 18 | | |
12 | 19 | | |
13 | 20 | | |
14 | 21 | | |
15 | 22 | | |
16 | 23 | | |
17 | | - | |
| 24 | + | |
18 | 25 | | |
19 | 26 | | |
20 | 27 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 28 | + | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
34 | | - | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| |||
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
45 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
46 | 91 | | |
47 | 92 | | |
48 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
49 | 111 | | |
50 | 112 | | |
51 | 113 | | |
| |||
58 | 120 | | |
59 | 121 | | |
60 | 122 | | |
61 | | - | |
| 123 | + | |
62 | 124 | | |
63 | 125 | | |
64 | 126 | | |
0 commit comments