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 ¶
- type BoolResult
- type Fake
- func (f *Fake) BranchSetUpstreamTo(_ context.Context, dir, upstream, branch string) error
- func (f *Fake) BranchShowCurrent(_ context.Context, dir string) (string, error)
- func (f *Fake) CallCount() int
- func (f *Fake) CherryPick(_ context.Context, dir, sha string) error
- func (f *Fake) CherryPickNoCommit(_ context.Context, dir string, shas ...string) error
- func (f *Fake) CommitNoVerify(_ context.Context, dir, message string) error
- func (f *Fake) CommitObjectExists(_ context.Context, dir, sha string) (bool, error)
- func (f *Fake) ConfigRegexpMatches(_ context.Context, dir, pattern string) (bool, error)
- func (f *Fake) CurrentBranch(_ context.Context, dir string) (string, error)
- func (f *Fake) FailCall(callNum int, failErr error)
- func (f *Fake) Fetch(_ context.Context, dir, remote string) error
- func (f *Fake) FetchRefs(_ context.Context, dir, remote string, refs ...string) error
- func (f *Fake) IsAncestor(_ context.Context, dir, ancestor, descendant string) (bool, error)
- func (f *Fake) MergeBaseIsAncestorStrict(_ context.Context, dir, ancestor, descendant string) error
- func (f *Fake) MergeTreeWriteTree(_ context.Context, dir, a, b string) (string, error)
- func (f *Fake) PushForceWithLeaseHead(_ context.Context, dir, ref, leaseSHA string) error
- func (f *Fake) RemotePushURL(_ context.Context, dir, remote string) (string, error)
- func (f *Fake) RevListReverseRange(_ context.Context, dir, from, to string) (string, error)
- func (f *Fake) RevParse(_ context.Context, dir, rev string) (string, error)
- func (f *Fake) ShowTreeFormat(_ context.Context, dir, commit string) (string, error)
- func (f *Fake) StatusPorcelain(_ context.Context, dir string) (string, error)
- func (f *Fake) WorktreeAddDetached(_ context.Context, dir, path, revision string) error
- func (f *Fake) WorktreeRemoveForce(_ context.Context, dir, worktree string) error
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BoolResult ¶
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 ¶
BranchSetUpstreamTo implements orchestrate.Git.
func (*Fake) BranchShowCurrent ¶
BranchShowCurrent implements orchestrate.Git.
func (*Fake) CallCount ¶
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 ¶
CherryPick implements orchestrate.Git.
func (*Fake) CherryPickNoCommit ¶
CherryPickNoCommit implements orchestrate.Git.
func (*Fake) CommitNoVerify ¶
CommitNoVerify implements orchestrate.Git.
func (*Fake) CommitObjectExists ¶
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 ¶
ConfigRegexpMatches implements orchestrate.Git.
func (*Fake) CurrentBranch ¶
CurrentBranch implements gitcli.Git.
func (*Fake) FailCall ¶
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) IsAncestor ¶
IsAncestor implements gitcli.Git.
func (*Fake) MergeBaseIsAncestorStrict ¶
MergeBaseIsAncestorStrict implements orchestrate.Git.
func (*Fake) MergeTreeWriteTree ¶
MergeTreeWriteTree implements orchestrate.Git.
func (*Fake) PushForceWithLeaseHead ¶
PushForceWithLeaseHead implements orchestrate.Git.
func (*Fake) RemotePushURL ¶
RemotePushURL implements orchestrate.Git.
func (*Fake) RevListReverseRange ¶
RevListReverseRange implements orchestrate.Git.
func (*Fake) ShowTreeFormat ¶
ShowTreeFormat implements orchestrate.Git.
func (*Fake) StatusPorcelain ¶
StatusPorcelain implements orchestrate.Git.
func (*Fake) WorktreeAddDetached ¶
WorktreeAddDetached implements orchestrate.Git.