githubfake

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package githubfake is a fake of the contents API of GitHub for the tests of the github flag source: the files of one branch of one repository, answered with an ETag and 304, a 404 for a file that is away, a token the server requires, the answers of an exhausted request limit, a redirect, and a record of what the relay sent (path, ref, token and Accept).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Request

type Request struct {
	// Path is the path of the file in the repository.
	Path string
	// Ref is the ref query of the request.
	Ref string
	// Authorization and Accept are the headers of the request.
	Authorization string
	Accept        string
	// RawQuery is the whole query, to show that nothing else is in it.
	RawQuery string
}

Request is what one request carried.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an http.Handler for /<prefix>/repos/<slug>/contents/<path>?ref=<branch>.

func New

func New(prefix, slug, branch string) *Server

New returns a server for the repository slug (owner/repo) and the branch. prefix is the path of the API below the host: empty for github.com, /api/v3 for GitHub Enterprise Server.

func (*Server) Counts

func (s *Server) Counts() httpfake.Counts

Counts returns what the file server answered: requests, bodies and 304 answers.

func (*Server) Delete

func (s *Server) Delete(path string)

Delete removes a file: the path is answered 404.

func (*Server) Dir

func (s *Server) Dir(path string)

Dir makes the path a directory: the contents API answers a key that is a directory with the JSON listing, also when the raw media type was asked for.

func (*Server) Put

func (s *Server) Put(path string, data []byte)

Put sets a file: a new version of the path.

func (*Server) Redirect

func (s *Server) Redirect(path, address string)

Redirect answers a request for the path with a redirect to the address.

func (*Server) Requests

func (s *Server) Requests() []Request

Requests returns what the requests carried, in order.

func (*Server) RequireToken

func (s *Server) RequireToken(token string)

RequireToken makes the server answer 401 to a request that does not carry "Bearer <token>". Empty removes the rule.

func (*Server) Secondary

func (s *Server) Secondary(seconds int)

Secondary makes the server answer every request with 403 and a Retry-After of that many seconds (the secondary limit of GitHub). Zero ends it.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

func (*Server) Throttle

func (s *Server) Throttle(reset time.Time)

Throttle makes the server answer every request with 403 and no request left, resetting at reset. A zero reset ends the throttling.

Jump to

Keyboard shortcuts

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