Documentation ¶
Overview ¶
Package gerritfake implements fake Gerrit for needs of CV tests.
Index ¶
- func CI(change int, mods ...CIModifier) *gerritpb.ChangeInfo
- func LastMessage(ci *gerritpb.ChangeInfo) *gerritpb.ChangeMessageInfo
- func NonZeroVotes(ci *gerritpb.ChangeInfo, label string) []*gerritpb.ApprovalInfo
- func RelatedChange(change, ps, curPs int, parents ...interface{}) *gerritpb.GetRelatedChangesResponse_ChangeAndCommit
- func ResetVotes(ci *gerritpb.ChangeInfo, labels ...string)
- func Rev(ch, ps int) string
- func RevInfo(ps int) *gerritpb.RevisionInfo
- func ShouldLastMessageContain(actual interface{}, oneSubstring ...interface{}) string
- func U(username string) *gerritpb.AccountInfo
- type AccessCheck
- type CIModifier
- func AllRevs() CIModifier
- func CQ(value int, timeAndUser ...interface{}) CIModifier
- func Desc(cldescription string) CIModifier
- func Files(fs ...string) CIModifier
- func Messages(msgs ...*gerritpb.ChangeMessageInfo) CIModifier
- func Owner(username string) CIModifier
- func PS(ps int) CIModifier
- func Project(p string) CIModifier
- func Ref(ref string) CIModifier
- func Status(s interface{}) CIModifier
- func Updated(t time.Time) CIModifier
- func Vote(label string, value int, timeAndUser ...interface{}) CIModifier
- type Change
- type Client
- func (client *Client) GetChange(ctx context.Context, in *gerritpb.GetChangeRequest, opts ...grpc.CallOption) (*gerritpb.ChangeInfo, error)
- func (client *Client) GetRelatedChanges(ctx context.Context, in *gerritpb.GetRelatedChangesRequest, ...) (*gerritpb.GetRelatedChangesResponse, error)
- func (client *Client) ListChanges(ctx context.Context, in *gerritpb.ListChangesRequest, opts ...grpc.CallOption) (*gerritpb.ListChangesResponse, error)
- func (client *Client) ListFiles(ctx context.Context, in *gerritpb.ListFilesRequest, opts ...grpc.CallOption) (*gerritpb.ListFilesResponse, error)
- func (client *Client) SetReview(ctx context.Context, in *gerritpb.SetReviewRequest, opts ...grpc.CallOption) (*gerritpb.ReviewResult, error)
- func (client *Client) SubmitRevision(ctx context.Context, in *gerritpb.SubmitRevisionRequest, ...) (*gerritpb.SubmitInfo, error)
- type Fake
- func (f *Fake) AddFrom(other *Fake) *Fake
- func (f *Fake) CreateChange(c *Change)
- func (f *Fake) DeleteChange(host string, change int)
- func (f *Fake) Factory() gerrit.ClientFactory
- func (f *Fake) GetChange(host string, change int) *Change
- func (f *Fake) Has(host string, change int) bool
- func (f *Fake) MutateChange(host string, change int, mut func(c *Change))
- func (f *Fake) Requests() []proto.Message
- func (f *Fake) SetDependsOn(host string, child interface{}, parents ...interface{})
- type Operation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CI ¶
func CI(change int, mods ...CIModifier) *gerritpb.ChangeInfo
CI creates a new ChangeInfo with 1 patchset with status NEW and without any votes.
func LastMessage ¶
func LastMessage(ci *gerritpb.ChangeInfo) *gerritpb.ChangeMessageInfo
LastMessage returns the last message from the Gerrit Change.
Return nil if there are no messages.
func NonZeroVotes ¶
func NonZeroVotes(ci *gerritpb.ChangeInfo, label string) []*gerritpb.ApprovalInfo
NonZeroVotes returns all non-zero votes for the provided label.
Return nil slice if label doesn't exist.
func RelatedChange ¶
func RelatedChange(change, ps, curPs int, parents ...interface{}) *gerritpb.GetRelatedChangesResponse_ChangeAndCommit
RelatedChange returns ChangeAndCommit for the GetRelatedChangesResponse.
Parents can be specified in several ways:
- gerritpb.CommitInfo_Parent
- gerritpb.CommitInfo
- "<change>_<patchset>", e.g. "123_4"
- "<revision>" (without underscores).
func ResetVotes ¶
func ResetVotes(ci *gerritpb.ChangeInfo, labels ...string)
ResetVotes resets all non-0 votes of the given labels to 0.
func Rev ¶
Rev generates revision in the form "rev-000006-013" where 6 and 13 are change and patchset numbers, respectively.
func RevInfo ¶
func RevInfo(ps int) *gerritpb.RevisionInfo
func ShouldLastMessageContain ¶
func ShouldLastMessageContain(actual interface{}, oneSubstring ...interface{}) string
ShouldLastMessageContain asserts the last posted message on a ChangeInfo contains the expected substring.
func U ¶
func U(username string) *gerritpb.AccountInfo
U returns a Gerrit User for `username`@example.com as gerritpb.AccountInfo.
AccountID is either 1 or taken from the ending digits of a username.
Types ¶
type AccessCheck ¶
func ACLGrant ¶
func ACLGrant(op Operation, code codes.Code, luciProjects ...string) AccessCheck
ACLGrant grants a permission to given projects.
func ACLPublic ¶
func ACLPublic() AccessCheck
ACLPublic grants what every registered user can do on public projects.
func ACLReadOnly ¶
func ACLReadOnly(luciProjects ...string) AccessCheck
ACLReadOnly grants read-only access to the given projects.
func ACLRestricted ¶
func ACLRestricted(luciProjects ...string) AccessCheck
ACLRestricted grants full access to specified projects only.
func (AccessCheck) Or ¶
func (a AccessCheck) Or(bs ...AccessCheck) AccessCheck
Or returns the "less restrictive" status of the 2+ AccessChecks.
{OK, FAILED_PRECONDITION} <= PERMISSION_DENIED <= NOT_FOUND. Doesn't work well with other statuses.
type CIModifier ¶
type CIModifier func(ci *gerritpb.ChangeInfo)
func AllRevs ¶
func AllRevs() CIModifier
AllRevs ensures ChangeInfo has a RevisionInfo per each revision corresponding to patchsets 1..current.
func CQ ¶
func CQ(value int, timeAndUser ...interface{}) CIModifier
CQ is a shorthand for Vote("Commit-Queue", ...).
func Desc ¶
func Desc(cldescription string) CIModifier
Desc sets commit message, aka CL description, for ChangeInfo's current revision.
func Files ¶
func Files(fs ...string) CIModifier
Files sets ChangeInfo's current revision to contain given files.
func Messages ¶
func Messages(msgs ...*gerritpb.ChangeMessageInfo) CIModifier
Messages sets .Messages to the given messages.
func Owner ¶
func Owner(username string) CIModifier
Owner sets .Owner to the given username.
See U() for format.
func PS ¶
func PS(ps int) CIModifier
PS ensures ChangeInfo's CurrentRevision corresponds to given patchset, and deletes all revisions with bigger patchsets.
func Status ¶
func Status(s interface{}) CIModifier
Status sets .Status to the given status. Either a string or value of gerritpb.ChangeStatus.
func Vote ¶
func Vote(label string, value int, timeAndUser ...interface{}) CIModifier
Vote sets a label to the given value by the given user(s) on the latest patchset.
type Change ¶
type Change struct { Host string Info *gerritpb.ChangeInfo ACLs AccessCheck }
Change = change details + ACLs.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements client for Fake Gerrit.
func (*Client) GetChange ¶
func (client *Client) GetChange(ctx context.Context, in *gerritpb.GetChangeRequest, opts ...grpc.CallOption) (*gerritpb.ChangeInfo, error)
Loads a change by id.
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-change
func (*Client) GetRelatedChanges ¶
func (client *Client) GetRelatedChanges(ctx context.Context, in *gerritpb.GetRelatedChangesRequest, opts ...grpc.CallOption) (*gerritpb.GetRelatedChangesResponse, error)
Retrieves related changes of a revision.
Related changes are changes that either depend on, or are dependencies of the revision.
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-related-changes
func (*Client) ListChanges ¶
func (client *Client) ListChanges(ctx context.Context, in *gerritpb.ListChangesRequest, opts ...grpc.CallOption) (*gerritpb.ListChangesResponse, error)
Lists changes that match a query.
Note, although the Gerrit API supports multiple queries, for which it can return multiple lists of changes, this is not a foreseen use-case so this API just includes one query with one returned list of changes.
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes
func (*Client) ListFiles ¶
func (client *Client) ListFiles(ctx context.Context, in *gerritpb.ListFilesRequest, opts ...grpc.CallOption) (*gerritpb.ListFilesResponse, error)
Lists the files that were modified, added or deleted in a revision.
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-files
func (*Client) SetReview ¶
func (client *Client) SetReview(ctx context.Context, in *gerritpb.SetReviewRequest, opts ...grpc.CallOption) (*gerritpb.ReviewResult, error)
Set various review bits on a change.
Currently, only support following functionalities:
- Post Message.
- Set votes on a label (by project itself or on behalf of other user)
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#set-review
func (*Client) SubmitRevision ¶
func (client *Client) SubmitRevision(ctx context.Context, in *gerritpb.SubmitRevisionRequest, opts ...grpc.CallOption) (*gerritpb.SubmitInfo, error)
Submit a specific revision of a change.
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#submit-revision
type Fake ¶
type Fake struct {
// contains filtered or unexported fields
}
Fake simulates Gerrit for CV tests.
func WithCIs ¶
func WithCIs(host string, acls AccessCheck, cis ...*gerritpb.ChangeInfo) *Fake
WithCIs returns a Fake with one change per passed ChangeInfo sharing the same host and ACLs.
func (*Fake) AddFrom ¶
AddFrom adds all changes from another fake to the this fake and returns this fake.
Changes are added by reference. Primarily useful to construct Fake with CLs on several hosts, e.g.:
fake := WithCIs(hostA, aclA, ciA1, ciA2).AddFrom(hostB, aclB, ciB1)
func (*Fake) CreateChange ¶
CreateChange adds a change that must not yet exist.
func (*Fake) DeleteChange ¶
DeleteChange deletes a change that must exist. Panics otherwise.
func (*Fake) Factory ¶
func (f *Fake) Factory() gerrit.ClientFactory
func (*Fake) MutateChange ¶
MutateChange modifies a change while holding a lock blocking concurrent RPCs. Change must exist. Panics otherwise.
func (*Fake) Requests ¶
Requests returns a shallow copy of all incoming requests this fake has received.
func (*Fake) SetDependsOn ¶
SetDependsOn establishes Git relationship between a child CL and 1 or more parents, which are considered dependencies of the child CL.
Child and each parent can be specified as either:
- Change or ChangeInfo, in which case their current patchset is used,
- <change>_<patchset>, e.g. "10_3".
type Operation ¶
type Operation int
const ( // OpRead gates Fetch CL metadata, files, related CLs. OpRead Operation = iota // OpReview gates posting comments and votes on one's own behalf. // // NOTE: The actual Gerrit service has per-label ACLs for voting, but CV // doesn't vote on its own. OpReview // OpVote gates altering votes of behalf of others. OpAlterVotesOfOthers // OpSubmit gates submitting. OpSubmit )