propstest

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package propstest provides a public test-fixture helper for constructing a fully-wired *props.Props with hermetic, safe defaults.

Tools built on go-tool-base — and GTB's own tests — frequently need a Props instance to drive commands and bootstrap-style code under test. Hand-assembling the logger, in-memory filesystem, telemetry collector, error handler, tool metadata and config container in every test is repetitive and easy to get wrong (for example, leaving Collector nil and violating the documented non-nil-Collector invariant).

propstest.New returns a Props with every field wired to a hermetic default: a noop logger, an in-memory afero filesystem, a NoopCollector, an error handler whose Exit and Writer are inert, benign Tool metadata, a deterministic Version, empty-but-valid Assets, and a usable empty Config container. Each field may be overridden with a functional Option.

The helper performs no real filesystem, network, keychain or os.Exit side effects, and every call returns a fresh, independent instance, so it is safe to use from t.Parallel() tests.

func TestSomething(t *testing.T) {
	t.Parallel()
	p := propstest.New(propstest.WithTool(props.Tool{Name: "mytool"}))
	// ... drive code that needs a *props.Props ...
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts ...Option) *props.Props

New constructs a fully-wired *props.Props with hermetic defaults, applying any supplied options. Every field is non-nil and safe to use, and each call returns an independent instance suitable for t.Parallel() tests.

Types

type Option

type Option func(*options)

Option customises a single field of the Props produced by New.

func WithAssets

func WithAssets(a props.Assets) Option

WithAssets overrides the default empty Assets container.

func WithCollector

func WithCollector(c props.TelemetryCollector) Option

WithCollector overrides the default NoopCollector.

func WithConfig

func WithConfig(c config.Containable) Option

WithConfig overrides the default empty config container.

func WithErrorHandler

func WithErrorHandler(h errorhandling.ErrorHandler) Option

WithErrorHandler overrides the default inert error handler.

func WithFS

func WithFS(fs afero.Fs) Option

WithFS overrides the default in-memory filesystem.

func WithLogger

func WithLogger(l logger.Logger) Option

WithLogger overrides the default noop logger.

func WithTool

func WithTool(t props.Tool) Option

WithTool overrides the default Tool metadata.

func WithVersion

func WithVersion(v version.Version) Option

WithVersion overrides the default deterministic test version.

Jump to

Keyboard shortcuts

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