Skip to content

[test-improver] Improve tests for httputil package#7546

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
test/httputil-compute-retry-after-7543f7ede34a7d2e
Draft

[test-improver] Improve tests for httputil package#7546
github-actions[bot] wants to merge 1 commit into
mainfrom
test/httputil-compute-retry-after-7543f7ede34a7d2e

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

File Analyzed

  • Test File: internal/httputil/httputil_test.go
  • Package: internal/httputil
  • Lines Added: +37

Improvements Made

1. Increased Coverage

Added TestComputeRetryAfter to cover the previously untested ComputeRetryAfter function in github_http.go, which was the sole coverage gap in the package.

  • ✅ Added test: zero time → returns default 60s
  • ✅ Added test: time in the past → returns default 60s (the secs < 1 branch)
  • ✅ Added test: future time → returns delay with 1s safety buffer (assert.InDelta used to tolerate scheduling jitter)
  • ✅ Added test: far future (2h) → clamped to 3600s maximum
  • ✅ Added test: just above max (3601s) → still clamped to 3600s

Previous Coverage: 86.8%
New Coverage: 100.0%
Improvement: +13.2%

2. Better Testing Patterns

  • Uses t.Parallel() for all subtests consistent with existing test style
  • Uses assert.InDelta for the timing-sensitive case to avoid flakiness from scheduling jitter
  • Table-free structure matches the function's non-tabular branching logic

Test Execution

All tests pass:

ok  github.com/github/gh-aw-mcpg/internal/httputil  0.008s  coverage: 100.0% of statements

Why These Changes?

ComputeRetryAfter computes the Retry-After delay for rate-limited GitHub API responses. It has four distinct code branches (zero time, past time, within-range future, and over-max future) but had zero test coverage. The function is called when GitHub returns a X-RateLimit-Reset header, making it important for correct retry behaviour.


Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • index.crates.io

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "index.crates.io"

See Network Configuration for more information.

Generated by Test Improver · 611.1 AIC · ⊞ 29.5K ·

Cover all branches of ComputeRetryAfter in github_http.go:
- zero time → default 60s
- past time → default 60s (secs < 1 branch)
- future time → delay with 1s safety buffer
- far future → clamped to 3600s maximum
- just above max → still clamped to 3600s

Brings internal/httputil coverage from 86.8% to 100%.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

0 participants