gittest

package
v15.4.4 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: MIT Imports: 36 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"

	// SeedGitLabTest is the path of the gitlab-test.git repository in _build/testrepos
	SeedGitLabTest = "gitlab-test.git"

	// SeedGitLabTestMirror is the path of the gitlab-test-mirror.git repository in _build/testrepos
	SeedGitLabTestMirror = "gitlab-test-mirror.git"
)
View Source
const (
	// GlID is the ID of the default user.
	GlID = "user-123"

	// Timezone is the Timezone of the default user.
	Timezone = "Asia/Shanghai"
	// TimezoneOffset is ISO 8601-like format of the default user Timezone.
	TimezoneOffset = "+0800"
)

Variables

View Source
var (
	// DefaultCommitterName is the default name of the committer and author used to create
	// commits.
	DefaultCommitterName = "Scrooge McDuck"
	// DefaultCommitterMail is the default mail of the committer and author used to create
	// commits.
	DefaultCommitterMail = "scrooge@mcduck.com"
	// DefaultCommitTime is the default time used as written by WriteCommit().
	DefaultCommitTime = time.Date(2019, 11, 3, 11, 27, 59, 0, time.FixedZone("", 60*60))
	// DefaultCommitterSignature is the default signature in the format like it would be present
	// in commits: "$name <$email> $unixtimestamp $timezone".
	DefaultCommitterSignature = fmt.Sprintf(
		"%s <%s> %d %s", DefaultCommitterName, DefaultCommitterMail, DefaultCommitTime.Unix(), DefaultCommitTime.Format("-0700"),
	)
	// DefaultCommitAuthor is the Protobuf message representation of the default committer and
	// author used to create commits.
	DefaultCommitAuthor = &gitalypb.CommitAuthor{
		Name:     []byte(DefaultCommitterName),
		Email:    []byte(DefaultCommitterMail),
		Date:     timestamppb.New(DefaultCommitTime),
		Timezone: []byte("+0100"),
	}
)
View Source
var CommitsByID = map[string]*gitalypb.GitCommit{
	"0031876facac3f2b2702a0e53a26e89939a42209": {
		Id:        "0031876facac3f2b2702a0e53a26e89939a42209",
		Subject:   []byte("Merge branch 'few-commits-4' into few-commits-2"),
		Body:      []byte("Merge branch 'few-commits-4' into few-commits-2\n"),
		Author:    ahmadSherif(1500320762),
		Committer: ahmadSherif(1500320762),
		ParentIds: []string{
			"bf6e164cac2dc32b1f391ca4290badcbe4ffc5fb",
			"48ca272b947f49eee601639d743784a176574a09",
		},
		BodySize: 48,
		TreeId:   "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"48ca272b947f49eee601639d743784a176574a09": {
		Id:        "48ca272b947f49eee601639d743784a176574a09",
		Subject:   []byte("Commit #9 alternate"),
		Body:      []byte("Commit #9 alternate\n"),
		Author:    ahmadSherif(1500320271),
		Committer: ahmadSherif(1500320271),
		ParentIds: []string{"335bc94d5b7369b10251e612158da2e4a4aaa2a5"},
		BodySize:  20,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"335bc94d5b7369b10251e612158da2e4a4aaa2a5": {
		Id:        "335bc94d5b7369b10251e612158da2e4a4aaa2a5",
		Subject:   []byte("Commit #8 alternate"),
		Body:      []byte("Commit #8 alternate\n"),
		Author:    ahmadSherif(1500320269),
		Committer: ahmadSherif(1500320269),
		ParentIds: []string{"1039376155a0d507eba0ea95c29f8f5b983ea34b"},
		BodySize:  20,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"bf6e164cac2dc32b1f391ca4290badcbe4ffc5fb": {
		Id:        "bf6e164cac2dc32b1f391ca4290badcbe4ffc5fb",
		Subject:   []byte("Commit #10"),
		Body:      []byte("Commit #10\n"),
		Author:    ahmadSherif(1500320272),
		Committer: ahmadSherif(1500320272),
		ParentIds: []string{"9d526f87b82e2b2fd231ca44c95508e5e85624ca"},
		BodySize:  11,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"9d526f87b82e2b2fd231ca44c95508e5e85624ca": {
		Id:        "9d526f87b82e2b2fd231ca44c95508e5e85624ca",
		Subject:   []byte("Commit #9"),
		Body:      []byte("Commit #9\n"),
		Author:    ahmadSherif(1500320270),
		Committer: ahmadSherif(1500320270),
		ParentIds: []string{"1039376155a0d507eba0ea95c29f8f5b983ea34b"},
		BodySize:  10,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"1039376155a0d507eba0ea95c29f8f5b983ea34b": {
		Id:        "1039376155a0d507eba0ea95c29f8f5b983ea34b",
		Subject:   []byte("Commit #8"),
		Body:      []byte("Commit #8\n"),
		Author:    ahmadSherif(1500320268),
		Committer: ahmadSherif(1500320268),
		ParentIds: []string{"54188278422b1fa877c2e71c4e37fc6640a58ad1"},
		BodySize:  10,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"54188278422b1fa877c2e71c4e37fc6640a58ad1": {
		Id:        "54188278422b1fa877c2e71c4e37fc6640a58ad1",
		Subject:   []byte("Commit #7"),
		Body:      []byte("Commit #7\n"),
		Author:    ahmadSherif(1500320266),
		Committer: ahmadSherif(1500320266),
		ParentIds: []string{"8b9270332688d58e25206601900ee5618fab2390"},
		BodySize:  10,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"8b9270332688d58e25206601900ee5618fab2390": {
		Id:        "8b9270332688d58e25206601900ee5618fab2390",
		Subject:   []byte("Commit #6"),
		Body:      []byte("Commit #6\n"),
		Author:    ahmadSherif(1500320264),
		Committer: ahmadSherif(1500320264),
		ParentIds: []string{"f9220df47bce1530e90c189064d301bfc8ceb5ab"},
		BodySize:  10,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"f9220df47bce1530e90c189064d301bfc8ceb5ab": {
		Id:        "f9220df47bce1530e90c189064d301bfc8ceb5ab",
		Subject:   []byte("Commit #5"),
		Body:      []byte("Commit #5\n"),
		Author:    ahmadSherif(1500320262),
		Committer: ahmadSherif(1500320262),
		ParentIds: []string{"40d408f89c1fd26b7d02e891568f880afe06a9f8"},
		BodySize:  10,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"40d408f89c1fd26b7d02e891568f880afe06a9f8": {
		Id:        "40d408f89c1fd26b7d02e891568f880afe06a9f8",
		Subject:   []byte("Commit #4"),
		Body:      []byte("Commit #4\n"),
		Author:    ahmadSherif(1500320260),
		Committer: ahmadSherif(1500320260),
		ParentIds: []string{"df914c609a1e16d7d68e4a61777ff5d6f6b6fde3"},
		BodySize:  10,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"df914c609a1e16d7d68e4a61777ff5d6f6b6fde3": {
		Id:        "df914c609a1e16d7d68e4a61777ff5d6f6b6fde3",
		Subject:   []byte("Commit #3"),
		Body:      []byte("Commit #3\n"),
		Author:    ahmadSherif(1500320258),
		Committer: ahmadSherif(1500320258),
		ParentIds: []string{"6762605237fc246ae146ac64ecb467f71d609120"},
		BodySize:  10,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"6762605237fc246ae146ac64ecb467f71d609120": {
		Id:        "6762605237fc246ae146ac64ecb467f71d609120",
		Subject:   []byte("Commit #2"),
		Body:      []byte("Commit #2\n"),
		Author:    ahmadSherif(1500320256),
		Committer: ahmadSherif(1500320256),
		ParentIds: []string{"79b06233d3dc769921576771a4e8bee4b439595d"},
		BodySize:  10,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"79b06233d3dc769921576771a4e8bee4b439595d": {
		Id:        "79b06233d3dc769921576771a4e8bee4b439595d",
		Subject:   []byte("Commit #1"),
		Body:      []byte("Commit #1\n"),
		Author:    ahmadSherif(1500320254),
		Committer: ahmadSherif(1500320254),
		ParentIds: []string{"1a0b36b3cdad1d2ee32457c102a8c0b7056fa863"},
		BodySize:  10,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"1a0b36b3cdad1d2ee32457c102a8c0b7056fa863": {
		Id:        "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863",
		Subject:   []byte("Initial commit"),
		Body:      []byte("Initial commit\n"),
		Author:    dmitriyZaporozhets(1393488198),
		Committer: dmitriyZaporozhets(1393488198),
		ParentIds: nil,
		BodySize:  15,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"304d257dcb821665ab5110318fc58a007bd104ed": {
		Id:        "304d257dcb821665ab5110318fc58a007bd104ed",
		Subject:   []byte("Commit #11"),
		Body:      []byte("Commit #11\n"),
		Author:    ahmadSherif(1500322381),
		Committer: ahmadSherif(1500322381),
		ParentIds: []string{"1a0b36b3cdad1d2ee32457c102a8c0b7056fa863"},
		BodySize:  11,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"1e292f8fedd741b75372e19097c76d327140c312": {
		Id:        "1e292f8fedd741b75372e19097c76d327140c312",
		Subject:   []byte("Merge branch 'cherry-pikc-ce369011' into 'master'"),
		Body:      []byte("Merge branch 'cherry-pikc-ce369011' into 'master'\n\nAdd file with a _flattable_ path\n\n See merge request gitlab-org/gitlab-test!35\n"),
		Author:    drewBlessing(1540830087),
		Committer: drewBlessing(1540830087),
		ParentIds: []string{
			"79b06233d3dc769921576771a4e8bee4b439595d",
			"c1c67abbaf91f624347bb3ae96eabe3a1b742478",
		},
		BodySize: 388,
		TreeId:   "07f8147e8e73aab6c935c296e8cdc5194dee729b",
	},
	"60ecb67744cb56576c30214ff52294f8ce2def98": {
		Id:        "60ecb67744cb56576c30214ff52294f8ce2def98",
		Subject:   []byte("Merge branch 'lfs' into 'master'"),
		Body:      []byte("Merge branch 'lfs' into 'master'\n\nAdd LFS tracking of \"*.lfs\" to .gitattributes\n\nSee merge request gitlab-org/gitlab-test!28"),
		Author:    stanHu(1515740810),
		Committer: stanHu(1515740810),
		ParentIds: []string{
			"e63f41fe459e62e1228fcef60d7189127aeba95a",
			"55bc176024cfa3baaceb71db584c7e5df900ea65",
		},
		BodySize: 124,
		TreeId:   "7e2f26d033ee47cd0745649d1a28277c56197921",
	},
	"e63f41fe459e62e1228fcef60d7189127aeba95a": {
		Id:        "e63f41fe459e62e1228fcef60d7189127aeba95a",
		Subject:   []byte("Merge branch 'gitlab-test-usage-dev-testing-docs' into 'master'"),
		Body:      []byte("Merge branch 'gitlab-test-usage-dev-testing-docs' into 'master'\r\n\r\nUpdate README.md to include `Usage in testing and development`\r\n\r\nSee merge request !21"),
		Author:    seanMcGivern(1491906794),
		Committer: seanMcGivern(1491906794),
		ParentIds: []string{
			"b83d6e391c22777fca1ed3012fce84f633d7fed0",
			"4a24d82dbca5c11c61556f3b35ca472b7463187e",
		},
		BodySize: 154,
		TreeId:   "86ec18bfe87ad42a782fdabd8310f9b7ac750f51",
	},
	"55bc176024cfa3baaceb71db584c7e5df900ea65": {
		Id:        "55bc176024cfa3baaceb71db584c7e5df900ea65",
		Subject:   []byte("LFS tracks \"*.lfs\" through .gitattributes"),
		Body:      []byte("LFS tracks \"*.lfs\" through .gitattributes\n"),
		Author:    jamesEdwardsJones(1515687321),
		Committer: jamesEdwardsJones(1515738427),
		ParentIds: []string{
			"b83d6e391c22777fca1ed3012fce84f633d7fed0",
		},
		BodySize: 42,
		TreeId:   "1970c07e0e1ce7fcf82edc2e3792564bd8ea3744",
	},
	"4a24d82dbca5c11c61556f3b35ca472b7463187e": {
		Id:        "4a24d82dbca5c11c61556f3b35ca472b7463187e",
		Subject:   []byte("Update README.md to include `Usage in testing and development`"),
		Body:      []byte("Update README.md to include `Usage in testing and development`"),
		Author:    lukeBennett(1491905339),
		Committer: lukeBennett(1491905339),
		ParentIds: []string{
			"b83d6e391c22777fca1ed3012fce84f633d7fed0",
		},
		BodySize: 62,
		TreeId:   "86ec18bfe87ad42a782fdabd8310f9b7ac750f51",
	},
	"ce369011c189f62c815f5971d096b26759bab0d1": {
		Id:        "ce369011c189f62c815f5971d096b26759bab0d1",
		Subject:   []byte("Add file with a _flattable_ path"),
		Body:      []byte("Add file with a _flattable_ path\n"),
		Author:    alejandroRodriguez(1504382739),
		Committer: alejandroRodriguez(1504397760),
		ParentIds: []string{
			"913c66a37b4a45b9769037c55c2d238bd0942d2e",
		},
		BodySize: 33,
		TreeId:   "729bb692f55d49149609dd1ceaaf1febbdec7d0d",
	},
	"ca47bfd5e930148c42ed74c3b561a8783e381f7f": {
		Id:     "ca47bfd5e930148c42ed74c3b561a8783e381f7f",
		TreeId: "a5d06eba4fd37a4f7a39863c226e5ff66010deed",
		ParentIds: []string{
			"00850ec866c95e6516fca79614af7a868f6d3f43",
		},
		Subject:  []byte("Add Modula-2 source file for language detection"),
		Body:     []byte("Add Modula-2 source file for language detection\n"),
		BodySize: 48,
		Author: &gitalypb.CommitAuthor{
			Name:     []byte("Jacob Vosmaer"),
			Email:    []byte("jacob@gitlab.com"),
			Date:     &timestamppb.Timestamp{Seconds: 1501503403},
			Timezone: []byte("+0200"),
		},
		Committer: &gitalypb.CommitAuthor{
			Name:     []byte("Ahmad Sherif"),
			Email:    []byte("me@ahmadsherif.com"),
			Date:     &timestamppb.Timestamp{Seconds: 1521033060},
			Timezone: []byte("+0100"),
		},
	},
}

CommitsByID is a map of GitCommit structures by their respective IDs.

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

TestUser is the default user for tests.

Functions

func AddWorktree

func AddWorktree(tb 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 BundleRepo

func BundleRepo(tb testing.TB, cfg config.Cfg, repoPath, bundlePath string, patterns ...string)

BundleRepo creates a bundle of a repository. `patterns` define the bundle contents as per `git-rev-list-args`. If there are no patterns then `--all` is assumed.

func CaptureHookEnv

func CaptureHookEnv(tb testing.TB, cfg config.Cfg) (git.CommandFactory, string)

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

func ChecksumRepo

func ChecksumRepo(tb testing.TB, cfg config.Cfg, repoPath string) *git.Checksum

ChecksumRepo calculates the checksum of a repository.

func CommitEqual

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

CommitEqual tests if two `GitCommit`s are equal

func CreateRepository

func CreateRepository(ctx context.Context, tb testing.TB, cfg config.Cfg, configs ...CreateRepositoryConfig) (*gitalypb.Repository, string)

CreateRepository creates a new repository and returns it and its absolute path.

func Exec

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

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

func ExecOpts

func ExecOpts(tb testing.TB, cfg config.Cfg, execCfg ExecConfig, args ...string) []byte

ExecOpts runs a git command with the given configuration.

func FixGitLabTestRepoForCommitGraphs added in v15.2.0

func FixGitLabTestRepoForCommitGraphs(tb testing.TB, cfg config.Cfg, repoPath string)

FixGitLabTestRepoForCommitGraphs fixes the "gitlab-test.git" repository so that it can be used in the context of commit-graphs. The test repository contains the commit ba3343b (Weird commit date, 292278994-08-17). As you can already see, this commit has a commit year of 292278994, which is not exactly a realistic commit date to have in normal repositories. Unfortunately, this commit date causes commit-graphs to become corrupt with the following error that's likely caused by an overflow:

commit date for commit ba3343bc4fa403a8dfbfcab7fc1a8c29ee34bd69 in commit-graph is 15668040695 != 9223372036854775

This is not a new error, but something that has existed for quite a while already in Git. And while the bug can also be easily hit in Gitaly because we do write commit-graphs in pool repositories, until now we haven't because we never exercised this.

Unfortunately, we're between a rock and a hard place: this error will be hit when running git-fsck(1) to find dangling objects, which we do to rescue objects. git-fsck(1) will by default verify the commit-graphs to be consistent even with `--connectivity-only`, which causes the error. But while we could in theory just disable the usage of commit-graphs by passing `core.commitGraph=0`, the end result would be that the connectivity check itself may become a lot slower.

So for now we just bail on this whole topic: it's not a new bug and we can't do much about it given it could regress performance. The pool members would be broken in the same way, even though less visibly so because we don't git-fsck(1) in "normal" RPCs. But to make our tests work we delete the reference for this specific commit so that it doesn't cause our tests to break.

You can easily test whether this bug still exists via the following commands:

$ git clone _build/testrepos/gitlab-test.git
$ git -C gitlab-test commit-graph write
$ git -C gitlab-test commit-graph verify

func GetGitPackfileDirSize

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

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

func GetReplicaPath

func GetReplicaPath(ctx context.Context, tb testing.TB, cfg config.Cfg, repo repository.GitRepo, opts ...GetReplicaPathConfig) string

GetReplicaPath retrieves the repository's replica path if the test has been run with Praefect in front of it. This is necessary if the test creates a repository through Praefect and peeks into the filesystem afterwards. Conn should be pointing to Praefect.

func GitSupportsStatusFlushing added in v15.3.0

func GitSupportsStatusFlushing(t *testing.T, ctx context.Context, cfg config.Cfg) bool

GitSupportsStatusFlushing returns whether or not the current version of Git supports status flushing.

func HTTPServer

func HTTPServer(ctx context.Context, tb testing.TB, gitCmdFactory git.CommandFactory, repoPath string, middleware func(http.ResponseWriter, *http.Request, http.Handler)) (int, func() error)

HTTPServer 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 InitRepoDir

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

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

func NewCommand

func NewCommand(tb testing.TB, cfg config.Cfg, args ...string) *exec.Cmd

NewCommand creates a new Git command ready for execution.

func NewCommandFactory

func NewCommandFactory(tb testing.TB, cfg config.Cfg, opts ...git.ExecCommandFactoryOption) git.CommandFactory

NewCommandFactory creates a new Git command factory.

func NewObjectPoolName

func NewObjectPoolName(tb 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(tb 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 ObjectHashIsSHA256 added in v15.3.0

func ObjectHashIsSHA256() bool

ObjectHashIsSHA256 returns if the current default object hash is SHA256.

func Pktlinef added in v15.3.0

func Pktlinef(t *testing.T, format string, a ...interface{}) string

Pktlinef formats the given formatting string into a pktline.

func RemoteExists

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

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

func RequireObjectExists

func RequireObjectExists(tb testing.TB, cfg config.Cfg, repoPath string, objectID git.ObjectID)

RequireObjectExists asserts that the given repository does contain an object with the specified object ID.

func RequireObjectNotExists

func RequireObjectNotExists(tb testing.TB, cfg config.Cfg, repoPath string, objectID git.ObjectID)

RequireObjectNotExists asserts that the given repository does not contain an object with the specified object ID.

func RequireTree

func RequireTree(tb 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 ResolveRevision added in v15.2.0

func ResolveRevision(tb testing.TB, cfg config.Cfg, repoPath string, revision string) git.ObjectID

ResolveRevision resolves the revision to an object ID.

func RewrittenRepository

func RewrittenRepository(ctx context.Context, tb testing.TB, cfg config.Cfg, repository *gitalypb.Repository) *gitalypb.Repository

RewrittenRepository returns the repository as it would be received by a Gitaly after being rewritten by Praefect. This should be used when the repository is being accessed through the filesystem to ensure the access path is correct. If the test is not running with Praefect in front, it returns the an unaltered copy of repository.

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,
	repoPathToModify string,
	repoPathToRepack string,
	isPoolRepo bool,
	repack func() error,
)

TestDeltaIslands checks whether functions that repack objects in a repository correctly set up delta islands. Based on https://github.com/git/git/blob/master/t/t5320-delta-islands.sh. Note that this function accepts two different repository paths: one repo to modify that shall grow the new references and objects, and one repository that we ultimately end up repacking. In the general case these should refer to the same repository, but for object pools these may be the pool member and the pool, respectively.

func TestRepository

func TestRepository(t *testing.T, cfg config.Cfg, getRepository GetRepositoryFunc)

TestRepository tests an implementation of Repository.

func WriteBlob

func WriteBlob(tb 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(tb 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(tb testing.TB, 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(tb testing.TB, cfg config.Cfg, repoPath string, opts ...WriteCommitOption) git.ObjectID

WriteCommit writes a new commit into the target repository.

func WriteCustomHook

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

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

func WriteEnvToCustomHook

func WriteEnvToCustomHook(tb 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 WritePktlinef added in v15.2.0

func WritePktlinef(t *testing.T, writer io.Writer, format string, args ...interface{})

WritePktlinef formats the given format string and writes the pktline-formatted data into the writer.

func WriteRef

func WriteRef(tb testing.TB, cfg config.Cfg, repoPath string, ref git.ReferenceName, oid git.ObjectID)

WriteRef writes a reference into the repository pointing to the given object ID.

func WriteTag

func WriteTag(
	tb testing.TB,
	cfg config.Cfg,
	repoPath string,
	tagName string,
	targetRevision git.Revision,
	optionalConfig ...WriteTagConfig,
) git.ObjectID

WriteTag writes a new tag into the repository. This function either returns the tag ID in case an annotated tag was created, or otherwise the target object ID when a lightweight tag was created. Takes either no WriteTagConfig, in which case the default values will be used, or exactly one.

func WriteTree

func WriteTree(tb 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 CreateRepositoryConfig

type CreateRepositoryConfig struct {
	// ClientConn is the connection used to create the repository. If unset, the config is used to
	// dial the service.
	ClientConn *grpc.ClientConn
	// Storage determines the storage the repository is created in. If unset, the first storage
	// from the config is used.
	Storage config.Storage
	// RelativePath sets the relative path of the repository in the storage. If unset,
	// the relative path is set to a randomly generated hashed storage path
	RelativePath string
	// Seed determines which repository is used to seed the created repository. If unset, the repository
	// is just created. The value should be one of the test repositories in _build/testrepos.
	Seed string
	// SkipCreationViaService skips creation of the repository by calling the respective RPC call.
	// In general, this should not be skipped so that we end up in a state that is consistent
	// and expected by both Gitaly and Praefect. It may be required though when testing at a
	// level where there are no gRPC services available.
	SkipCreationViaService bool
	// ObjectFormat overrides the object format used by the repository.
	ObjectFormat string
}

CreateRepositoryConfig allows for configuring how the repository is created.

type ExecConfig

type ExecConfig struct {
	// Stdin sets up stdin of the spawned command.
	Stdin io.Reader
	// Stdout sets up stdout of the spawned command. Note that `ExecOpts()` will not return any
	// output anymore if this field is set.
	Stdout io.Writer
	// Env contains environment variables that should be appended to the spawned command's
	// environment.
	Env []string
}

ExecConfig contains configuration for ExecOpts.

type GetReplicaPathConfig

type GetReplicaPathConfig struct {
	// ClientConn is the connection used to create the repository. If unset, the config is used to
	// dial the service.
	ClientConn *grpc.ClientConn
}

GetReplicaPathConfig allows for configuring the GetReplicaPath call.

type GetRepositoryFunc

type GetRepositoryFunc func(ctx context.Context, t testing.TB) (git.Repository, string)

GetRepositoryFunc is used to get a clean test repository for the different implementations of the Repository interface in the common test suite TestRepository.

type InterceptingCommandFactory

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

InterceptingCommandFactory is a git.CommandFactory which intercepts all executions of Git commands with a custom script.

func NewInterceptingCommandFactory

func NewInterceptingCommandFactory(
	ctx context.Context,
	tb testing.TB,
	cfg config.Cfg,
	generateScript func(git.ExecutionEnvironment) string,
	opts ...InterceptingCommandFactoryOption,
) *InterceptingCommandFactory

NewInterceptingCommandFactory creates a new command factory which intercepts Git commands. The given configuration must point to the real Git executable. The function will be executed to generate the script and receives as input the Git execution environment pointing to the real Git binary.

func (*InterceptingCommandFactory) GetExecutionEnvironment

func (f *InterceptingCommandFactory) GetExecutionEnvironment(ctx context.Context) git.ExecutionEnvironment

GetExecutionEnvironment returns the execution environment of the intercetping command factory. The Git binary path will point to the intercepting script, while environment variables will point to the intercepted Git installation.

func (*InterceptingCommandFactory) GitVersion

GitVersion returns the Git version as returned by the intercepted command.

func (*InterceptingCommandFactory) HooksPath

HooksPath returns the path where hooks are stored. This returns the actual hooks path of the real Git command factory.

func (*InterceptingCommandFactory) New

New creates a new Git command for the given repository using the intercepting script.

func (*InterceptingCommandFactory) NewWithDir

func (f *InterceptingCommandFactory) NewWithDir(ctx context.Context, dir string, sc git.Cmd, opts ...git.CmdOpt) (*command.Command, error)

NewWithDir creates a new Git command in the given directory using the intercepting script.

func (*InterceptingCommandFactory) NewWithoutRepo

func (f *InterceptingCommandFactory) NewWithoutRepo(ctx context.Context, sc git.Cmd, opts ...git.CmdOpt) (*command.Command, error)

NewWithoutRepo creates a new Git command using the intercepting script.

func (*InterceptingCommandFactory) SidecarGitConfiguration

func (f *InterceptingCommandFactory) SidecarGitConfiguration(ctx context.Context) ([]git.ConfigPair, error)

SidecarGitConfiguration returns the Ruby sidecar Git configuration as computed by the actual Git command factory.

type InterceptingCommandFactoryOption

type InterceptingCommandFactoryOption func(*interceptingCommandFactoryConfig)

InterceptingCommandFactoryOption is an option that can be passed to NewInterceptingCommandFactory.

func WithInterceptedVersion

func WithInterceptedVersion() InterceptingCommandFactoryOption

WithInterceptedVersion will cause `GitVersion()` to use the intercepting Git command factory instead of the real Git command factory. This allows the caller to explicitly test version detection.

func WithRealCommandFactoryOptions

func WithRealCommandFactoryOptions(opts ...git.ExecCommandFactoryOption) InterceptingCommandFactoryOption

WithRealCommandFactoryOptions is an option that allows the caller to pass options to the real git.ExecCommandFactory.

type ProtocolDetectingCommandFactory added in v15.2.0

type ProtocolDetectingCommandFactory struct {
	git.CommandFactory
	// contains filtered or unexported fields
}

ProtocolDetectingCommandFactory is an intercepting Git command factory that allows the protocol to be tested.

func NewProtocolDetectingCommandFactory

func NewProtocolDetectingCommandFactory(ctx context.Context, tb testing.TB, cfg config.Cfg) ProtocolDetectingCommandFactory

NewProtocolDetectingCommandFactory returns a new ProtocolDetectingCommandFactory.

func (*ProtocolDetectingCommandFactory) ReadProtocol added in v15.2.0

func (p *ProtocolDetectingCommandFactory) ReadProtocol(t *testing.T) string

ReadProtocol reads the protocol used by previous Git executions.

func (*ProtocolDetectingCommandFactory) Reset added in v15.2.0

Reset resets previously recorded protocols.

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 WithAlternateObjectDirectory

func WithAlternateObjectDirectory(alternateObjectDir string) WriteCommitOption

WithAlternateObjectDirectory will cause the commit to be written into the given alternate object directory. This can either be an absolute path or a relative path. In the latter case the path is considered to be relative to the repository path.

func WithAuthorDate added in v15.2.0

func WithAuthorDate(date time.Time) WriteCommitOption

WithAuthorDate is an option for WriteCommit which will set the author date.

func WithAuthorName added in v15.2.0

func WithAuthorName(name string) WriteCommitOption

WithAuthorName is an option for WriteCommit which will set the author name.

func WithBranch

func WithBranch(branch string) WriteCommitOption

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

func WithCommitterDate added in v15.2.0

func WithCommitterDate(date time.Time) WriteCommitOption

WithCommitterDate is an option for WriteCommit which will set the committer date.

func WithCommitterName

func WithCommitterName(name string) WriteCommitOption

WithCommitterName is an option for WriteCommit which will set the committer name.

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 WithReference added in v15.3.0

func WithReference(reference string) WriteCommitOption

WithReference is an option for WriteCommit which will cause it to update the given reference to point to the new commit. This function requires the fully-qualified reference name.

func WithTree

func WithTree(treeID git.ObjectID) WriteCommitOption

WithTree is an option for WriteCommit which will cause it to use the given object ID as the root tree of the resulting commit. as root tree 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.

type WriteTagConfig

type WriteTagConfig struct {
	// Message is the message of an annotated tag. If left empty, then a lightweight tag will
	// be created.
	Message string
	// Force indicates whether existing tags with the same name shall be overwritten.
	Force bool
}

WriteTagConfig holds extra options for WriteTag.

Jump to

Keyboard shortcuts

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