testutil

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testutil holds heraut's test doubles and fixtures: MockGenerator, MockPlatform, RealGitRepo, and helpers that keep the CI and git environment out of tests.

Index

Constants

View Source
const (
	Git = "git"
	Cog = "cog"
)

Binary name constants used in contract tests.

Variables

This section is empty.

Functions

func ClearCIEnv added in v0.57.0

func ClearCIEnv(t *testing.T)

ClearCIEnv neutralizes every CI marker and token variable production code reads (config.CIEnvVars), so a test's resolution outcome depends only on the variables it explicitly sets rather than the ambient environment the test happens to run in (e.g. this repo's own GitHub Actions CI).

func IsolateProcessEnv added in v1.0.1

func IsolateProcessEnv()

IsolateProcessEnv is for a package's TestMain when its tests run real git: the developer's global and system git config (commit signing, hooks, a default branch) and an exported HERAUT_FILE must not change what the tests see.

func RealGitRepo added in v0.25.0

func RealGitRepo(t *testing.T, tag string)

RealGitRepo creates a temporary git repository with a single tagged conventional commit and chdirs into it (restored on test cleanup). Used by tests that need a real git binary rather than MockRunner/FakeBin — e.g. commit-verification integration tests. Skips the test when git is not on PATH.

Types

type MockGenerator added in v0.3.0

type MockGenerator struct {
	CheckErr         error
	GenerateOut      string
	GenerateErr      error
	GenerateCalls    []string            // tags passed to Generate
	GenerateContexts []*port.LinkContext // link context passed alongside each tag (nil = single-platform)
	GenerateCtxs     []context.Context   // command context passed alongside each tag
	DegradedVal      bool                // value returned by Degraded()
	DegradedReasonV  string              // value returned by DegradedReason()
	LastOutputPathV  string              // value returned by LastOutputPath()
}

MockGenerator is a port.Generator that records calls for contract testing.

func (*MockGenerator) Check added in v0.3.0

func (m *MockGenerator) Check() error

func (*MockGenerator) Degraded added in v0.26.0

func (m *MockGenerator) Degraded() bool

Degraded reports whether the generator fell back to offline mode (T78). It mirrors the optional Degraded() method the pipeline type-asserts on real generators.

func (*MockGenerator) DegradedReason added in v0.54.0

func (m *MockGenerator) DegradedReason() string

DegradedReason mirrors the optional DegradedReason() method the pipeline type-asserts on the native generator to surface the enrichment-failure reason as a step sub-result.

func (*MockGenerator) Generate added in v0.3.0

func (m *MockGenerator) Generate(ctx context.Context, tag string, lc *port.LinkContext) (string, error)

func (*MockGenerator) LastOutputPath added in v0.59.0

func (m *MockGenerator) LastOutputPath() string

LastOutputPath mirrors the optional LastOutputPath() method the pipeline type-asserts on a rotation-wrapped generator to target the commit/summary steps at the concrete file a rotating changelog.output pattern resolved to, instead of the raw "{TOKEN}" pattern. Like the real wrapper, it knows the path only once Generate has run.

type MockPlatform added in v0.3.0

type MockPlatform struct {
	PlatformName     string
	CheckErr         error
	CreateReleaseErr error
	HasAssetsVal     bool
	CheckAssetsErr   error
	LinkContextVal   port.LinkContext

	CheckContexts []context.Context // context passed to each Check

	CreateReleaseCalls []struct {
		Ctx        context.Context
		Tag, Notes string
		Prerelease bool
	}
	ReleaseURLFromContextCalls []struct {
		Tag string
		LC  *port.LinkContext
	}
}

MockPlatform is a port.Platform that records calls for contract testing.

func (*MockPlatform) Check added in v0.3.0

func (m *MockPlatform) Check(ctx context.Context) error

func (*MockPlatform) CheckAssets added in v0.81.0

func (m *MockPlatform) CheckAssets() error

func (*MockPlatform) CreateRelease added in v0.3.0

func (m *MockPlatform) CreateRelease(ctx context.Context, tag, notes string, prerelease bool) error

func (*MockPlatform) HasAssets added in v0.3.0

func (m *MockPlatform) HasAssets() bool

func (*MockPlatform) LinkContext added in v0.24.0

func (m *MockPlatform) LinkContext() port.LinkContext

func (*MockPlatform) Name added in v0.3.0

func (m *MockPlatform) Name() string

func (*MockPlatform) ReleaseURL added in v0.3.0

func (m *MockPlatform) ReleaseURL(tag string) string

func (*MockPlatform) ReleaseURLFromContext added in v0.36.5

func (m *MockPlatform) ReleaseURLFromContext(tag string, lc *port.LinkContext) string

Jump to

Keyboard shortcuts

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