testutils

package
v0.0.0-...-d625583 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: BSD-3-Clause Imports: 12 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GitSetup

func GitSetup(ctx context.Context, g *GitBuilder) []string

GitSetup adds commits to the Git repo managed by g.

The repo layout looks like this:

older newer c0--c1------c3--c4--

\-c2-----/

Returns the commit hashes in order from c0-c4.

Types

type GitBuilder

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

GitBuilder creates commits and branches in a git repo.

func GitInit

func GitInit(t sktest.TestingT, ctx context.Context) *GitBuilder

GitInit calls GitInitWithDefaultBranch with MainBranch.

func GitInitWithDefaultBranch

func GitInitWithDefaultBranch(t sktest.TestingT, ctx context.Context, defaultBranch string) *GitBuilder

GitInitWithDefaultBranch creates a new git repo in a temporary directory with the specified default branch and returns a GitBuilder to manage it. Call Cleanup to remove the temporary directory. The current branch will be the main branch.

func GitInitWithDir

func GitInitWithDir(t sktest.TestingT, ctx context.Context, dir, defaultBranch string) *GitBuilder

GitInit creates a new git repo in the specified directory and returns a GitBuilder to manage it. Call Cleanup to remove the temporary directory. The current branch will be the main branch.

func (*GitBuilder) AcceptPushes

func (g *GitBuilder) AcceptPushes(ctx context.Context)

AcceptPushes allows pushing changes to the repo.

func (*GitBuilder) Add

func (g *GitBuilder) Add(ctx context.Context, file, contents string)

Add writes contents to file and adds it to the index.

func (*GitBuilder) AddGen

func (g *GitBuilder) AddGen(ctx context.Context, file string)

AddGen writes arbitrary content to file and adds it to the index.

func (*GitBuilder) CheckoutBranch

func (g *GitBuilder) CheckoutBranch(ctx context.Context, name string)

CheckoutBranch checks out the given branch.

func (*GitBuilder) Cleanup

func (g *GitBuilder) Cleanup()

Cleanup removes the directory containing the git repo.

func (*GitBuilder) Commit

func (g *GitBuilder) Commit(ctx context.Context) string

Commit commits files in the index. The current branch is then pushed. Uses an arbitrary commit message. Returns the hash of the new commit.

func (*GitBuilder) CommitGen

func (g *GitBuilder) CommitGen(ctx context.Context, file string) string

CommitGen commits arbitrary content to the given file. The current branch is then pushed. Returns the hash of the new commit.

func (*GitBuilder) CommitGenAt

func (g *GitBuilder) CommitGenAt(ctx context.Context, file string, ts time.Time) string

CommitGenAt commits arbitrary content to the given file using the given time as the commit time. Note that the nanosecond component of time will be dropped. Returns the hash of the new commit.

func (*GitBuilder) CommitGenMsg

func (g *GitBuilder) CommitGenMsg(ctx context.Context, file, msg string) string

CommitGenMsg commits arbitrary content to the given file and uses the given commit message. The current branch is then pushed. Returns the hash of the new commit.

func (*GitBuilder) CommitMsg

func (g *GitBuilder) CommitMsg(ctx context.Context, msg string) string

CommitMsg commits files in the index with the given commit message. The current branch is then pushed. Returns the hash of the new commit.

func (*GitBuilder) CommitMsgAt

func (g *GitBuilder) CommitMsgAt(ctx context.Context, msg string, time time.Time) string

CommitMsg commits files in the index with the given commit message using the given time as the commit time. The current branch is then pushed. Note that the nanosecond component of time will be dropped. Returns the hash of the new commit.

func (*GitBuilder) CreateBranchAtCommit

func (g *GitBuilder) CreateBranchAtCommit(ctx context.Context, name, commit string)

CreateBranchTrackBranch creates a new branch pointing at the given commit, checks out the new branch, and pushes the new branch.

func (*GitBuilder) CreateBranchTrackBranch

func (g *GitBuilder) CreateBranchTrackBranch(ctx context.Context, newBranch, existingBranch string)

CreateBranchTrackBranch creates a new branch tracking an existing branch, checks out the new branch, and pushes the new branch.

func (*GitBuilder) CreateFakeGerritCLGen

func (g *GitBuilder) CreateFakeGerritCLGen(ctx context.Context, issue, patchset string)

CreateFakeGerritCLGen creates a Gerrit-like ref so that it can be applied like a CL on a trybot.

func (*GitBuilder) CreateOrphanBranch

func (g *GitBuilder) CreateOrphanBranch(ctx context.Context, newBranch string)

CreateOrphanBranch creates a new orphan branch.

func (*GitBuilder) Dir

func (g *GitBuilder) Dir() string

Dir returns the directory of the git repo, e.g. for cloning.

func (*GitBuilder) Git

func (g *GitBuilder) Git(ctx context.Context, cmd ...string) string

func (*GitBuilder) MergeBranch

func (g *GitBuilder) MergeBranch(ctx context.Context, name string) string

MergeBranch merges the given branch into the current branch and pushes the current branch. Returns the hash of the new commit.

func (*GitBuilder) MergeBranchAt

func (g *GitBuilder) MergeBranchAt(ctx context.Context, name string, ts time.Time) string

MergeBranchAt merges the given branch into the current branch at the given time and pushes the current branch. Returns the hash of the new commit.

func (*GitBuilder) RepoUrl

func (g *GitBuilder) RepoUrl() string

RepoUrl returns a git-friendly URL for the repo.

func (*GitBuilder) Reset

func (g *GitBuilder) Reset(ctx context.Context, args ...string)

Reset runs "git reset" in the repo.

func (*GitBuilder) Seed

func (g *GitBuilder) Seed(seed int64)

Seed replaces the random seed used by the GitBuilder.

func (*GitBuilder) UpdateRef

func (g *GitBuilder) UpdateRef(ctx context.Context, args ...string)

UpdateRef runs "git update-ref" in the repo.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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