Documentation
¶
Overview ¶
Package fakegh is an in-memory GitHub REST and GraphQL server for the endpoints loupe calls, reached through the production client so request encoding is exercised end to end.
Index ¶
- Constants
- func IsolateConfig(dir string) error
- type CheckRun
- type Outcome
- type Request
- type Server
- func (s *Server) AddIssueComment(owner, repo string, number int, c github.IssueComment) github.IssueComment
- func (s *Server) AddReview(owner, repo string, number int, review github.Review)
- func (s *Server) AddReviewThread(owner, repo string, number int, t github.ReviewThread)
- func (s *Server) AllowUser()
- func (s *Server) Client(t *testing.T) github.Client
- func (s *Server) CreateCount() int
- func (s *Server) DenyUser()
- func (s *Server) EditReview(owner, repo string, number int, id int64, body string)
- func (s *Server) Fail(method, path string, status int)
- func (s *Server) FailAfter(method, path string, after, status int)
- func (s *Server) NewClient() (github.Client, error)
- func (s *Server) OnCreate(fn func(*http.Request))
- func (s *Server) OnUpdate(fn func(*http.Request))
- func (s *Server) QueueCreate(outcomes ...Outcome)
- func (s *Server) QueueUpdate(outcomes ...Outcome)
- func (s *Server) Requests() []Request
- func (s *Server) SeedCheckRun(owner, repo, sha string, r CheckRun)
- func (s *Server) SeedWorkflowRun(owner, repo string, r WorkflowRun)
- func (s *Server) SetBranch(owner, repo string, number int, branch string)
- func (s *Server) SetCommits(owner, repo string, number int, commits ...github.Commit)
- func (s *Server) SetComparison(owner, repo, base, head string, c github.Comparison)
- func (s *Server) SetForkBranch(owner, repo string, number int, headOwner, branch string)
- func (s *Server) SetHead(owner, repo string, number int, sha string)
- func (s *Server) SetLatestRelease(tag string)
- func (s *Server) SetPR(owner, repo string, pr github.PullRequest)
- func (s *Server) SetPageSize(n int)
- func (s *Server) SetViewer(login string)
- func (s *Server) StallLatestRelease() <-chan struct{}
- func (s *Server) StallPullRequest() <-chan struct{}
- func (s *Server) UpdateCount() int
- type WorkflowRun
Constants ¶
const PullRequestCommitCap = 250
PullRequestCommitCap is the most commits GitHub lists for a pull request.
Variables ¶
This section is empty.
Functions ¶
func IsolateConfig ¶
IsolateConfig points GH_CONFIG_DIR at dir for the whole process. A TestMain whose tests call t.Parallel MUST call it before m.Run, because Client otherwise calls t.Setenv, which panics in a parallel test.
Types ¶
type CheckRun ¶ added in v0.25.0
type CheckRun struct {
Name, Status, Conclusion, DetailsURL string
}
CheckRun is one check run on a commit. An empty Conclusion or DetailsURL is sent as null, as GitHub does for a run that has not finished or links nowhere.
type Outcome ¶
type Outcome struct {
// contains filtered or unexported fields
}
func OKWithoutIdentity ¶
func OKWithoutIdentity() Outcome
OKWithoutIdentity stores nothing and returns 200 with an empty object, a success that names no review.
func Reject422Errors ¶
Reject422Errors stores nothing and returns 422 in GitHub's shape with a generic message and the reasons in errors.
func ServerErrorAfterRecord ¶
func ServerErrorAfterRecord() Outcome
ServerErrorAfterRecord stores the review and still returns 500, as when GitHub's response is lost.
func ServerErrorDrop ¶
func ServerErrorDrop() Outcome
ServerErrorDrop returns 500 without storing anything.
func Unauthorized ¶
func Unauthorized() Outcome
Unauthorized stores nothing and returns 401, as when GitHub rejects the token.
type Request ¶
type Server ¶
type Server struct {
URL string
// contains filtered or unexported fields
}
func Start ¶
func Start() (s *Server, stop func())
Start serves the fake outside a test, for the demo program; stop closes the listener.
func (*Server) AddIssueComment ¶
func (s *Server) AddIssueComment(owner, repo string, number int, c github.IssueComment) github.IssueComment
AddIssueComment stores a top-level pull request comment and returns it with its id and URL.
func (*Server) AddReview ¶
AddReview stores a review as if it already existed; a zero ID and empty HTMLURL are assigned.
func (*Server) AddReviewThread ¶
func (s *Server) AddReviewThread(owner, repo string, number int, t github.ReviewThread)
AddReviewThread stores an inline thread. A comment's User ending in [bot] is served as a GraphQL Bot without the suffix, and an empty User as a deleted account, so the client's naming is exercised.
func (*Server) AllowUser ¶
func (s *Server) AllowUser()
AllowUser undoes DenyUser, for a test that hands the same pull request from an App back to a person.
func (*Server) Client ¶
Client builds the production REST client against this server with a fixed token.
func (*Server) CreateCount ¶
CreateCount is the number of review creation requests received, whatever their outcome.
func (*Server) DenyUser ¶
func (s *Server) DenyUser()
DenyUser makes GET /user answer 403, as GitHub does for an App installation token. The created review's author still follows SetViewer.
func (*Server) EditReview ¶
EditReview replaces a stored review's body, as another round or the author on GitHub would.
func (*Server) Fail ¶
Fail answers every later request with method and exact path with status, after recording it; status 0 stops.
func (*Server) FailAfter ¶
FailAfter answers the requests with method and exact path with status once after have been answered normally, so a listing can fail on a later page.
func (*Server) NewClient ¶
NewClient is Client for a caller without a test, which MUST point GH_CONFIG_DIR away from the developer's own.
func (*Server) OnCreate ¶
OnCreate runs fn on every review creation request before the server stores or responds to anything. fn may read the request body.
func (*Server) OnUpdate ¶
OnUpdate runs fn on every review edit request before the server stores or responds to anything.
func (*Server) QueueCreate ¶
QueueCreate sets the outcomes of the next review creations in order; once empty, creations succeed.
func (*Server) QueueUpdate ¶
QueueUpdate sets the outcomes of the next review body edits in order; once empty, edits succeed. A rejection or a dropped edit leaves the body as it was, and ServerErrorAfterRecord replaces it.
func (*Server) SeedCheckRun ¶ added in v0.25.0
SeedCheckRun adds a check run on sha, listed in the order seeded.
func (*Server) SeedWorkflowRun ¶ added in v0.25.0
func (s *Server) SeedWorkflowRun(owner, repo string, r WorkflowRun)
SeedWorkflowRun adds an Actions run to the repository, listed in the order seeded and filtered by head_sha.
func (*Server) SetBranch ¶
SetBranch names the pull request's head branch for the branch lookup endpoint.
func (*Server) SetCommits ¶
SetCommits is the pull request's commit list, in the oldest-first order loupe assumes GitHub uses. The fake lists at most PullRequestCommitCap of them, as GitHub does.
func (*Server) SetComparison ¶
func (s *Server) SetComparison(owner, repo, base, head string, c github.Comparison)
SetComparison is what comparing base to head returns; a pair never set is a 404, as for a commit GitHub does not have.
func (*Server) SetForkBranch ¶
SetForkBranch names a head branch that lives in headOwner's fork.
func (*Server) SetLatestRelease ¶
SetLatestRelease sets the tag GET /repos/{owner}/{repo}/releases/latest answers with, for every repository.
func (*Server) SetPageSize ¶
SetPageSize caps every listing's page at n items whatever the client asks for, as GitHub MAY, so a test crosses pages with a few items; 0 removes the cap.
func (*Server) StallLatestRelease ¶
func (s *Server) StallLatestRelease() <-chan struct{}
StallLatestRelease makes the latest-release request hang until the caller cancels it. The returned channel closes when the first such request reaches the server, so a test cancels on arrival, not on a timer.
func (*Server) StallPullRequest ¶
func (s *Server) StallPullRequest() <-chan struct{}
StallPullRequest makes the single pull request request hang until the caller cancels it. The returned channel closes when the first such request reaches the server, so a test can cancel a request it knows is in flight.
func (*Server) UpdateCount ¶
UpdateCount is the number of review edit requests received, whatever their outcome.
type WorkflowRun ¶ added in v0.25.0
WorkflowRun is one Actions run. Path is the workflow file, such as .github/workflows/review.yml.