Package gerritfake implements fake Gerrit for needs of CV tests.



    This section is empty.


    This section is empty.


    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

        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

              func Rev(ch, ps int) string

                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` as gerritpb.AccountInfo.

                    AccountID is either 1 or taken from the ending digits of a username.


                    type AccessCheck

                    type AccessCheck func(op Operation, luciProject string) *status.Status

                    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 Project

                                            func Project(p string) CIModifier

                                              Project sets .Project to the given Gerrit project.

                                              func Ref

                                              func Ref(ref string) CIModifier

                                                Ref sets .Ref to the given ref.

                                                func Status

                                                func Status(s interface{}) CIModifier

                                                  Status sets .Status to the given status. Either a string or value of gerritpb.ChangeStatus.

                                                  func Updated

                                                  func Updated(t time.Time) CIModifier

                                                    Updated sets .Updated to the given time.

                                                    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) GetRelatedChanges

                                                            Retrieves related changes of a revision.

                                                            Related changes are changes that either depend on, or are dependencies of the revision.


                                                            func (*Client) ListChanges

                                                              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.


                                                              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.


                                                                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)


                                                                  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 WithCLs

                                                                      func WithCLs(cs ...*Change) *Fake

                                                                        WithCLs returns Fake with several changes.

                                                                        func (*Fake) AddFrom

                                                                        func (f *Fake) AddFrom(other *Fake) *Fake

                                                                          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

                                                                          func (f *Fake) CreateChange(c *Change)

                                                                            CreateChange adds a change that must not yet exist.

                                                                            func (*Fake) DeleteChange

                                                                            func (f *Fake) DeleteChange(host string, change int, mut func(c *Change))

                                                                              DeleteChange deletes a change that must exist. Panics otherwise.

                                                                              func (*Fake) GetChange

                                                                              func (f *Fake) GetChange(host string, change int) *Change

                                                                                GetChange returns a mutable Change that must exist. Panics otherwise.

                                                                                The returned Change can be modified, but such modification won't be atomic from perspective of concurrent RPCs. Recommended for use in between the RPCs.

                                                                                func (*Fake) Has

                                                                                func (f *Fake) Has(host string, change int) bool

                                                                                  Has returns if given change exists.

                                                                                  func (*Fake) Install

                                                                                  func (f *Fake) Install(ctx context.Context) context.Context

                                                                                  func (*Fake) MutateChange

                                                                                  func (f *Fake) MutateChange(host string, change int, mut func(c *Change))

                                                                                    MutateChange modifies a change while holding a lock blocking concurrent RPCs. Change must exist. Panics otherwise.

                                                                                    func (*Fake) Requests

                                                                                    func (f *Fake) Requests() []proto.Message

                                                                                      Requests returns a shallow copy of all incoming requests this fake has received.

                                                                                      func (*Fake) SetDependsOn

                                                                                      func (f *Fake) SetDependsOn(host string, child interface{}, parents ...interface{})

                                                                                        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: actual Gerrit has per-label ACLs for voting, but CV doesn't vote on
                                                                                        	// its own.
                                                                                        	// OpVote gates altering votes of behalf of others.
                                                                                        	// OpSubmit gates submitting.