gittest

package
v14.0.0-rc43 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GlRepository is the default repository name for newly created test
	// repos.
	GlRepository = "project-1"
	// GlProjectPath is the default project path for newly created test
	// repos.
	GlProjectPath = "gitlab-org/gitlab-test"
)
View Source
const (
	// GlID is the ID of the default user.
	GlID = "user-123"
)

Variables

View Source
var (
	// TestUser is the default user for tests.
	TestUser = &gitalypb.User{
		Name:       []byte("Jane Doe"),
		Email:      []byte("janedoe@gitlab.com"),
		GlId:       GlID,
		GlUsername: "janedoe",
	}
)

Functions

func AddWorktree

func AddWorktree(t testing.TB, cfg config.Cfg, repoPath string, worktreeName string)

AddWorktree creates a worktree in the repository path for tests

func AddWorktreeArgs

func AddWorktreeArgs(repoPath, worktreeName string) []string

AddWorktreeArgs returns git command arguments for adding a worktree at the specified repo

func AuthorEqual

func AuthorEqual(t testing.TB, expected *gitalypb.CommitAuthor, actual *gitalypb.CommitAuthor)

AuthorEqual tests if two `CommitAuthor`s are equal.

func CaptureHookEnv

func CaptureHookEnv(t testing.TB) (string, func())

CaptureHookEnv creates a bogus 'update' Git hook to sniff out what environment variables get set for hooks.

func CloneBenchRepo

func CloneBenchRepo(t testing.TB, cfg config.Cfg) (repo *gitalypb.Repository, repoPath string, cleanup func())

CloneBenchRepo creates a bare copy of the benchmarking test repository.

func CloneRepoAtStorage

func CloneRepoAtStorage(t testing.TB, cfg config.Cfg, storage config.Storage, relativePath string) (*gitalypb.Repository, string, testhelper.Cleanup)

CloneRepoAtStorage clones a new copy of test repository under a subdirectory in the storage root.

func CloneRepoAtStorageRoot

func CloneRepoAtStorageRoot(t testing.TB, cfg config.Cfg, storageRoot, relativePath string) *gitalypb.Repository

CloneRepoAtStorageRoot clones a new copy of test repository under a subdirectory in the storage root.

func CloneRepoWithWorktreeAtStorage

func CloneRepoWithWorktreeAtStorage(t testing.TB, cfg config.Cfg, storage config.Storage) (*gitalypb.Repository, string, testhelper.Cleanup)

CloneRepoWithWorktreeAtStorage creates a copy of the test repository with a worktree at the storage you want. This is allows you to run normal 'non-bare' Git commands.

func CommitEqual

func CommitEqual(t testing.TB, expected, actual *gitalypb.GitCommit)

CommitEqual tests if two `GitCommit`s are equal

func CreateCommitInAlternateObjectDirectory

func CreateCommitInAlternateObjectDirectory(t testing.TB, gitBin, repoPath, altObjectsDir string, cmd *exec.Cmd) (currentHead []byte)

CreateCommitInAlternateObjectDirectory runs a command such that its created objects will live in an alternate objects directory. It returns the current head after the command is run and the alternate objects directory path

func CreateRemoteBranch

func CreateRemoteBranch(t testing.TB, cfg config.Cfg, repoPath, remoteName, branchName, ref string)

CreateRemoteBranch creates a new remote branch

func CreateTag

func CreateTag(t testing.TB, cfg config.Cfg, repoPath, tagName, targetID string, opts *CreateTagOpts) string

CreateTag creates a new tag.

func EnableGitProtocolV2Support

func EnableGitProtocolV2Support(t testing.TB, cfg config.Cfg) (func() string, config.Cfg)

EnableGitProtocolV2Support replaces the git binary in config with a wrapper that allows the protocol to be tested. It returns a function to read the GIT_PROTOCOl environment variable created by the wrapper script, the modified configuration as well as a cleanup function.

func Exec

func Exec(t testing.TB, cfg config.Cfg, args ...string) []byte

Exec runs a git command and returns the standard output, or fails.

func ExecStream

func ExecStream(t testing.TB, cfg config.Cfg, stream io.Reader, args ...string) []byte

ExecStream runs a git command with an input stream and returns the standard output, or fails.

func GetGitObjectDirSize

func GetGitObjectDirSize(t testing.TB, repoPath string) int64

GetGitObjectDirSize gets the number of 1k blocks of a git object directory

func GetGitPackfileDirSize

func GetGitPackfileDirSize(t testing.TB, repoPath string) int64

GetGitPackfileDirSize gets the number of 1k blocks of a git object directory

func GitObjectMustExist

func GitObjectMustExist(t testing.TB, gitBin, repoPath, sha string)

GitObjectMustExist is a test assertion that fails unless the git repo in repoPath contains sha

func GitObjectMustNotExist

func GitObjectMustNotExist(t testing.TB, gitBin, repoPath, sha string)

GitObjectMustNotExist is a test assertion that fails unless the git repo in repoPath contains sha

func GitServer

func GitServer(t testing.TB, cfg config.Cfg, repoPath string, middleware func(http.ResponseWriter, *http.Request, http.Handler)) (int, func() error)

GitServer starts an HTTP server with git-http-backend(1) as CGI handler. The repository is prepared such that git-http-backend(1) will serve it by creating the "git-daemon-export-ok" magic file.

func InitBareRepoAt

func InitBareRepoAt(t testing.TB, cfg config.Cfg, storage config.Storage) (*gitalypb.Repository, string, func())

InitBareRepoAt creates a new bare repository in the storage

func InitRepoDir

func InitRepoDir(t testing.TB, storagePath, relativePath string) *gitalypb.Repository

InitRepoDir creates a temporary directory for a repo, without initializing it

func InitRepoWithWorktreeAtStorage

func InitRepoWithWorktreeAtStorage(t testing.TB, cfg config.Cfg, storage config.Storage) (*gitalypb.Repository, string, func())

InitRepoWithWorktreeAtStorage creates a new repository with a worktree in the storage

func NewObjectPoolName

func NewObjectPoolName(t testing.TB) string

NewObjectPoolName returns a random pool repository name in format '@pools/[0-9a-z]{2}/[0-9a-z]{2}/[0-9a-z]{64}.git'.

func NewRepositoryName

func NewRepositoryName(t testing.TB, bare bool) string

NewRepositoryName returns a random repository hash in format '@hashed/[0-9a-f]{2}/[0-9a-f]{2}/[0-9a-f]{64}(.git)?'.

func RemoteExists

func RemoteExists(t testing.TB, cfg config.Cfg, repoPath string, remoteName string) bool

RemoteExists tests if the repository at repoPath has a Git remote named remoteName.

func RemoteUploadPackServer

func RemoteUploadPackServer(ctx context.Context, t *testing.T, gitPath, repoName, httpToken, repoPath string) (*httptest.Server, string)

RemoteUploadPackServer implements two HTTP routes for git-upload-pack by copying stdin and stdout into and out of the git upload-pack command

func RequireTree

func RequireTree(t testing.TB, cfg config.Cfg, repoPath, treeish string, expectedEntries []TreeEntry)

RequireTree looks up the given treeish and asserts that its entries match the given expected entries. Tree entries are checked recursively.

func TestBitmapHasHashcache

func TestBitmapHasHashcache(t *testing.T, bitmap string)

TestBitmapHasHashcache checks if the named pack bitmap file contains "hash cache" data. See https://github.com/git/git/blob/master/Documentation/technical/bitmap-format.txt

func TestDeltaIslands

func TestDeltaIslands(t *testing.T, cfg config.Cfg, repoPath string, repack func() error)

TestDeltaIslands is based on the tests in https://github.com/git/git/blob/master/t/t5320-delta-islands.sh .

func TestRepository

func TestRepository(t *testing.T, cfg config.Cfg, getRepository func(testing.TB, *gitalypb.Repository) git.Repository)

TestRepository tests an implementation of Repository.

func WriteBlob

func WriteBlob(t testing.TB, cfg config.Cfg, testRepoPath string, contents []byte) git.ObjectID

WriteBlob writes the given contents as a blob into the repository and returns its OID.

func WriteBlobs

func WriteBlobs(t testing.TB, cfg config.Cfg, testRepoPath string, n int) []string

WriteBlobs writes n distinct blobs into the git repository's object database. Each object has the current time in nanoseconds as contents.

func WriteCheckNewObjectExistsHook

func WriteCheckNewObjectExistsHook(t testing.TB, gitBin, repoPath string)

WriteCheckNewObjectExistsHook writes a pre-receive hook which only succeeds if it can find the object in the quarantine directory. if GIT_OBJECT_DIRECTORY and GIT_ALTERNATE_OBJECT_DIRECTORIES were not passed through correctly to the hooks, it will fail

func WriteCommit

func WriteCommit(t testing.TB, cfg config.Cfg, repoPath string, opts ...WriteCommitOption) git.ObjectID

WriteCommit writes a new commit into the target repository.

func WriteCustomHook

func WriteCustomHook(t testing.TB, repoPath, name string, content []byte)

WriteCustomHook writes a hook in the repo/path.git/custom_hooks directory

func WriteEnvToCustomHook

func WriteEnvToCustomHook(t testing.TB, repoPath, hookName string) string

WriteEnvToCustomHook dumps the env vars that the custom hooks receives to a file

func WritePktlineDelim

func WritePktlineDelim(t *testing.T, writer io.Writer)

WritePktlineDelim writes the pktline-formatted delimiter into the writer.

func WritePktlineFlush

func WritePktlineFlush(t *testing.T, writer io.Writer)

WritePktlineFlush writes the pktline-formatted flush into the writer.

func WritePktlineString

func WritePktlineString(t *testing.T, writer io.Writer, data string)

WritePktlineString writes the pktline-formatted data into the writer.

func WriteTree

func WriteTree(t testing.TB, cfg config.Cfg, repoPath string, entries []TreeEntry) git.ObjectID

WriteTree writes a new tree object to the given path. This function does not verify whether OIDs referred to by tree entries actually exist in the repository.

Types

type CreateTagOpts

type CreateTagOpts struct {
	Message string
	Force   bool
}

CreateTagOpts holds extra options for CreateTag.

type TreeEntry

type TreeEntry struct {
	// OID is the object ID the tree entry refers to.
	OID git.ObjectID
	// Mode is the file mode of the tree entry.
	Mode string
	// Path is the full path of the tree entry.
	Path string
	// Content is the content of the tree entry.
	Content string
}

TreeEntry represents an entry of a git tree object.

type WriteCommitOption

type WriteCommitOption func(*writeCommitConfig)

WriteCommitOption is an option which can be passed to WriteCommit.

func WithBranch

func WithBranch(branch string) WriteCommitOption

WithBranch is an option for WriteCommit which will cause it to update the update the given branch name to the new commit.

func WithMessage

func WithMessage(message string) WriteCommitOption

WithMessage is an option for WriteCommit which will set the commit message.

func WithParents

func WithParents(parents ...git.ObjectID) WriteCommitOption

WithParents is an option for WriteCommit which will set the parent OIDs of the resulting commit.

func WithTreeEntries

func WithTreeEntries(entries ...TreeEntry) WriteCommitOption

WithTreeEntries is an option for WriteCommit which will cause it to create a new tree and use it as root tree of the resulting commit.

Jump to

Keyboard shortcuts

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