fakegithub

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 6 Imported by: 0 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 fakegithub is an in-process GitHub for tests. It answers requests by substring match and records them, so tests can assert API call budgets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GitHub

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

GitHub implements http.RoundTripper.

func New

func New(routes ...Route) *GitHub

New returns a GitHub answering with routes, checked in order.

func (*GitHub) Add

func (g *GitHub) Add(routes ...Route)

Add appends routes.

func (*GitHub) Count

func (g *GitHub) Count() int

Count returns how many calls were made.

func (*GitHub) Requests

func (g *GitHub) Requests() []Request

Requests returns every recorded call.

func (*GitHub) RoundTrip

func (g *GitHub) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip records the request and returns the first matching route's response.

type Request

type Request struct {
	Description string
	Variables   map[string]any
	Header      http.Header
	Body        string
}

Request is one recorded call.

type Route

type Route struct {
	Match   string
	Status  int
	Body    string
	Headers map[string]string
	// Times limits how often the route answers; zero means without limit.
	Times int
}

Route answers requests whose description contains Match. The description is the GraphQL query for GraphQL calls, and "METHOD host/path" for everything else.

Jump to

Keyboard shortcuts

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