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 GitOutput(t *testing.T, dir string, args ...string) string
- func GitRun(t *testing.T, dir string, args ...string)
- func Golden(t *testing.T, name string, got []byte)
- func InitSkillRepo(t *testing.T, name, body string, tags ...string) string
- func PublishCommit(t *testing.T, repo, name, body string) string
- func PublishVersion(t *testing.T, repo, name, body, tag string)
- func SkillBody(name, marker string) string
- 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 GitOutput ¶ added in v0.7.1
GitOutput runs a git command in dir and returns its trimmed stdout.
func GitRun ¶ added in v0.7.1
GitRun runs a git command in dir with a scrubbed environment, failing the test on error.
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 InitSkillRepo ¶ added in v0.7.1
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
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
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
SkillBody returns a valid SKILL.md for name whose heading carries marker, so installed content can be told apart across versions.
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.