gitclitest

package
v0.182.6 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package gitclitest is the in-memory fake for internal/gitcli.Git, so a unit test can substitute it for a real gitcli.Client without touching a real repository. internal/gitcli/contract_test.go (//go:build e2e) runs the same cases against both, proving the fake does not diverge from real git for the cases it emulates.

Fake also has task-8's fail-call-N mode (decision 23), mirrored from internal/runner/runnertest.Fake: FailCall makes one chosen call fail on its own, standalone, and Fake implements internal/testsweep.Failer so internal/testsweep.Sweep can drive it once per call a happy-path body makes. See CallCount and FailCall, and gitclitest_test.go's multiCallConsumer for a worked example.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolResult

type BoolResult struct {
	Value bool
	Err   error
}

BoolResult is IsAncestor's canned outcome.

type Fake

type Fake struct {
	// CurrentBranchByDir maps a worktree directory to CurrentBranch's
	// canned (branch, error) result.
	CurrentBranchByDir map[string]Result
	// RevParseByDirAndRev maps "dir\x00rev" to RevParse's canned result.
	RevParseByDirAndRev map[string]Result
	// IsAncestorByCase maps "dir\x00ancestor\x00descendant" to IsAncestor's
	// canned (bool, error) result.
	IsAncestorByCase map[string]BoolResult
	// FetchErrByDirAndRemote maps "dir\x00remote" to Fetch's canned error.
	FetchErrByDirAndRemote map[string]error

	WorktreeRemoveForceErrByCase       map[string]error
	WorktreeAddDetachedErrByCase       map[string]error
	CherryPickNoCommitErrByCase        map[string]error
	CommitNoVerifyErrByCase            map[string]error
	CherryPickErrByCase                map[string]error
	PushForceWithLeaseHeadErrByCase    map[string]error
	FetchRefsErrByCase                 map[string]error
	RevListReverseRangeByCase          map[string]Result
	RemotePushURLByDirAndRemote        map[string]Result
	StatusPorcelainByDir               map[string]Result
	BranchShowCurrentByDir             map[string]Result
	MergeBaseIsAncestorStrictErrByCase map[string]error
	BranchSetUpstreamToErrByCase       map[string]error
	MergeTreeWriteTreeByCase           map[string]Result
	ShowTreeFormatByCase               map[string]Result
	CommitObjectExistsByCase           map[string]BoolResult
	ConfigRegexpMatchesByCase          map[string]BoolResult
	// contains filtered or unexported fields
}

Fake is a scriptable gitcli.Git: each method looks up dir (and, for IsAncestor, the ancestor/descendant pair) in a map the test populates directly, and fails loudly via panic on an unscripted call, so a test omission is caught immediately rather than answering with a silent zero value.

Fake also has task-8's fail-call-N mode (decision 23): FailCall makes one chosen call number fail regardless of its scripted result, on its own or driven by internal/testsweep.Sweep across every call a happy path makes. See CallCount and FailCall.

func (*Fake) BranchSetUpstreamTo

func (f *Fake) BranchSetUpstreamTo(_ context.Context, dir, upstream, branch string) error

BranchSetUpstreamTo implements orchestrate.Git.

func (*Fake) BranchShowCurrent

func (f *Fake) BranchShowCurrent(_ context.Context, dir string) (string, error)

BranchShowCurrent implements orchestrate.Git.

func (*Fake) CallCount

func (f *Fake) CallCount() int

CallCount reports how many calls the Fake has answered so far, across CurrentBranch, RevParse, IsAncestor, Fetch and CommitObjectExists combined, in the order it answered them. It implements internal/testsweep.Failer.

func (*Fake) CherryPick

func (f *Fake) CherryPick(_ context.Context, dir, sha string) error

CherryPick implements orchestrate.Git.

func (*Fake) CherryPickNoCommit

func (f *Fake) CherryPickNoCommit(_ context.Context, dir string, shas ...string) error

CherryPickNoCommit implements orchestrate.Git.

func (*Fake) CommitNoVerify

func (f *Fake) CommitNoVerify(_ context.Context, dir, message string) error

CommitNoVerify implements orchestrate.Git.

func (*Fake) CommitObjectExists

func (f *Fake) CommitObjectExists(_ context.Context, dir, sha string) (bool, error)

CommitObjectExists implements orchestrate.Git. It counts toward CallCount/FailCall (unlike the other orchestrate.Git port methods below), so a test whose production code calls it twice for the same case -- e.g. a retry after a best-effort fetch -- can make the second call answer differently from the first via FailCall. See FailCall's doc comment.

func (*Fake) ConfigRegexpMatches

func (f *Fake) ConfigRegexpMatches(_ context.Context, dir, pattern string) (bool, error)

ConfigRegexpMatches implements orchestrate.Git.

func (*Fake) CurrentBranch

func (f *Fake) CurrentBranch(_ context.Context, dir string) (string, error)

CurrentBranch implements gitcli.Git.

func (*Fake) FailCall

func (f *Fake) FailCall(callNum int, failErr error)

FailCall arranges for the callNum'th call (1-indexed, counting CurrentBranch, RevParse, IsAncestor, Fetch and CommitObjectExists together in the order the Fake answers them) to fail with failErr instead of returning its scripted result; every other call keeps returning its own scripted result unchanged, so FailCall fails exactly call N and passes the rest. The call FailCall targets must still be scripted (present in the relevant map) first -- FailCall replaces that call's result, not the lookup that catches an unscripted call.

This is also how a caller gets two different results from the same scripted case across two calls -- e.g. CommitObjectExists(dir, sha) answering false on its first call and an error on its second, as worktree_merge_pr_land.go's headLocal retry needs: script the case once with the first result, then FailCall(2, secondErr) so only the second of the two calls that key answers is overridden.

It works standalone, or driven once per call number by internal/testsweep.Sweep, which is why Fake implements internal/testsweep.Failer. A callNum of 0 disables the override; calling FailCall again replaces the previous target rather than adding a second one.

func (*Fake) Fetch

func (f *Fake) Fetch(_ context.Context, dir, remote string) error

Fetch implements gitcli.Git.

func (*Fake) FetchRefs

func (f *Fake) FetchRefs(_ context.Context, dir, remote string, refs ...string) error

FetchRefs implements orchestrate.Git.

func (*Fake) IsAncestor

func (f *Fake) IsAncestor(_ context.Context, dir, ancestor, descendant string) (bool, error)

IsAncestor implements gitcli.Git.

func (*Fake) MergeBaseIsAncestorStrict

func (f *Fake) MergeBaseIsAncestorStrict(_ context.Context, dir, ancestor, descendant string) error

MergeBaseIsAncestorStrict implements orchestrate.Git.

func (*Fake) MergeTreeWriteTree

func (f *Fake) MergeTreeWriteTree(_ context.Context, dir, a, b string) (string, error)

MergeTreeWriteTree implements orchestrate.Git.

func (*Fake) PushForceWithLeaseHead

func (f *Fake) PushForceWithLeaseHead(_ context.Context, dir, ref, leaseSHA string) error

PushForceWithLeaseHead implements orchestrate.Git.

func (*Fake) RemotePushURL

func (f *Fake) RemotePushURL(_ context.Context, dir, remote string) (string, error)

RemotePushURL implements orchestrate.Git.

func (*Fake) RevListReverseRange

func (f *Fake) RevListReverseRange(_ context.Context, dir, from, to string) (string, error)

RevListReverseRange implements orchestrate.Git.

func (*Fake) RevParse

func (f *Fake) RevParse(_ context.Context, dir, rev string) (string, error)

RevParse implements gitcli.Git.

func (*Fake) ShowTreeFormat

func (f *Fake) ShowTreeFormat(_ context.Context, dir, commit string) (string, error)

ShowTreeFormat implements orchestrate.Git.

func (*Fake) StatusPorcelain

func (f *Fake) StatusPorcelain(_ context.Context, dir string) (string, error)

StatusPorcelain implements orchestrate.Git.

func (*Fake) WorktreeAddDetached

func (f *Fake) WorktreeAddDetached(_ context.Context, dir, path, revision string) error

WorktreeAddDetached implements orchestrate.Git.

func (*Fake) WorktreeRemoveForce

func (f *Fake) WorktreeRemoveForce(_ context.Context, dir, worktree string) error

WorktreeRemoveForce implements orchestrate.Git.

type Result

type Result struct {
	Value string
	Err   error
}

Result is one string-returning method's canned outcome.

Jump to

Keyboard shortcuts

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