Documentation
¶
Overview ¶
Package githubtest is a fake GitHub REST server for tests: App and token authentication, organisation and user account listings with pagination, single repositories, rate-limit headers, ETags and 304s, fault injection and a request ledger.
Index ¶
- Constants
- Variables
- type Commit
- type Delivery
- type Issue
- type Pull
- type Release
- type Server
- func (s *Server) AddRepo(org string, r gh.Repository) int64
- func (s *Server) AddToken(tok string)
- func (s *Server) AddUser(login string)
- func (s *Server) AddUserToken(tok, login string)
- func (s *Server) Asked(tok string) []string
- func (s *Server) BaseURL() string
- func (s *Server) Count(prefix string) int
- func (s *Server) Exhaust(credential string)
- func (s *Server) Expires(tok string, end time.Time)
- func (s *Server) Fail(pattern string, status, times int, retryAfter time.Duration)
- func (s *Server) Heal()
- func (s *Server) ID(owner, name string) int64
- func (s *Server) Install(login string) int64
- func (s *Server) Ledger() []string
- func (s *Server) PrivateKeyPEM() []byte
- func (s *Server) Reach(tok string, ids ...int64)
- func (s *Server) Remove(id int64)
- func (s *Server) Select(login string, ids ...int64)
- func (s *Server) SetBranch(id int64, name string, cs ...Commit)
- func (s *Server) SetCommits(id int64, cs ...Commit)
- func (s *Server) SetDeliveries(d ...Delivery)
- func (s *Server) SetFile(id int64, path, content string)
- func (s *Server) SetGrants(login string, permissions map[string]string, events []string)
- func (s *Server) SetIssues(id int64, is ...Issue)
- func (s *Server) SetPulls(id int64, ps ...Pull)
- func (s *Server) SetRelease(id int64, tag, name string, published time.Time)
- func (s *Server) SetReleases(id int64, rels ...Release)
- func (s *Server) SetTag(id int64, name, sha string)
- func (s *Server) SetTreeLimit(n int)
- func (s *Server) Uninstall(login string)
- func (s *Server) Update(id int64, fn func(*gh.Repository))
Constants ¶
const Limit = 5000
Limit is the core rate limit of every credential.
Variables ¶
var ( AllPermissions = map[string]string{"contents": "read", "metadata": "read", "issues": "read", "pull_requests": "read", "checks": "read", "statuses": "read"} AllEvents = []string{"push", "release", "repository", "issues", "pull_request", "pull_request_review"} //nolint:gochecknoglobals // test data )
AllPermissions and AllEvents are what the fake's installations grant unless SetGrants says otherwise: every permission and event the portal asks for.
Functions ¶
This section is empty.
Types ¶
type Commit ¶
type Commit struct {
SHA, Message, AuthorName, AuthorLogin string
Date time.Time
Parents []string // nil: the next commit of the list (a linear history), none for the last
// Additions, Deletions and Files are its diff stats, answered by POST /graphql; all zero: GitHub answers null for it.
Additions, Deletions, Files int
}
Commit is a commit on the fake default branch.
type Delivery ¶
type Delivery struct {
GUID string
Event string
Action string
RepositoryID int64
At time.Time
Status int // the portal's answer; 0: none
}
Delivery is a line of the App's webhook delivery log (SetDeliveries).
type Issue ¶
type Issue struct {
Number int
Title, Author string
Bot bool // the author's account type is Bot
Created, Updated time.Time
Labels []string
Assignees []string
Comments int
Milestone, Type string
}
Issue is an open issue of the fake.
type Pull ¶
type Pull struct {
Number int
Title, Author string
Bot, Draft, Fork bool // Bot: the author's account type is Bot
Created, Updated time.Time
Base, Head, HeadSHA string
Labels []string
Requested int // people asked to review, named reviewer0, reviewer1, ... after Reviewers
Reviewers []string // people asked to review, by login
Review, Mergeable, Checks string // GraphQL's reviewDecision, mergeable and the head's statusCheckRollup state
Approved, Changes bool // a reviewer's latest opinion
Additions, Deletions, Files int
}
Pull is an open pull request of the fake: what the REST listing gives and what POST /graphql answers for it.
type Server ¶
Server is a fake GitHub. Its methods are safe for concurrent use.
func (*Server) AddRepo ¶
func (s *Server) AddRepo(org string, r gh.Repository) int64
AddRepo adds a repository to org and returns its id. Fields left empty get defaults.
func (*Server) AddUser ¶
AddUser makes login a user account (owners are organisations otherwise): GET /orgs/{login}/repos answers 404, its repositories list at /users/{login}/repos (public ones), /user/repos (for its own token) and /installation/repositories.
func (*Server) AddUserToken ¶
AddUserToken accepts tok as a personal access token of the user account login.
func (*Server) Asked ¶
Asked is every request made with the personal token tok (one with a login or a reach), as "METHOD /path status".
func (*Server) Count ¶
Count returns how many requests started with prefix ("GET /orgs/acme/repos").
func (*Server) Exhaust ¶
Exhaust uses up the rate limit of credential (a token, or an installation's account login).
func (*Server) Expires ¶
Expires makes the personal token tok end at end: every answer to it carries GitHub's GitHub-Authentication-Token-Expiration header, and after end it is refused (401).
func (*Server) Fail ¶
Fail makes the next times requests whose "METHOD /path" starts with pattern answer status. A 429 or 403 with retryAfter sends Retry-After (a secondary rate limit).
func (*Server) ID ¶
lookup returns the repository at owner/name. Callers hold s.mu. ID is the id of the repository owner/name, 0 when there is none.
func (*Server) PrivateKeyPEM ¶
PrivateKeyPEM is the App private key.
func (*Server) Reach ¶
Reach limits what the personal token tok reads to the repositories ids, as a person's token reads only what GitHub lets that person read: listings leave the others out and every /repos/{owner}/{name} call of another answers 404. Without it a token reads every one.
func (*Server) Select ¶
Select gives the App's installation on login only the repositories ids ("Only select repositories"; none at all with no ids): /installation/repositories lists only them and the installation listing says "selected". Without it, an installation has all.
func (*Server) SetBranch ¶
SetBranch sets a branch of the repository with id to its own commits, newest first; the last one names its parents in the default branch (or another branch). No commits deletes the branch.
func (*Server) SetCommits ¶
SetCommits replaces the default-branch commits of the repository with id (newest first). No commits means an empty repository.
func (*Server) SetDeliveries ¶
SetDeliveries sets the App's webhook delivery log, newest first.
func (*Server) SetFile ¶
SetFile writes a file on the default branch of the repository with id; an empty content deletes it.
func (*Server) SetGrants ¶
SetGrants sets what the App's installation on login may read and which events it is sent.
func (*Server) SetRelease ¶
SetRelease sets the one release of the repository with id; an empty tag removes it.
func (*Server) SetReleases ¶
SetReleases sets the releases of the repository with id, replacing its earlier ones; GitHub lists them newest first.
func (*Server) SetTag ¶
SetTag points a tag of the repository with id at a commit; an empty SHA deletes it.
func (*Server) SetTreeLimit ¶
SetTreeLimit makes a recursive tree of more than n entries come truncated, its first n entries only, as GitHub truncates one past 100,000 entries or 7 MB; 0 lifts the limit.