{"modulePath":"github.com/TerracodeBA/vx","version":"v0.3.0","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package githubtest\n\nPackage githubtest is a fake GitHub for tests: an httptest server with the parts of the REST API and the browser flows vx uses, plus helpers to create users, organizations and repositories, set permissions, install the App and fire signed webhook deliveries.\n\nThe fake serves the browser side at URL (like [https://github.com](https://github.com)) and the API at APIURL = URL + \"/api/v3\" (like GitHub Enterprise Server), so tests exercise configurable base URLs.\n\n\tgh := githubtest.New(t)\n\tcreds := gh.NewApp()                  // or the manifest flow\n\tapi := gh.Client(t)                   // *github.Client against the fake\n\talice := gh.AddUser(\"alice\")\n\tgh.AddOrg(\"acme\")\n\tgh.AddRepo(\"acme/shop\", false)\n\tgh.SetPermission(\"acme/shop\", \"alice\", \"write\")\n\tinst := gh.Install(\"acme\")            // all repositories of acme\n\tgh.Deliver(t, server.URL+\"/hooks/github\", \"installation\", gh.InstallationEvent(\"created\", inst))\n\n## Functions\n\n```go\nfunc DeliveryIDAt(t time.Time) string\n```\nDeliveryIDAt returns a delivery id made at t, for tests of stale deliveries.\n\n```go\nfunc NewDeliveryID() string\n```\nNewDeliveryID returns a delivery id like GitHub's: a version 1 UUID, which carries the time it was made (now).\n\n```go\nfunc Sign(secret string, body []byte) string\n```\nSign returns the X-Hub-Signature-256 value of body with secret.\n\n## Types\n\n```go\ntype Account struct {\n\tID    int64\n\tLogin string\n\tType  string // User or Organization\n\tName  string\n\tEmail string // primary verified email; empty: none shared\n}\n```\nAccount is a GitHub user or organization.\n\n```go\ntype Delivery struct {\n\tEvent     string\n\tID        string // X-GitHub-Delivery; empty: a new random id\n\tBody      []byte\n\tSignature string // X-Hub-Signature-256; empty: signed with the webhook secret, \"-\": no header\n}\n```\nDelivery is one webhook delivery.\n\n```go\ntype Installation struct {\n\tID          int64\n\tAccount     string // login\n\tAll         bool   // repository_selection all\n\tRepos       []int64\n\tSuspendedAt *time.Time\n}\n```\nInstallation is an installation of the App.\n\n```go\ntype Repo struct {\n\tID            int64\n\tOwner         string\n\tName          string\n\tDefaultBranch string\n\tPrivate       bool\n}\n```\nRepo is a repository on the fake.\n\n```go\nfunc (r Repo) FullName() string\n```\nFullName is owner/name.\n\n```go\ntype Server struct {\n\t// URL is the browser base (WebURL), APIURL the REST API base.\n\tURL    string\n\tAPIURL string\n\t// Now is the fake's clock, for token expiry and App JWT checks.\n\tNow func() time.Time\n\t// TokenTTL is how long installation tokens live (default one hour).\n\tTokenTTL time.Duration\n\t// PageSize is the page size of paginated lists (default 30), so tests\n\t// see pagination with few repositories.\n\tPageSize int\n\t// contains filtered or unexported fields\n}\n```\nServer is a fake GitHub. Its methods are safe for concurrent use.\n\n```go\nfunc New(t testing.TB) *Server\n```\nNew starts a fake GitHub, closed when the test ends.\n\n```go\nfunc (s *Server) Account(login string) (Account, bool)\n```\nAccount returns an account by login.\n\n```go\nfunc (s *Server) AddInstallationRepos(id int64, repos ...string)\n```\nAddInstallationRepos adds repositories to a \"selected\" installation.\n\n```go\nfunc (s *Server) AddOrg(login string) Account\n```\nAddOrg creates an organization.\n\n```go\nfunc (s *Server) AddRepo(fullName string, private bool) Repo\n```\nAddRepo creates owner/name (the owner must exist) with default branch main.\n\n```go\nfunc (s *Server) AddUser(login string) Account\n```\nAddUser creates a user with name = login and email login@example.com.\n\n```go\nfunc (s *Server) App() (service.GitHubAppCredentials, bool)\n```\nApp returns the App's credentials; ok is false before it exists.\n\n```go\nfunc (s *Server) Calls(pattern string) int\n```\nCalls returns how many requests matched \"METHOD /path\" so far, with numbers and names in the path as sent, e.g. \"POST /app/installations/1001/access\\_tokens\". A pattern ending in \"\\*\" matches by prefix. API paths are given without the /api/v3 prefix.\n\n```go\nfunc (s *Server) Client(t testing.TB) *github.Client\n```\nClient returns a github.Client for the App against the fake, creating the App first if it does not exist yet.\n\n```go\nfunc (s *Server) Close()\n```\nClose stops the server early; New already closes it at the end of the test.\n\n```go\nfunc (s *Server) Configure(t testing.TB, svc *service.Service) service.GitHubAppCredentials\n```\nConfigure is Prepare plus an App: it creates the App on the fake (if it does not exist) and saves it in svc, so svc.GitHubClient, svc.GitHubApp and webhook verification work.\n\n```go\nfunc (s *Server) Connector() func(service.GitHubAppCredentials) (service.GitHubAPI, error)\n```\nConnector returns a service.GitHubSettings.Connect function that makes clients against the fake.\n\n```go\nfunc (s *Server) DeleteInstallation(id int64)\n```\nDeleteInstallation uninstalls the App; its tokens stop working.\n\n```go\nfunc (s *Server) DeleteRepo(fullName string) Repo\n```\nDeleteRepo deletes a repository and returns what it was.\n\n```go\nfunc (s *Server) Deliver(t testing.TB, hookURL, event string, payload any) int\n```\nDeliver posts a webhook event signed with the App's webhook secret, with a new delivery id made at s.Now(), and returns the response status code.\n\n```go\nfunc (s *Server) DeliverRaw(t testing.TB, hookURL string, d Delivery) int\n```\nDeliverRaw posts a delivery as given, for tests of bad signatures and replays, and returns the response status code.\n\n```go\nfunc (s *Server) DenyAuthorization(deny bool)\n```\nDenyAuthorization makes the authorize page redirect back with error=access\\_denied, as when the person cancels.\n\n```go\nfunc (s *Server) ExpireTokens()\n```\nExpireTokens makes every installation and user token invalid.\n\n```go\nfunc (s *Server) Fail(pattern string, status, n int)\n```\nFail makes the next n requests matching pattern (see Calls) fail with status. 403 and 429 come back as rate limits, as GitHub sends them.\n\n```go\nfunc (s *Server) Install(account string, repos ...string) int64\n```\nInstall installs the App on an account. With no repositories it gets all of the account's repositories, now and later.\n\n```go\nfunc (s *Server) Installation(id int64) (Installation, bool)\n```\nInstallation returns an installation.\n\n```go\nfunc (s *Server) InstallationEvent(action string, id int64) map[string]any\n```\nInstallationEvent is an \"installation\" payload: created, deleted, suspend, unsuspend, new\\_permissions\\_accepted.\n\n```go\nfunc (s *Server) InstallationReposEvent(action string, id int64, repos ...string) map[string]any\n```\nInstallationReposEvent is an \"installation\\_repositories\" payload: added or removed, listing repos (full names).\n\n```go\nfunc (s *Server) InstallationTokenFor(id int64) string\n```\nInstallationTokenFor mints an installation token directly.\n\n```go\nfunc (s *Server) Manifest() map[string]any\n```\nManifest returns the manifest the App was created from (decoded JSON).\n\n```go\nfunc (s *Server) ManifestCode(manifestJSON []byte) string\n```\nManifestCode registers a manifest as if a site admin had posted it to GitHub and confirmed, and returns the one-time code GitHub sends back.\n\n```go\nfunc (s *Server) MemberEvent(installationID int64, action, fullName, login string) map[string]any\n```\nMemberEvent is a \"member\" payload (a repository collaborator): added, removed or edited.\n\n```go\nfunc (s *Server) MembershipEvent(installationID int64, action, org, team, login string) map[string]any\n```\nMembershipEvent is a \"membership\" payload (team membership): added or removed.\n\n```go\nfunc (s *Server) NewApp() service.GitHubAppCredentials\n```\nNewApp creates the App directly, as if the manifest flow had run, and returns its credentials.\n\n```go\nfunc (s *Server) OAuthCode(login, redirectURI, codeChallenge string) string\n```\nOAuthCode mints a sign-in code for login, as GitHub's authorize page would after the person approved. codeChallenge is the PKCE S256 challenge (\"\" for none); redirectURI must match the exchange's.\n\n```go\nfunc (s *Server) OrgMemberEvent(installationID int64, action, org, login, role string) map[string]any\n```\nOrgMemberEvent is an \"organization\" payload: member\\_added, member\\_removed or member\\_invited.\n\n```go\nfunc (s *Server) Prepare(t testing.TB, svc *service.Service)\n```\nPrepare points svc at the fake without creating an App: a random server key, the fake's URLs, Connect, and PublicURL [http://vx.test](http://vx.test) when empty. The manifest flow can then run.\n\n```go\nfunc (s *Server) PushEvent(installationID int64, fullName, ref, before, after string) map[string]any\n```\nPushEvent is a \"push\" payload to ref (e.g. refs/heads/main).\n\n```go\nfunc (s *Server) RemoveInstallationRepos(id int64, repos ...string)\n```\nRemoveInstallationRepos removes repositories from an installation (an \"all\" installation becomes \"selected\").\n\n```go\nfunc (s *Server) RenameAccount(login, newLogin string)\n```\nRenameAccount changes a user's or organization's login (the id stays).\n\n```go\nfunc (s *Server) RenameRepo(fullName, newName string) Repo\n```\nRenameRepo renames a repository (its id stays).\n\n```go\nfunc (s *Server) Repo(fullName string) (Repo, bool)\n```\nRepo returns a repository by full name.\n\n```go\nfunc (s *Server) RepoRenamedEvent(installationID int64, fullName, oldName string) map[string]any\n```\nRepoRenamedEvent is a \"repository\" renamed payload; call it after RenameRepo with the old name.\n\n```go\nfunc (s *Server) RepoTransferredEvent(installationID int64, fullName, oldOwner string) map[string]any\n```\nRepoTransferredEvent is a \"repository\" transferred payload; call it after TransferRepo with the old owner.\n\n```go\nfunc (s *Server) RepositoryEvent(action string, installationID int64, r Repo) map[string]any\n```\nRepositoryEvent is a \"repository\" payload for r (from Repo, or the value DeleteRepo returned): deleted, privatized, publicized, edited, archived.\n\n```go\nfunc (s *Server) SetDefaultBranch(fullName, branch string)\n```\nSetDefaultBranch changes a repository's default branch.\n\n```go\nfunc (s *Server) SetOrgMember(org, login, role string)\n```\nSetOrgMember sets login's role in an organization: admin, member, or \"\" to remove them.\n\n```go\nfunc (s *Server) SetPermission(fullName, login, perm string)\n```\nSetPermission sets login's permission on a repository: admin, maintain, write, triage, read, or none/\"\" to remove it.\n\n```go\nfunc (s *Server) SetPrivate(fullName string, private bool) Repo\n```\nSetPrivate changes a repository's visibility.\n\n```go\nfunc (s *Server) SetProfile(login, name, email string)\n```\nSetProfile sets a user's name and primary verified email (\"\" for none).\n\n```go\nfunc (s *Server) SetupClient(t testing.TB) *github.Client\n```\nSetupClient returns a client without App credentials, which can only complete the manifest flow.\n\n```go\nfunc (s *Server) Sign(body []byte) string\n```\nSign returns the X-Hub-Signature-256 value of body with the App's webhook secret.\n\n```go\nfunc (s *Server) SignIn(login string)\n```\nSignIn makes login the person signed in at the fake's web pages, so /login/oauth/authorize approves for them right away. \"\" signs out.\n\n```go\nfunc (s *Server) SuspendInstallation(id int64, suspended bool)\n```\nSuspendInstallation suspends or unsuspends an installation.\n\n```go\nfunc (s *Server) TeamAddEvent(installationID int64, org, team, fullName string) map[string]any\n```\nTeamAddEvent is a \"team\\_add\" payload: a team got access to a repository.\n\n```go\nfunc (s *Server) TeamEvent(installationID int64, action, org, team, fullName string) map[string]any\n```\nTeamEvent is a \"team\" payload: created, deleted, edited, added\\_to\\_repository or removed\\_from\\_repository (fullName may be \"\").\n\n```go\nfunc (s *Server) TransferRepo(fullName, newOwner string) Repo\n```\nTransferRepo moves a repository to another owner (its id stays).\n\n```go\nfunc (s *Server) UserToken(login string) string\n```\nUserToken mints a user access token for login.\n\n","path":"github.com/TerracodeBA/vx/internal/github/githubtest","name":"githubtest","synopsis":"Package githubtest is a fake GitHub for tests: an httptest server with the parts of the REST API and the browser flows vx uses, plus helpers to create users, organizations and repositories, set permissions, install the App and fire signed webhook deliveries.","isRedistributable":true}
