Documentation
¶
Overview ¶
Package githubtest is a GitHub API stand-in for tests: in-memory organizations with their installed apps, Actions secrets and rulesets, and one or more repositories with rulesets, refs, tags, check runs, environments and issues, served over httptest so the real client speaks to it unchanged.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type App ¶
App is a GitHub App the stand-in answers for: its key verifies the app's JWT, and the record and the installations are what GET /app and GET /app/installations give it.
type Deployment ¶
type Deployment struct {
ID int64
Request github.DeploymentRequest
Statuses []github.DeploymentStatus
}
Deployment is one deployment made through the API and the statuses added to it.
type EnvSecret ¶
type EnvSecret struct {
// Value is the plaintext: what the stand-in found on opening the sealed value a put
// carried, with the key pair an organization secret's is opened with (OrgSecret).
Value []byte
// UpdatedAt is when the value was last put; every put sets it.
UpdatedAt time.Time
}
EnvSecret is one Actions secret of an environment.
type Environment ¶
type Environment struct {
// Custom says the environment takes deployments from the branches its own patterns
// name alone (the API's custom_branch_policies), as a put through the API makes it.
// One without it is an environment any branch may deploy to: the API describes it
// with no branch policy and refuses it a pattern (404), as GitHub does.
Custom bool
// Branches are the name patterns of the branches that may deploy, in the order they
// were added; Tags the tags' patterns, which a test seeds (the API here adds none)
// and the listing carries after the branches', each marked as a tag's.
Branches []string
Tags []string
// Secrets are the environment's Actions secrets, by name: the ones a test seeds and
// the ones put through the API.
Secrets map[string]*EnvSecret
}
Environment is one deployment environment of a repository.
type OrgSecret ¶
type OrgSecret struct {
// Value is the plaintext: what the stand-in found on opening the sealed value a put
// carried, so a test can assert what was sealed. GitHub never gives it back, and
// neither does any answer of the stand-in.
Value []byte
// Visibility is the secret's visibility as the put gave it (all, private, selected).
Visibility string
// RepositoryIDs are the ids of the repositories selected for the secret, as the
// last put or the last setting of its selection carried them: an empty list, not
// nil, for a JSON array of none.
RepositoryIDs []int64
// UpdatedAt is when the value was last put; every put sets it.
UpdatedAt time.Time
}
OrgSecret is one Actions secret of an organization.
type Repo ¶
type Repo struct {
// ID is the repository's id, which an organization secret's selection names it by. A
// repository added (AddRepo) or made through the API with none gets the next of the
// stand-in's ids, and one a test put in Repos directly gets its own the first time the
// API serves it, so the API never answers 0.
ID int64
// Private says the repository is private: as a test set it, as its creation through
// the API asked, or as a PATCH with private last set it.
Private bool
// Refs by full name (refs/heads/master, refs/tags/v0.1.0) to the object they point at;
// the branches listing is the refs/heads entries, none for an empty repository.
Refs map[string]github.Object
// TagObjects by SHA: the commit each annotated tag object names.
TagObjects map[string]string
// Ancestry lists, per commit, the commits reachable from it (itself included), so a
// comparison can be answered: base...head is identical when equal, ahead when base
// is reachable from head, behind when the reverse, diverged otherwise.
Ancestry map[string][]string
// MergeBase by "a b" (either order) for a diverged pair.
MergeBase map[string]string
// Trees by commit SHA, and Files by "<tree>:<path>" to the blob's content; Blobs
// by SHA. A commit made through the API gets a tree that copies its base tree's
// files with the entries changed.
Trees map[string]string
Files map[string]string
Blobs map[string]string
// Comments by issue or pull request number, oldest first; a comment posted through
// the API is appended.
Comments map[int][]github.Comment
// Releases by tag.
Releases map[string]github.Release
// Changed lists, per head commit, the files a comparison against it names.
Changed map[string][]string
// Archived says the repository was archived through the API (PATCH with archived).
Archived bool
// PullStates by pull request number: open or closed.
PullStates map[int]string
// PullRequests as the API lists them, oldest first; one opened through the API is
// appended, numbered after the highest number the repository knows.
PullRequests []github.PullRequest
// Deployments made through the API, oldest first, with their statuses.
Deployments []*Deployment
// Dispatches is the workflow_dispatch events started, oldest first.
Dispatches []Dispatch
// Workflows are the paths of the workflows GitHub lists for the repository
// (.github/workflows/ci.yml), in listing order; a dispatch of a file the listing lacks
// is answered 404 as GitHub answers it. Nil models no listing, and every file dispatches.
Workflows []string
// Rulesets are the repository's rulesets, made or replaced through the API, with
// their ids; Settings its merge settings, as read and as set through the API.
Rulesets []*github.Ruleset
Settings github.RepositorySettings
// Environments are the repository's deployment environments, by name; one put
// through the API is added.
Environments map[string]*Environment
// Issues are the repository's issues, oldest first; one opened through the API is
// appended, numbered after the highest issue or pull request number the repository
// knows, and its body kept in IssueBodies by that number. The listing of issues
// carries the pull requests of PullRequests too, each with a pull_request key, as
// GitHub's does.
Issues []*github.Issue
IssueBodies map[int]string
// CheckRuns are the check runs by the ref they are asked for with: a commit SHA, or
// a branch or tag name. A name with no entry of its own is resolved through Refs to
// its commit, and answered with that commit's runs.
CheckRuns map[string][]github.CheckRun
}
Repo is one repository's state.
type Server ¶
type Server struct {
*httptest.Server
Repos map[string]*Repo
// AppID and AppKey are the GitHub App whose JWT the installation endpoints accept;
// AppInstallation is its installation's id. The installation token it mints is the
// token every other endpoint accepts.
AppID string
AppKey *rsa.PublicKey
AppInstallation int64
// Apps are the apps the stand-in knows beside that one, by App ID: a JWT issued by
// one is verified with its key, and GET /app and GET /app/installations answer with
// its record and installations. Conversions are the apps a manifest's code makes
// (POST /app-manifests/<code>/conversions), by code; a code is good once.
Apps map[string]*App
Conversions map[string]*github.App
// Calls records every method and path served, in order; Messages the commit
// messages of commits made through the API.
Calls []string
Messages []string
// Bodies are the bodies of the pull requests opened through the API, oldest first.
Bodies []string
// Created are the repositories made through the API (owner/name), oldest first.
Created []string
// Login is who the token belongs to, as /user answers; octocat by default.
// Memberships are the token's user's roles in organizations, by organization (admin
// for an owner, member); an organization not listed answers not found.
Login string
Memberships map[string]string
// DefaultBranch is the organization's setting for a new repository's initial branch
// (main by default), which GitHub uses whatever the creation asks.
DefaultBranch string
// The organizations' Actions settings, by organization: Variables by name, the
// runner groups and the hosted runners made through the API. PublicApps are the apps
// read by slug (/apps/<slug>); OrgInstallations the apps installed on an
// organization, as its listing gives them.
Variables map[string]map[string]github.Variable
RunnerGroups map[string][]*github.RunnerGroup
HostedRunners map[string][]*github.HostedRunner
PublicApps map[string]github.App
OrgInstallations map[string][]github.OrgInstallation
// OrgSecrets are the organizations' Actions secrets, by organization then name: the
// ones a test seeds and the ones put through the API. OrgRulesets are the
// organizations' own rulesets, by organization, made, replaced and removed through
// the API, with their ids.
OrgSecrets map[string]map[string]*OrgSecret
OrgRulesets map[string][]*github.Ruleset
// ImmutableReleases are the organizations' policies on immutable releases, by
// organization: all, none or selected, none for an organization that never set one.
// An organization in ImmutableReleasesHidden answers not found to the read and the
// set alike, as GitHub answers a token that may not administer the organization.
ImmutableReleases map[string]string
ImmutableReleasesHidden map[string]bool
// contains filtered or unexported fields
}
Server is the stand-in.