Commit 3050fcf
authored
[test-improver] Improve tests for tracing package (#5033)
# Test Improvements: `internal/tracing/http_test.go`
## File Analyzed
- **New Test File**: `internal/tracing/http_test.go`
- **Package**: `internal/tracing`
- **Implementation**: `internal/tracing/http.go` —
`statusResponseWriter` wrapper type
## Improvements Made
### 1. New Test Coverage for `statusResponseWriter`
The `statusResponseWriter` type (used inside `WrapHTTPHandler`) had no
dedicated unit tests:
| Method | Before | After |
|--------|--------|-------|
| `Write` | 66.7% | 100% |
| `Unwrap` | **0.0%** | **100%** |
| `WriteHeader` | 100% | 100% |
**Package total: 95.1% → 96.7%**
### 2. Tests Added
- ✅ `TestStatusResponseWriter_WriteHeader` — verifies status code is
captured and forwarded
- ✅ `TestStatusResponseWriter_Write_SetsImplicit200` — verifies implicit
200 set when `Write` called without prior `WriteHeader`
- ✅ `TestStatusResponseWriter_Write_PreservesExplicitStatus` — verifies
an already-set status isn't overwritten by `Write`
- ✅ `TestStatusResponseWriter_Unwrap_ReturnsUnderlying` — verifies
`Unwrap` returns the wrapped `ResponseWriter`
- ✅ `TestStatusResponseWriter_Unwrap_ExposesOptionalInterfaces` —
verifies `http.ResponseController` can discover `http.Flusher` through
`Unwrap` (the primary reason `Unwrap` exists)
### 3. Idiomatic testify usage
Uses `require.NoError` for fatal checks and `assert.Equal`/`assert.True`
for non-fatal assertions, consistent with the rest of the codebase.
## Test Execution
```
--- PASS: TestStatusResponseWriter_WriteHeader (0.00s)
--- PASS: TestStatusResponseWriter_Write_SetsImplicit200 (0.00s)
--- PASS: TestStatusResponseWriter_Write_PreservesExplicitStatus (0.00s)
--- PASS: TestStatusResponseWriter_Unwrap_ReturnsUnderlying (0.00s)
--- PASS: TestStatusResponseWriter_Unwrap_ExposesOptionalInterfaces (0.00s)
ok github.com/github/gh-aw-mcpg/internal/tracing 0.018s coverage: 96.7% of statements
```
## Why This File?
`statusResponseWriter.Unwrap()` existed specifically to allow
`http.ResponseController` to detect optional interfaces on the
underlying writer (e.g. `http.Flusher`), but had 0% coverage — the most
critical path was completely untested. The `Write` method also had a
branch (implicit-200 assignment) that wasn't exercised. These are small,
focused tests that meaningfully verify the contract of the type.
---
*Generated by Test Improver Workflow*
*Focuses on better patterns, increased coverage, and more stable tests*
> [!WARNING]
> **1 file changed
Lines changed: 73 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 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 | + | |
0 commit comments