v1.2.0
Adds a ghtest sub-package with two helpers that hide the non-discoverable
GitHub-specific traps in testing ghkit-using code: secondary-rate-limit
classification (the documentation_url suffix gofri/go-github-ratelimit
pattern-matches on) and the bored-engineer ETag hash domain (which includes
the request Authorization header). Plus a TESTING.md with self-contained
recipes for the surrounding stdlib bits. No new runtime dependencies.
Added
ghtest sub-package
ghtest.WriteSecondaryLimit(w, retryAfter)writes a 403 withRetry-After
(whole seconds; negative durations clamp to zero) and a JSON body whose
documentation_urlends in#secondary-rate-limits. That suffix is what
gofri/go-github-ratelimitpattern-matches on to classify the response as
anAbuseRateLimitError, so consumer retry paths actually trigger in
tests instead of silently falling through.ghtest.Write304IfMatch(w, r, body) boolcomputes the expected ETag using
the bored-engineer algorithm (hashes Authorization, Accept, and Cookie
request headers along with the body), normalises every tag in
If-None-Match(split on commas, trim whitespace, stripW/weak prefix
and surrounding quotes), and on any match sets a quoted RFC 7232ETag
response header, writes 304 Not Modified with empty body, and returns
true. Returns false and writes nothing on miss.- Both helpers compose with stdlib
httptest.NewServer; consumers bring
their own handler. Tests cover quoted/unquoted/weak-only matches, multi-tag
comma splitting, no-match leaves response untouched, no-header
short-circuit, and different-body misses.
Documentation
- New
TESTING.mdwith self-contained recipes: routing a ghkit-built client
at a test server (thegh.BaseURL = url.Parse(srv.URL+"/")pattern),
ETag 304 replay handling, rate-limit header emission (no helper, recipe
only), Link-header pagination (no helper, recipe only), secondary-rate-
limit testing, plus a "See also" pointer tomigueleliasweb/go-github-mock
for the SDK-layer mocking case. - README "Testing your code" section, three lines linking to
TESTING.md.
Dependencies
No changes. Same as 1.1.0.