Documentation
¶
Overview ¶
Package githubtestrepo gives tests real pull requests on github.com to land.
The GitHub merger and the GitHub change provider talk to GitHub's REST API, and only real pull requests show what that API actually does — an in-process fake encodes only our reading of the docs. The suites that verify them (the merger extension test and TestGitHubLandE2E) share this package to open branches and pull requests, link them into stacks, push a new head, read back whether GitHub merged them and with which commit, and remove what they opened.
New skips the calling test unless SQ_GITHUB_TOKEN and SQ_GITHUB_TEST_REPO ("owner/repo") are set, so runs without the credential never touch GitHub. Where the credential is expected — SQ_GITHUB_TEST_REQUIRED=true, which CI sets on every run that can read its secrets — a missing one fails the test instead, so a deleted secret cannot quietly turn these suites into skips. A token GitHub rejects (expired or revoked) always fails. Fixtures are named under sq-it/<run id>/ and closed and deleted when the test ends; what a test merges stays on the repository's default branch.
Index ¶
- Constants
- type Pull
- type PullState
- type TestRepo
- func (r *TestRepo) AwaitPullHead(number int, head string)
- func (r *TestRepo) CommitFile(branch, path, content string) string
- func (r *TestRepo) FileOnTrunk(path string) bool
- func (r *TestRepo) FilePath(name string) string
- func (r *TestRepo) HTTPClient() *http.Client
- func (r *TestRepo) MergeCommit(number int) string
- func (r *TestRepo) OpenChain(name string, n int) []Pull
- func (r *TestRepo) OpenPull(name, base string) Pull
- func (r *TestRepo) OpenStack(name string, n int) []Pull
- func (r *TestRepo) Owner() string
- func (r *TestRepo) PullState(number int) PullState
- func (r *TestRepo) Repo() string
- func (r *TestRepo) RunID() string
- func (r *TestRepo) Token() string
- func (r *TestRepo) Trunk() string
- func (r *TestRepo) URI(p Pull) string
- func (r *TestRepo) URIs(pulls ...Pull) []string
Constants ¶
const ( // TokenEnv names the variable holding a token with write access to the // test repository. TokenEnv = "SQ_GITHUB_TOKEN" // RepoEnv names the variable holding the test repository, "owner/repo". RepoEnv = "SQ_GITHUB_TEST_REPO" // RequiredEnv names the variable that, when "true", makes a missing // TokenEnv or RepoEnv fail the test rather than skip it. RequiredEnv = "SQ_GITHUB_TEST_REQUIRED" // Host is the GitHub instance the test repository's change URIs name. Host = "github.com" // APIBaseURL is the REST API root for Host. APIBaseURL = "https://api.github.com" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pull ¶
type Pull struct {
// Number is the pull request number.
Number int
// Branch is the pull request's head branch.
Branch string
// Head is the head commit the pull request was opened at.
Head string
}
Pull is a fixture pull request.
type PullState ¶
type PullState struct {
// State is "open" or "closed".
State string `json:"state"`
// Merged reports whether the pull request was merged.
Merged bool `json:"merged"`
}
PullState is what GitHub reports about a fixture pull request.
type TestRepo ¶
type TestRepo struct {
// contains filtered or unexported fields
}
TestRepo creates fixtures in the test repository and removes them when the test ends.
func New ¶
New returns a TestRepo for the configured repository. When the credential or repository is not configured it skips the test, or fails it if RequiredEnv is "true".
func (*TestRepo) AwaitPullHead ¶
AwaitPullHead waits until GitHub reports head as the pull request's head. A push reaches the pull request asynchronously, so a staleness check run before that would compare against the old head. Bounded by the test runner's timeout.
func (*TestRepo) CommitFile ¶
CommitFile writes a file on branch and returns the new head commit.
func (*TestRepo) FileOnTrunk ¶
FileOnTrunk reports whether path exists on the trunk.
func (*TestRepo) HTTPClient ¶
HTTPClient is an authenticated client rooted at APIBaseURL.
func (*TestRepo) MergeCommit ¶
MergeCommit is the commit GitHub's merged event records for a pull request, or "" when it has none.
func (*TestRepo) OpenChain ¶
OpenChain opens n pull requests stacked by base branch without creating a GitHub stack.
func (*TestRepo) OpenPull ¶
OpenPull opens one pull request against base that adds a file unique to it.
func (*TestRepo) OpenStack ¶
OpenStack opens n pull requests, each adding its own file, the first based on the trunk and each later one on the branch below it, and links them into a GitHub stack.