githubfake

package
v1.62.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package githubfake is one GitHub organisation, in memory, answering the calls the controller makes and changing as they change it.

For tests only. It is a package rather than a test file because two packages test against it: the GitHub client, and the controller that drives it end to end.

Index

Constants

View Source
const (
	ClientID     = "Iv1.link"
	ClientSecret = "link-secret"
)

ClientID and ClientSecret are the link App's, as the fake knows them.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID    int64
	Login string
	// Emails are the account's addresses, to whether GitHub verified each.
	Emails map[string]bool
	// Access and Refresh are the pair currently valid, empty when none is.
	Access, Refresh string
	// contains filtered or unexported fields
}

Account is one GitHub account a person can authorize the link App as.

type App

type App struct {
	ID          int64
	Slug        string
	Permissions map[string]string
	Events      []string
}

App is the App as GitHub holds it: what its owner last saved in its settings.

type Budget

type Budget struct {
	Cost, Remaining int
	ResetAt         time.Time
}

Budget is a GraphQL point budget as the query reports it.

type FailedInvitation

type FailedInvitation struct {
	Login    string
	FailedAt time.Time
}

FailedInvitation is an invitation that expired.

type Installation

type Installation struct {
	Account             string
	Permissions         map[string]string
	RepositorySelection string
}

Installation is one installation of the App: the permissions its owner accepted, which lag the App's until they approve a request.

type Invitation

type Invitation struct {
	ID    int64
	Email string
	// Login is set for an invitation to an account rather than an address.
	Login string
	Teams []int64
}

Invitation is a pending invitation.

type Member

type Member struct {
	ID     int64
	Login  string
	Owner  bool
	Emails []string
}

Member is one member.

type Org

type Org struct {
	Login string
	// Members by login.
	Members map[string]*Member
	// Teams by slug.
	Teams map[string]*Team
	// Invitations by address.
	Invitations map[string]*Invitation
	// Token is the installation token every call must carry.
	Token string
	// Actions is every change made, in order, as "verb target".
	Actions []string
	// Refuse makes the next matching write fail, keyed by the action text.
	Refuse map[string]string
	// GraphQLError, when set, is returned inside a 200 from the members
	// query, as GitHub does.
	GraphQLError string
	// Budget, when set, is what the members query reports as its
	// `rateLimit`, so a test can ask for a wait before the next page.
	Budget *Budget

	// Rejections are answers served before any handler, in order, each
	// once: a rate limit as GitHub sends it. Hits counts every request by
	// "METHOD path", rejected ones included.
	Rejections []Rejection
	Hits       map[string]int

	// Accounts are the GitHub accounts people link, by login, whether or
	// not they are members.
	Accounts map[string]*Account
	// UsersDown makes every call made with a person's token fail with a
	// 502, as an outage would.
	UsersDown bool
	// Seats and Filled are the plan; Seats zero is a plan the App may not
	// read, as without organisation administration.
	Seats, Filled int
	// Failed are failed invitations.
	Failed []FailedInvitation
	// Collaborators are outside collaborators, by login.
	Collaborators []string
	// Public are the addresses accounts show on their profiles, by login.
	Public map[string]string
	// App is what GET /app answers, asked as the App.
	App App
	// Installations are the App's installations, by id.
	Installations map[int64]*Installation
	// AppReads counts the calls made as the App to read it or one of its
	// installations.
	AppReads int
	// TokenRequests are the installation tokens asked for, in order, with
	// the narrowing each asked for.
	TokenRequests []TokenRequest
	// Uninstalled are installation ids GitHub no longer knows: minting a
	// token for one is a 404.
	Uninstalled map[int64]bool
	// Repositories are the repositories every installation can reach.
	// Empty reaches any; otherwise a token narrowed to another is a 422,
	// as GitHub answers.
	Repositories []string
	// contains filtered or unexported fields
}

Org is the organisation's state.

func Start

func Start(t *testing.T, login string) *Org

Start serves the organisation and points the GitHub client at it for the test's duration. Tests using it must not run in parallel with each other: the client's base URL is shared.

func (*Org) Accept

func (o *Org) Accept(email, login string, verified bool)

Accept has somebody accept their invitation with an account: they become a member, in the invitation's teams.

func (*Org) AcceptAccount

func (o *Org) AcceptAccount(login string)

AcceptAccount has a linked account accept its invitation: it becomes a member, in the invitation's teams.

func (*Org) AddAccount

func (o *Org) AddAccount(login string, emails ...string) *Account

AddAccount creates a GitHub account with verified addresses; an address ending in "?" is on the account and unverified.

func (*Org) AddMember

func (o *Org) AddMember(login string, owner bool, emails ...string)

AddMember puts somebody in the organisation.

func (*Org) AddTeam

func (o *Org) AddTeam(slug string, members ...string)

AddTeam creates a team with members; maintainers are marked with a trailing "*".

func (*Org) Authorize

func (o *Org) Authorize(login string) string

Authorize has the account authorize the link App, and returns the code its callback would carry.

func (*Org) Client

func (o *Org) Client() *http.Client

Client is an HTTP client for the fake.

func (*Org) Did

func (o *Org) Did() []string

Did reports the changes made so far.

func (*Org) Hit

func (o *Org) Hit(key string) int

Hit is how many requests "METHOD path" has had, rejected ones included.

func (*Org) Join

func (o *Org) Join(login string)

Join makes a linked account a member, as accepting an invitation would.

func (*Org) Revoke

func (o *Org) Revoke(login string)

Revoke has the account revoke its authorization: every token it was issued stops working.

func (*Org) SetEmail

func (o *Org) SetEmail(login, email string, verified, remove bool)

SetEmail changes one address on an account: verified, unverified, or — with remove — gone.

type Rejection

type Rejection struct {
	// Path is the request path it answers, e.g. "/graphql".
	Path   string
	Status int
	Header map[string]string
	Body   string
}

Rejection is one canned answer to the next request for a path.

type Team

type Team struct {
	ID      int64
	Slug    string
	Members map[string]bool
}

Team is one team: logins to whether they maintain it.

type TokenRequest

type TokenRequest struct {
	Installation int64
	// Body is the narrowing as sent, nil when the request had no body.
	Body *githubapp.Narrowing
}

TokenRequest is one installation token asked for.

Jump to

Keyboard shortcuts

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