Documentation
¶
Overview ¶
Package testutil provides golden-file and temporary-directory helpers shared across gskill tests. It is imported only from _test.go files.
Index ¶
- func GitEnv(extra ...string) []string
- func Golden(t *testing.T, name string, got []byte)
- func TempProject(t *testing.T) string
- func Update() bool
- type CountingGit
- func (c *CountingGit) FetchCommit(ctx context.Context, url, commit, dest string) error
- func (c *CountingGit) LsRemoteHeads(ctx context.Context, url string) ([]git.BranchRef, error)
- func (c *CountingGit) LsRemoteTags(ctx context.Context, url string) ([]git.TagRef, error)
- func (c *CountingGit) ResolutionCalls() int64
- func (c *CountingGit) ResolveRef(ctx context.Context, url, ref string) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GitEnv ¶ added in v0.3.0
GitEnv returns a subprocess environment safe for running git against a test's own isolated fixture repository: os.Environ() with every ambient GIT_* variable stripped, plus extra appended. Without this, a git command invoked from inside a real git hook (as gotest-short runs under pre-commit) inherits GIT_DIR/GIT_WORK_TREE/GIT_INDEX_FILE that git sets for the hook subprocess tree, so a fixture's "git init" in its own t.TempDir() silently operates on the enclosing gskill repository instead — under t.Parallel() this races real git state and can corrupt it.
This strips every GIT_* variable, unlike internal/git.sanitizedEnv's narrower repo-location-only allowlist: fixtures are local, no-auth repos that never need GIT_SSH_COMMAND/GIT_ASKPASS/GIT_CONFIG_*, so the blunter strip is safe here even though it would be wrong for gskill's own fetches.
func Golden ¶
Golden compares got against the golden file at testdata/<name>. When -update is set it rewrites the golden file instead of asserting equality, so golden files can be regenerated with "go test -update".
func TempProject ¶
TempProject returns an isolated temporary directory usable as a gskill project root for a single test. The directory is removed when the test ends.
Types ¶
type CountingGit ¶ added in v0.5.0
type CountingGit struct {
Inner git.Runner
Latency time.Duration // simulated network latency per counted call
Fail error // when set, every counted call returns it
Tags, Heads, Refs, Fetches atomic.Int64
}
CountingGit wraps a git.Runner, counting network calls per method and optionally injecting latency or a fixed error. A ResolveRef of a full commit SHA is not counted: the real runner answers it locally. Counters are safe for concurrent use.
func (*CountingGit) FetchCommit ¶ added in v0.5.0
func (c *CountingGit) FetchCommit(ctx context.Context, url, commit, dest string) error
FetchCommit counts the call, then delegates.
func (*CountingGit) LsRemoteHeads ¶ added in v0.5.0
LsRemoteHeads counts the call, then delegates.
func (*CountingGit) LsRemoteTags ¶ added in v0.5.0
LsRemoteTags counts the call, then delegates.
func (*CountingGit) ResolutionCalls ¶ added in v0.5.0
func (c *CountingGit) ResolutionCalls() int64
ResolutionCalls returns the total ls-remote-style round trips (everything except FetchCommit).
func (*CountingGit) ResolveRef ¶ added in v0.5.0
ResolveRef counts non-SHA resolutions, then delegates.