ghtest

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package ghtest provides minimal test helpers for code that uses ghkit. It is shape-correct, not behaviour-correct: see TESTING.md for the full recipe set and the boundary the helpers do and do not cover.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LinkHeader added in v1.4.0

func LinkHeader(baseURL string, page, perPage, lastPage int) string

LinkHeader builds an RFC 8288 Link header value for pagination fixtures. baseURL is the request URL without the page or per_page query string (e.g. "https://api.example/items"); page and perPage are 1-indexed; lastPage is the final page number.

First page omits prev and first; last page omits next and last. Returns "" when lastPage <= 1, the convention go-github sees on a single-page response.

func Write304IfMatch

func Write304IfMatch(w http.ResponseWriter, r *http.Request, body []byte) bool

Write304IfMatch computes the expected ETag for body using the bored-engineer algorithm (which hashes the request's Authorization, Accept, and Cookie headers along with the body). If any tag in If-None-Match (split on commas, trimmed, and normalised to strip the W/ weak prefix and surrounding quotes) matches, it sets a quoted ETag response header per RFC 7232, writes 304 Not Modified with empty body, and returns true. Otherwise it writes nothing and returns false.

func WriteSecondaryLimit

func WriteSecondaryLimit(w http.ResponseWriter, retryAfter time.Duration)

WriteSecondaryLimit writes a 403 with a Retry-After header (whole seconds) and a JSON body whose documentation_url ends in #secondary-rate-limits. That suffix is what go-github pattern-matches on to classify the error as an AbuseRateLimitError, so the consumer's retry path actually triggers in tests. Negative durations are clamped to zero.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL