testutil

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 11 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 GitOutput added in v0.7.1

func GitOutput(t *testing.T, dir string, args ...string) string

GitOutput runs a git command in dir and returns its trimmed stdout.

func GitRun added in v0.7.1

func GitRun(t *testing.T, dir string, args ...string)

GitRun runs a git command in dir with a scrubbed environment, failing the test on error.

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 InitSkillRepo added in v0.7.1

func InitSkillRepo(t *testing.T, name, body string, tags ...string) string

InitSkillRepo creates a local git repository holding one skill directory named name with body as its SKILL.md, an initial commit, and the given tags. It returns the repository path and skips the test when git is unavailable.

func PublishCommit added in v0.7.1

func PublishCommit(t *testing.T, repo, name, body string) string

PublishCommit replaces the skill's SKILL.md with body and commits it without tagging, advancing the branch head. It returns the new commit SHA.

func PublishVersion added in v0.7.1

func PublishVersion(t *testing.T, repo, name, body, tag string)

PublishVersion replaces the skill's SKILL.md with body, commits, and tags the commit — the "upstream publishes a newer release" step of a lifecycle test.

func SkillBody added in v0.7.1

func SkillBody(name, marker string) string

SkillBody returns a valid SKILL.md for name whose heading carries marker, so installed content can be told apart across versions.

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