gerritfake

package
v0.0.0-...-ef45db5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package gerritfake implements fake Gerrit for needs of CV tests.

Index

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

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 ...any) *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 any, oneSubstring ...any) 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

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 Approve

func Approve() CIModifier

Approve sets Submittable to true.

func CQ

func CQ(value int, timeAndUser ...any) 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 Disapprove

func Disapprove() CIModifier

Disapprove sets Submittable to false.

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 MetaRevID

func MetaRevID(metaRevID string) CIModifier

MetaRevID sets .MetaRevID for the given change.

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 PSWithUploader

func PSWithUploader(ps int, username string, creationTime time.Time) CIModifier

PSWithUploader does the same as PS, but attaches a user and creation timestamp to the patchset.

func ParentCommits

func ParentCommits(parents []string) CIModifier

ParentCommits sets the parent commits for the current revision.

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 Reviewer

func Reviewer(rs ...*gerritpb.AccountInfo) CIModifier

Reviewer sets the reviewers of the CL.

func Status

func Status(s any) 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 ...any) 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.

func (*Change) Copy

func (c *Change) Copy() *Change

Copy deep-copies a Change. NOTE: ACLs, which is a reference to a func, isn't deep-copied.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements client for Fake Gerrit.

func (*Client) GetRelatedChanges

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

ListAccountEmails returns the email addresses linked in the given Gerrit account.

https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#list-account-emails

func (*Client) ListChanges

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.

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)

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

SetReview sets 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)

SubmitRevision submits 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 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) AddLinkedAccountMapping

func (f *Fake) AddLinkedAccountMapping(emails []*gerritpb.EmailInfo)

AddLinkedAccountMapping maps each of the email to the set of email addresses.

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)

DeleteChange deletes a change that must exist. Panics otherwise.

func (*Fake) GetChange

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

GetChange returns a copy of a Change that must exist. Panics otherwise.

func (*Fake) Has

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

Has returns if given change exists.

func (*Fake) MakeClient

func (f *Fake) MakeClient(ctx context.Context, gerritHost, luciProject string) (gerrit.Client, error)

MakeClient implemnents gerrit.Factory.

func (*Fake) MakeMirrorIterator

func (f *Fake) MakeMirrorIterator(ctx context.Context) *gerrit.MirrorIterator

MakeMirrorIterator implemnents gerrit.Factory.

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 any, parents ...any)

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
	// OpAlterVotesOfOthers gates altering votes of behalf of others.
	OpAlterVotesOfOthers
	// OpSubmit gates submitting.
	OpSubmit
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL