{"modulePath":"github.com/impulseframework/bedrock","version":"v0.1.4","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package githubtest\n\nPackage 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.\n\n## Functions\n\n```go\nfunc AppJWT(t *testing.T, appID string, key *rsa.PrivateKey) string\n```\nAppJWT mints the JWT a GitHub App authenticates as, issued by appID and signed with the key, for a test that calls the app's own endpoints on the stand-in.\n\n## Types\n\n```go\ntype App struct {\n\tKey           *rsa.PublicKey\n\tRecord        github.App\n\tInstallations []github.Installation\n}\n```\nApp 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.\n\n```go\ntype Deployment struct {\n\tID       int64\n\tRequest  github.DeploymentRequest\n\tStatuses []github.DeploymentStatus\n}\n```\nDeployment is one deployment made through the API and the statuses added to it.\n\n```go\ntype Dispatch struct {\n\tFile   string\n\tRef    string\n\tInputs map[string]string\n}\n```\nDispatch is one workflow\\_dispatch event: the workflow file, the ref and the inputs.\n\n```go\ntype EnvSecret struct {\n\t// Value is the plaintext: what the stand-in found on opening the sealed value a put\n\t// carried, with the key pair an organization secret's is opened with (OrgSecret).\n\tValue []byte\n\t// UpdatedAt is when the value was last put; every put sets it.\n\tUpdatedAt time.Time\n}\n```\nEnvSecret is one Actions secret of an environment.\n\n```go\ntype Environment struct {\n\t// Custom says the environment takes deployments from the branches its own patterns\n\t// name alone (the API's custom_branch_policies), as a put through the API makes it.\n\t// One without it is an environment any branch may deploy to: the API describes it\n\t// with no branch policy and refuses it a pattern (404), as GitHub does.\n\tCustom bool\n\t// Branches are the name patterns of the branches that may deploy, in the order they\n\t// were added; Tags the tags' patterns, which a test seeds (the API here adds none)\n\t// and the listing carries after the branches', each marked as a tag's.\n\tBranches []string\n\tTags     []string\n\t// Secrets are the environment's Actions secrets, by name: the ones a test seeds and\n\t// the ones put through the API.\n\tSecrets map[string]*EnvSecret\n}\n```\nEnvironment is one deployment environment of a repository.\n\n```go\ntype OrgSecret struct {\n\t// Value is the plaintext: what the stand-in found on opening the sealed value a put\n\t// carried, so a test can assert what was sealed. GitHub never gives it back, and\n\t// neither does any answer of the stand-in.\n\tValue []byte\n\t// Visibility is the secret's visibility as the put gave it (all, private, selected).\n\tVisibility string\n\t// RepositoryIDs are the ids of the repositories selected for the secret, as the\n\t// last put or the last setting of its selection carried them: an empty list, not\n\t// nil, for a JSON array of none.\n\tRepositoryIDs []int64\n\t// UpdatedAt is when the value was last put; every put sets it.\n\tUpdatedAt time.Time\n}\n```\nOrgSecret is one Actions secret of an organization.\n\n```go\ntype Repo struct {\n\t// ID is the repository's id, which an organization secret's selection names it by. A\n\t// repository added (AddRepo) or made through the API with none gets the next of the\n\t// stand-in's ids, and one a test put in Repos directly gets its own the first time the\n\t// API serves it, so the API never answers 0.\n\tID int64\n\t// Private says the repository is private: as a test set it, as its creation through\n\t// the API asked, or as a PATCH with private last set it.\n\tPrivate bool\n\t// Refs by full name (refs/heads/master, refs/tags/v0.1.0) to the object they point at;\n\t// the branches listing is the refs/heads entries, none for an empty repository.\n\tRefs map[string]github.Object\n\t// TagObjects by SHA: the commit each annotated tag object names.\n\tTagObjects map[string]string\n\t// Ancestry lists, per commit, the commits reachable from it (itself included), so a\n\t// comparison can be answered: base...head is identical when equal, ahead when base\n\t// is reachable from head, behind when the reverse, diverged otherwise.\n\tAncestry map[string][]string\n\t// MergeBase by \"a b\" (either order) for a diverged pair.\n\tMergeBase map[string]string\n\t// Trees by commit SHA, and Files by \"\u003ctree\u003e:\u003cpath\u003e\" to the blob's content; Blobs\n\t// by SHA. A commit made through the API gets a tree that copies its base tree's\n\t// files with the entries changed.\n\tTrees map[string]string\n\tFiles map[string]string\n\tBlobs map[string]string\n\t// Comments by issue or pull request number, oldest first; a comment posted through\n\t// the API is appended.\n\tComments map[int][]github.Comment\n\t// Releases by tag.\n\tReleases map[string]github.Release\n\t// Changed lists, per head commit, the files a comparison against it names.\n\tChanged map[string][]string\n\t// Archived says the repository was archived through the API (PATCH with archived).\n\tArchived bool\n\t// PullStates by pull request number: open or closed.\n\tPullStates map[int]string\n\t// PullRequests as the API lists them, oldest first; one opened through the API is\n\t// appended, numbered after the highest number the repository knows.\n\tPullRequests []github.PullRequest\n\t// Deployments made through the API, oldest first, with their statuses.\n\tDeployments []*Deployment\n\t// Dispatches is the workflow_dispatch events started, oldest first.\n\tDispatches []Dispatch\n\t// Workflows are the paths of the workflows GitHub lists for the repository\n\t// (.github/workflows/ci.yml), in listing order; a dispatch of a file the listing lacks\n\t// is answered 404 as GitHub answers it. Nil models no listing, and every file dispatches.\n\tWorkflows []string\n\t// Rulesets are the repository's rulesets, made or replaced through the API, with\n\t// their ids; Settings its merge settings, as read and as set through the API.\n\tRulesets []*github.Ruleset\n\tSettings github.RepositorySettings\n\t// Environments are the repository's deployment environments, by name; one put\n\t// through the API is added.\n\tEnvironments map[string]*Environment\n\t// Issues are the repository's issues, oldest first; one opened through the API is\n\t// appended, numbered after the highest issue or pull request number the repository\n\t// knows, and its body kept in IssueBodies by that number. The listing of issues\n\t// carries the pull requests of PullRequests too, each with a pull_request key, as\n\t// GitHub's does.\n\tIssues      []*github.Issue\n\tIssueBodies map[int]string\n\t// CheckRuns are the check runs by the ref they are asked for with: a commit SHA, or\n\t// a branch or tag name. A name with no entry of its own is resolved through Refs to\n\t// its commit, and answered with that commit's runs.\n\tCheckRuns map[string][]github.CheckRun\n}\n```\nRepo is one repository's state.\n\n```go\ntype Server struct {\n\t*httptest.Server\n\n\tRepos map[string]*Repo\n\t// AppID and AppKey are the GitHub App whose JWT the installation endpoints accept;\n\t// AppInstallation is its installation's id. The installation token it mints is the\n\t// token every other endpoint accepts.\n\tAppID           string\n\tAppKey          *rsa.PublicKey\n\tAppInstallation int64\n\t// Apps are the apps the stand-in knows beside that one, by App ID: a JWT issued by\n\t// one is verified with its key, and GET /app and GET /app/installations answer with\n\t// its record and installations. Conversions are the apps a manifest's code makes\n\t// (POST /app-manifests/\u003ccode\u003e/conversions), by code; a code is good once.\n\tApps        map[string]*App\n\tConversions map[string]*github.App\n\n\t// Calls records every method and path served, in order; Messages the commit\n\t// messages of commits made through the API.\n\tCalls    []string\n\tMessages []string\n\t// Bodies are the bodies of the pull requests opened through the API, oldest first.\n\tBodies []string\n\t// Created are the repositories made through the API (owner/name), oldest first.\n\tCreated []string\n\t// Login is who the token belongs to, as /user answers; octocat by default.\n\t// Memberships are the token's user's roles in organizations, by organization (admin\n\t// for an owner, member); an organization not listed answers not found.\n\tLogin       string\n\tMemberships map[string]string\n\t// DefaultBranch is the organization's setting for a new repository's initial branch\n\t// (main by default), which GitHub uses whatever the creation asks.\n\tDefaultBranch string\n\t// The organizations' Actions settings, by organization: Variables by name, the\n\t// runner groups and the hosted runners made through the API. PublicApps are the apps\n\t// read by slug (/apps/\u003cslug\u003e); OrgInstallations the apps installed on an\n\t// organization, as its listing gives them.\n\tVariables        map[string]map[string]github.Variable\n\tRunnerGroups     map[string][]*github.RunnerGroup\n\tHostedRunners    map[string][]*github.HostedRunner\n\tPublicApps       map[string]github.App\n\tOrgInstallations map[string][]github.OrgInstallation\n\t// OrgSecrets are the organizations' Actions secrets, by organization then name: the\n\t// ones a test seeds and the ones put through the API. OrgRulesets are the\n\t// organizations' own rulesets, by organization, made, replaced and removed through\n\t// the API, with their ids.\n\tOrgSecrets  map[string]map[string]*OrgSecret\n\tOrgRulesets map[string][]*github.Ruleset\n\t// An organization in OrgSecretsRefused answers every request about its Actions\n\t// secrets 403, Resource not accessible by integration, whether the secret named\n\t// stands or not: GitHub's answer to an app that does not hold the organization's\n\t// Secrets permission.\n\tOrgSecretsRefused map[string]bool\n\t// Failing answers a request made with the token, by its method and path (GET\n\t// /repos/o/r/issues/7/comments), with the status named, before the token's routes\n\t// look at it: a call GitHub fails, for a test of what a run does when one does. The\n\t// routes an app's JWT opens (/app/...) and a manifest's conversion are served before\n\t// it and never fail by it. Set under Update once the server serves.\n\tFailing map[string]int\n\t// ImmutableReleases are the organizations' policies on immutable releases, by\n\t// organization: all, none or selected, none for an organization that never set one.\n\t// An organization in ImmutableReleasesHidden answers not found to the read and the\n\t// set alike, as GitHub answers a token that may not administer the organization.\n\tImmutableReleases       map[string]string\n\tImmutableReleasesHidden map[string]bool\n\t// contains filtered or unexported fields\n}\n```\nServer is the stand-in.\n\n```go\nfunc New(t *testing.T) *Server\n```\nNew starts the stand-in; it stops when the test ends.\n\n```go\nfunc (s *Server) AddRepo(owner, name string, repo *Repo) *Repo\n```\nAddRepo registers a repository with its state.\n\n```go\nfunc (s *Server) Client() *github.Client\n```\nClient is the real client pointed at the stand-in.\n\n```go\nfunc (s *Server) Update(fn func())\n```\nUpdate runs fn with the stand-in's lock held, for a test that changes the stand-in while the code under test is calling it: a browser flow's goroutine registering the app GitHub would have made, as the serving goroutines read the same maps.\n\n","path":"github.com/impulseframework/bedrock/internal/github/githubtest","name":"githubtest","synopsis":"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.","isRedistributable":true}
