githubfake

package
v1.87.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 17 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 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 Hook added in v1.74.0

type Hook struct {
	URL, ContentType, Secret string
	// Patches counts the PATCH calls made.
	Patches int
}

Hook is an App's webhook configuration. GitHub never returns the secret, so a test reads it here.

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
	// Hook is the App's webhook as GitHub holds it, read and replaced through
	// /app/hook/config.
	Hook Hook
	// Deliveries are the App's webhook deliveries, newest first.
	Deliveries []githubapp.Delivery
	// Redelivered are the delivery ids asked to be sent again, in order.
	Redelivered []int64
	// 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) AddConfiguration added in v1.85.0

func (o *Org) AddConfiguration(name string, settings map[string]string) int64

AddConfiguration puts an organisation configuration in place, as another writer would.

func (*Org) AddGlobalConfiguration added in v1.85.0

func (o *Org) AddGlobalConfiguration(name string)

AddGlobalConfiguration puts a configuration GitHub provides in place; the controller must neither list it as the organisation's nor touch it.

func (*Org) AddMember

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

AddMember puts somebody in the organisation.

func (*Org) AddRepository added in v1.85.0

func (o *Org) AddRepository(name string) int64

AddRepository adds a repository to the organisation and returns its id.

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) Archive added in v1.85.0

func (o *Org) Archive(name string)

Archive archives a repository.

func (*Org) Attach added in v1.85.0

func (o *Org) Attach(config string, repository int64)

Attach attaches a repository to a configuration directly, as another writer would.

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) Configuration added in v1.85.0

func (o *Org) Configuration(name string) *SecurityConfiguration

Configuration is a configuration by name, or nil.

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) OpenSecret added in v1.85.0

func (o *Org) OpenSecret(name string) (string, error)

OpenSecret decrypts what was written for a secret with the organisation's private key, as only GitHub could.

func (*Org) RemoveVariable added in v1.85.0

func (o *Org) RemoveVariable(name string)

RemoveVariable removes a variable, as an operator would on GitHub.

func (*Org) RepositoryID added in v1.85.0

func (o *Org) RepositoryID(name string) int64

RepositoryID is a repository's id, or 0.

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) Secret added in v1.85.0

func (o *Org) Secret(name string) *Secret

Secret is a secret, or nil.

func (*Org) SetDefault added in v1.85.2

func (o *Org) SetDefault(config, value string)

SetDefault makes a configuration the default for new repositories, as another writer would: `all`, `public`, `private_and_internal` or `none`.

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.

func (*Org) SetSecret added in v1.85.0

func (o *Org) SetSecret(name, visibility string)

SetSecret puts a secret in the organisation, as another writer would.

func (*Org) SetVariable added in v1.85.0

func (o *Org) SetVariable(name string, v Variable)

SetVariable puts a variable in the organisation, as another writer would.

func (*Org) Variable added in v1.85.0

func (o *Org) Variable(name string) *Variable

Variable is a variable, or nil.

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

type Repository struct {
	ID       int64
	Name     string
	Archived bool
}

Repository is a repository of the organisation.

type Secret added in v1.85.0

type Secret struct {
	Visibility string
	Selected   []int64
	// KeyID is the key the value was sealed with, and Sealed the base64
	// ciphertext as written. [Org.OpenSecret] opens it.
	KeyID  string
	Sealed string
	// Writes counts how many times the secret was written.
	Writes int
}

Secret is an Actions secret as GitHub keeps it: sealed, never readable.

type SecurityConfiguration added in v1.85.0

type SecurityConfiguration struct {
	ID          int64
	Name        string
	TargetType  string
	Description string
	Settings    map[string]string
	// Attached are the repositories it is attached to, by id, with their status.
	Attached map[int64]string
	// DefaultFor are the kinds of repository, `public` and
	// `private_and_internal`, that a repository created from now on gets this
	// configuration for; empty is nobody's default.
	DefaultFor map[string]bool
}

SecurityConfiguration is a code security configuration.

func (*SecurityConfiguration) Default added in v1.85.2

func (c *SecurityConfiguration) Default() string

Default is the configuration's default for new repositories in the words of the API: `all`, `public`, `private_and_internal` or `none`.

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.

type Variable added in v1.85.0

type Variable struct {
	Value      string
	Visibility string
	// Selected are the repository ids it is visible to, when selected.
	Selected []int64
}

Variable is an Actions variable.

Jump to

Keyboard shortcuts

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