Help us shape the future of Go! Take the 2026 Go Developer Survey

githubfake

package
v1.47.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 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 added in v1.3.0

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 added in v1.11.0

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 FailedInvitation added in v1.5.0

type FailedInvitation struct {
	Login    string
	FailedAt time.Time
}

FailedInvitation is an invitation that expired.

type Installation added in v1.11.0

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

	// 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 added in v1.3.0

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 added in v1.3.0

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 added in v1.3.0

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) Join added in v1.3.0

func (o *Org) Join(login string)

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

func (*Org) Revoke added in v1.3.0

func (o *Org) Revoke(login string)

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

func (*Org) SetEmail added in v1.3.0

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

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

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 added in v1.11.0

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