Documentation
¶
Overview ¶
Package gitlabtest is an in-memory GitLab behind httptest, for tests.
It serves the REST paths the client uses and models the platform facts of docs/architecture.md §2 the server depends on: 404 for a private project, the catch-all route shape, offset and keyset pagination with their edges, 429 in both body shapes, a moved project, OAuth with immediately rotating refresh tokens, and quick actions run from a note. Everything in it is generated (§9.1).
Index ¶
- Constants
- Variables
- type Fault
- type Options
- type Request
- type Server
- func (s *Server) Approvals(projectPath string, iid int64, user string) (gitlab.Approvals, bool)
- func (s *Server) BranchHead(projectPath, branch string) (gitlab.Commit, bool)
- func (s *Server) Comment(projectPath, kind string, iid int64, user, body string) (gitlab.Note, bool)
- func (s *Server) Discussions(projectPath, kind string, iid int64) []gitlab.Discussion
- func (s *Server) Drafts(projectPath string, iid int64) []gitlab.DraftNote
- func (s *Server) EditWikiPage(projectPath, slug, content string) bool
- func (s *Server) FileAt(projectPath, branch, path string) (string, bool)
- func (s *Server) Inject(f Fault)
- func (s *Server) Issue(projectPath string, iid int64) (gitlab.Issue, bool)
- func (s *Server) IssueLinks() int
- func (s *Server) Job(projectPath string, id int64) (gitlab.Job, bool)
- func (s *Server) JobInputsSent() map[string]any
- func (s *Server) MergeRequest(projectPath string, iid int64) (gitlab.MergeRequest, bool)
- func (s *Server) Pipeline(projectPath string, id int64) (gitlab.PipelineDetail, bool)
- func (s *Server) ProjectID(path string) int64
- func (s *Server) PushTo(projectPath, branch string) (string, bool)
- func (s *Server) Rebases() int
- func (s *Server) Refreshes() int
- func (s *Server) Release(projectPath, tag string) (gitlab.Release, bool)
- func (s *Server) Requests() []Request
- func (s *Server) ResetRequests()
- func (s *Server) ReviewerState(projectPath string, iid int64, user string) string
- func (s *Server) Revoke(token string)
- func (s *Server) SetHeadPipelineStatus(projectPath string, iid int64, status string) bool
- func (s *Server) SetIssuesAccess(projectPath, level string) bool
- func (s *Server) SetJobLog(projectPath string, id int64, status, log string, archived bool) bool
- func (s *Server) SetMRDiffs(projectPath string, iid int64, diffs []gitlab.Diff) bool
- func (s *Server) SetMergeStatus(projectPath string, iid int64, status string) bool
- func (s *Server) SnippetVisibility(id int64) string
- func (s *Server) TodoState(id int64) string
- func (s *Server) Token() string
- func (s *Server) TokenFor(user string, scopes ...string) string
- func (s *Server) TouchNote(projectPath, kind string, iid, noteID int64, at time.Time) bool
- func (s *Server) WikiPage(projectPath, slug string) (gitlab.WikiPage, bool)
Constants ¶
const ( // PipelineFailed is a failed pipeline on ProjectAlpha's main. PipelineFailed = 61001 // JobPassed passed; JobFailed failed its script and has a long log // with the synthetic token in it; JobAllowed failed and was allowed // to; JobManual waits for a person. JobPassed = 70001 JobFailed = 70002 JobAllowed = 70003 JobManual = 70004 // BridgeFailed is a trigger job on PipelineFailed whose downstream // pipeline, DownstreamFailed, failed. BridgeFailed = 79001 DownstreamFailed = 62001 // FakeToken is the synthetic token JobFailed's log prints. FakeToken = "glpat-" + "EXAMPLE0000000000000000000" // LogFiller is how many lines of test output JobFailed's log holds, // enough to be longer than one default window. LogFiller = 2500 )
Fixture CI ids tests address.
const ( // ProjectAlpha is public; alice maintains it. It has issues, merge // requests, discussions, files, branches and commits. ProjectAlpha = "example-group/alpha" // ProjectBeta is private under a subgroup; alice is a member. ProjectBeta = "example-group/sub/beta" // ProjectSecret is private and alice is not a member, so it answers // 404 exactly as a missing project does. ProjectSecret = "example-group/secret" // ProjectMoved is the old path of ProjectAlpha: a GET redirects, any // other method is 405. ProjectMoved = "example-group/old-alpha" // GroupTop and GroupSub are the two groups. GroupTop = "example-group" GroupSub = "example-group/sub" // DefaultUser is who a default token and an authorization act as. DefaultUser = "alice" )
Fixture names tests address.
const ( // MilestoneActive and MilestoneClosed are ProjectAlpha's; the group // milestone is GroupTop's. MilestoneActive = 90001 MilestoneClosed = 90002 MilestoneGroup = 90003 // GroupLabel is a label GroupTop defines for every project under it. GroupLabel = "group-wide" // TodoAssigned, TodoReview and TodoDone are alice's to-do items. TodoAssigned = 95001 TodoReview = 95002 TodoDone = 95003 )
Fixture ids tests address.
const ( TagRelease = "v1.0" TagPlain = "v0.9" )
Tags on ProjectAlpha: an annotated, protected tag with a release on release/1.0's head, and a lightweight one on main's head.
const ( // SnippetAlpha is bob's snippet in ProjectAlpha, two files long. SnippetAlpha = 80001 // SnippetPersonal is alice's private personal snippet. SnippetPersonal = 80002 // WikiNested is a wiki page whose slug holds a slash. WikiNested = "guides/setup" )
Fixture ids and names tests address.
const ClientID = "gitlabtest-application-id"
ClientID is the OAuth application's id.
const ConflictSHA = "c0ffee0000000000000000000000000000000000"
ConflictSHA is a commit whose cherry-pick or revert conflicts on every branch.
Variables ¶
var Users = []string{"alice", "bob", "carol", "dave"}
Users is the synthetic user list, in id order from 1001.
Functions ¶
This section is empty.
Types ¶
type Fault ¶
type Fault struct {
Method string
Path string
Times int
Status int
Header http.Header
Body string
// Delay holds the answer before its headers are written.
Delay time.Duration
// StallAfter writes the headers and part of Body, then waits this
// long before the rest.
StallAfter time.Duration
// AfterApply serves the request first, so a write lands, then
// discards that answer and sends the fault's: the answer to a write
// that succeeded was lost.
AfterApply bool
}
Fault is an injected answer. It replaces the next Times requests whose method (empty for any) and escaped path under /api/v4 (prefix match, "/projects" matches "/projects/2001/issues") match.
func Application429 ¶
Application429 is an application limit's 429: JSON, with Retry-After and no RateLimit-* headers.
func RackAttack429 ¶
RackAttack429 is the instance throttle's 429: a plain-text body with Retry-After and RateLimit-* headers.
type Options ¶
type Options struct {
// TotalLimit is the count past which X-Total and X-Total-Pages are
// dropped. GitLab's is 10,000; a test sets a small one.
TotalLimit int
// OffsetCap is the offset past which an endpoint with keyset
// pagination answers 405. GitLab's is 50,000.
OffsetCap int
// ExtraProjects adds public projects example-group/bulk-0001… for
// paging tests.
ExtraProjects int
// AlphaIssues, AlphaMergeRequests and AlphaCommits size ProjectAlpha.
// Defaults 25, 3 and 30.
AlphaIssues int
AlphaMergeRequests int
AlphaCommits int
// Version and Enterprise are what /metadata reports. Default
// "19.4.0", Community Edition.
Version string
Enterprise bool
// Confidential makes the OAuth application confidential: the token
// endpoint then refuses a request without ClientSecret.
Confidential bool
ClientSecret string
// RedirectURIs are the application's registered redirect URIs.
// Default http://127.0.0.1/callback.
RedirectURIs []string
// AuthorizeAs is the user an authorization signs in as. Default alice.
AuthorizeAs string
// AccessTokenTTL is expires_in. Default 7,200 s.
AccessTokenTTL time.Duration
// Now is the clock. Default time.Now.
Now func() time.Time
// MoveDropsQuery makes the redirect for a moved project carry the
// new path without the request's query string.
MoveDropsQuery bool
}
Options shape the instance. Zero values take the defaults.
type Request ¶
type Request struct {
Method string
EscapedPath string
RawQuery string
Authorization string
UserAgent string
// IfUnmodifiedSince is the header a conditional delete sends.
IfUnmodifiedSince string
}
Request is one request the instance received.
type Server ¶
Server is the in-memory instance. URL is its base, and the instance to configure is that URL.
func (*Server) BranchHead ¶
BranchHead returns a branch's head commit.
func (*Server) Comment ¶
func (s *Server) Comment(projectPath, kind string, iid int64, user, body string) (gitlab.Note, bool)
Comment plants a comment by user on an issue (kind "issue") or a merge request (kind "mr"), as content someone else wrote. It runs no quick action: it is a fixture, not a write through the API.
func (*Server) Discussions ¶
func (s *Server) Discussions(projectPath, kind string, iid int64) []gitlab.Discussion
Discussions returns a copy of an issue's (kind "issue") or a merge request's (kind "mr") discussions.
func (*Server) EditWikiPage ¶
EditWikiPage changes a page's content, as an edit made elsewhere does.
func (*Server) IssueLinks ¶
IssueLinks counts the links the instance holds.
func (*Server) JobInputsSent ¶
JobInputsSent are the input values the last job retry or play sent.
func (*Server) MergeRequest ¶
MergeRequest returns a copy of a merge request, for a test to check what a write did.
func (*Server) Refreshes ¶
Refreshes counts refresh grants that succeeded, for a test of the cross-process lock.
func (*Server) ResetRequests ¶
func (s *Server) ResetRequests()
ResetRequests forgets the recorded requests.
func (*Server) ReviewerState ¶
ReviewerState is the reviewer state a user last submitted with a review of a merge request, "" for none.
func (*Server) SetHeadPipelineStatus ¶
SetHeadPipelineStatus sets the status of a merge request's head pipeline, as CI running or failing does.
func (*Server) SetIssuesAccess ¶
SetIssuesAccess sets who sees a project's issues: enabled, private or disabled.
func (*Server) SetJobLog ¶
SetJobLog replaces a job's log and state. An archived log is also a trace artifact of its size, as GitLab lists one once it archives the log.
func (*Server) SetMRDiffs ¶
SetMRDiffs replaces the files a merge request changes.
func (*Server) SetMergeStatus ¶
SetMergeStatus sets a merge request's detailed_merge_status, as GitLab's checks do.
func (*Server) SnippetVisibility ¶
SnippetVisibility is a snippet's visibility, "" when there is none.