Commit e424676
authored
[test-improver] Improve tests for mcptest harness (#2631)
# Test Improvements: `harness_test.go`
## File Analyzed
- **Test File**: `internal/testutil/mcptest/harness_test.go`
- **Package**: `internal/testutil/mcptest`
- **Lines of Code**: 275 → 197 (−78 lines of boilerplate)
## Improvements Made
### 1. Better Testify Assertions
Replaced all manual `if`-block error checking with idiomatic testify
calls:
- ✅ `require.NoError(t, err)` instead of `if err := ...; err != nil {
t.Fatalf(...) }`
- ✅ `require.Len(t, tools, 1)` instead of `if len(tools) != 1 {
t.Errorf(...) }`
- ✅ `assert.Equal(t, "test_echo", tools[0].Name)` instead of nested `if
tools[0].Name != ...`
- ✅ `assert.False(t, result.IsError)` instead of `if result.IsError {
t.Error(...) }`
- ✅ `require.True(t, ok, "Expected *sdk.TextContent")` instead of `if
!ok { t.Error(...) }`
- ✅ `assert.ElementsMatch(t, []string{"echo1", "echo2", "add"},
toolNames)` instead of manual map-lookup loop
- ✅ Added `assert` import alongside existing `require`
### 2. Increased Coverage
- ✅ **Added missing assertion on `add` tool result**: `assert.Equal(t,
"8", textContent.Text)` — the original test called the add tool but
never verified the return value
- ✅ `require.Len` on `result.Content` before accessing
`result.Content[0]`, preventing a potential index panic
### 3. Cleaner & More Stable Tests
- ✅ Removed redundant `if len(x) > 0 { ... }` guards that were only
needed because `t.Errorf` doesn't stop execution (now `require.Len`
stops on failure)
- ✅ Removed `t.Logf("✓ ...")` status messages that added noise without
testing anything
- ✅ Cleaner linear test flow without deeply nested conditionals
- ✅ Consistent `err :=` declaration pattern across all test functions
## Why These Changes?
`harness_test.go` already imported `require` from testify but performed
most assertions via manual `if`-blocks with `t.Errorf`/`t.Fatalf`. This
pattern lets tests continue running after a failure, leading to
confusing cascaded errors (e.g., an index-out-of-bounds panic after a
length mismatch). Converting to testify stops tests at the right
boundary, gives clearer failure messages, and removes substantial
boilerplate.
The missing assertion on the `add` tool result was a genuine coverage
gap — the test confirmed the tool call succeeded but never checked the
computed value.
---
*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/23634910800)
·
[◷](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: 23634910800, workflow_id: test-improver, run:
https://github.com/github/gh-aw-mcpg/actions/runs/23634910800 -->
<!-- gh-aw-workflow-id: test-improver -->1 file changed
Lines changed: 36 additions & 114 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | 7 | | |
10 | 8 | | |
11 | 9 | | |
| 10 | + | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
29 | | - | |
| 27 | + | |
| 28 | + | |
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
| |||
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 40 | + | |
| 41 | + | |
52 | 42 | | |
53 | 43 | | |
54 | 44 | | |
55 | 45 | | |
56 | 46 | | |
57 | 47 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
77 | 53 | | |
78 | 54 | | |
79 | 55 | | |
| |||
111 | 87 | | |
112 | 88 | | |
113 | 89 | | |
114 | | - | |
115 | | - | |
116 | | - | |
| 90 | + | |
| 91 | + | |
117 | 92 | | |
118 | 93 | | |
119 | 94 | | |
| |||
125 | 100 | | |
126 | 101 | | |
127 | 102 | | |
| 103 | + | |
128 | 104 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
145 | 109 | | |
| 110 | + | |
146 | 111 | | |
147 | 112 | | |
148 | 113 | | |
149 | 114 | | |
150 | 115 | | |
151 | 116 | | |
152 | 117 | | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
166 | 123 | | |
167 | 124 | | |
168 | 125 | | |
| |||
183 | 140 | | |
184 | 141 | | |
185 | 142 | | |
186 | | - | |
187 | | - | |
188 | | - | |
| 143 | + | |
| 144 | + | |
189 | 145 | | |
190 | 146 | | |
191 | 147 | | |
| |||
197 | 153 | | |
198 | 154 | | |
199 | 155 | | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
| 156 | + | |
| 157 | + | |
212 | 158 | | |
213 | 159 | | |
214 | | - | |
| 160 | + | |
215 | 161 | | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
233 | 165 | | |
234 | 166 | | |
235 | 167 | | |
| |||
247 | 179 | | |
248 | 180 | | |
249 | 181 | | |
250 | | - | |
251 | | - | |
252 | | - | |
| 182 | + | |
| 183 | + | |
253 | 184 | | |
254 | 185 | | |
255 | 186 | | |
| |||
261 | 192 | | |
262 | 193 | | |
263 | 194 | | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
| 195 | + | |
| 196 | + | |
275 | 197 | | |
0 commit comments