gotest

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FixtureTasks

func FixtureTasks() Task

FixtureTasks creates tasks for building and managing test fixtures. It looks for Makefiles in test-fixtures and testdata directories and runs them. Hooks into "unit" to build fixtures before tests run.

Created tasks:

  • fixtures: builds all test fixtures (runs on "unit")
  • fixtures:clean: cleans all fixture caches (runs on "clean")
  • fixtures:directories: lists all fixture directories
  • fixtures:fingerprint: outputs a hash of all fixture files for caching

func Tasks

func Tasks(options ...Option) Task

Tasks creates a test task that runs Go tests with coverage reporting. The task hooks into the "test" label, so it runs whenever "make test" is called. By default, it runs tests for all packages with coverage enabled and race detection in CI environments.

Example:

gotest.Tasks()                           // default: run all tests
gotest.Tasks(gotest.Name("integration")) // named test suite
gotest.Tasks(gotest.ExcludeGlob("**/test/**")) // exclude paths

Types

type Config

type Config struct {
	// Name identifies this test suite (e.g., "unit", "integration"). Used in logs.
	Name string
	// IncludeGlob specifies which packages to test (default: "./...").
	IncludeGlob string
	// ExcludeGlob filters out packages matching this pattern.
	ExcludeGlob string
	// Verbose enables verbose test output (-v flag).
	Verbose bool
	// Coverage enables coverage reporting (default: true).
	Coverage bool
	// CoverageFile specifies where to write coverage data. If empty, uses temp file.
	CoverageFile string
	// CoverageThreshold is the minimum total coverage percentage required to pass.
	// If > 0, the task fails when measured coverage falls below this value, or
	// when the coverage percentage cannot be parsed from the report. Requires
	// Coverage to be enabled.
	CoverageThreshold float64
	// Race enables race detector (-race flag). Defaults to true in CI on non-Windows.
	Race bool
	// Tags specifies build tags to use during testing.
	Tags []string
	// RunFilter limits which tests run (-run flag pattern).
	RunFilter string
}

Config holds configuration for the test task.

type Option

type Option func(*Config)

Option is a functional option for configuring test tasks.

func CoverageThreshold added in v0.4.0

func CoverageThreshold(percent float64) Option

CoverageThreshold sets the minimum total coverage percentage required to pass. Values <= 0 disable the check. If measured coverage falls below this value, the task fails. Example: gotest.CoverageThreshold(80) requires at least 80%.

func ExcludeGlob added in v0.1.0

func ExcludeGlob(packages string) Option

ExcludeGlob sets a pattern to exclude packages from testing.

func IncludeGlob added in v0.1.0

func IncludeGlob(packages string) Option

IncludeGlob sets which packages to include in testing (default: "./...").

func Name added in v0.1.0

func Name(name string) Option

Name sets the test suite name (used in log output and task naming).

func NoCoverage added in v0.1.0

func NoCoverage() Option

NoCoverage disables coverage reporting.

func RunFilter added in v0.1.0

func RunFilter(filter string) Option

RunFilter sets a -run pattern to limit which tests execute.

func Tags added in v0.1.0

func Tags(tags ...string) Option

Tags adds build tags to use during testing.

func Verbose added in v0.1.0

func Verbose() Option

Verbose enables verbose test output.

Jump to

Keyboard shortcuts

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