testutil

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package testutil provides golden-file and temporary-directory helpers shared across gskill tests. It is imported only from _test.go files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GitEnv added in v0.3.0

func GitEnv(extra ...string) []string

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

func Golden(t *testing.T, name string, got []byte)

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

func TempProject(t *testing.T) string

TempProject returns an isolated temporary directory usable as a gskill project root for a single test. The directory is removed when the test ends.

func Update

func Update() bool

Update reports whether the -update flag was set for this test run.

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

func (c *CountingGit) LsRemoteHeads(ctx context.Context, url string) ([]git.BranchRef, error)

LsRemoteHeads counts the call, then delegates.

func (*CountingGit) LsRemoteTags added in v0.5.0

func (c *CountingGit) LsRemoteTags(ctx context.Context, url string) ([]git.TagRef, error)

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

func (c *CountingGit) ResolveRef(ctx context.Context, url, ref string) (string, error)

ResolveRef counts non-SHA resolutions, then delegates.

Jump to

Keyboard shortcuts

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