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 ¶
- func New(opts ...Option) *props.Props
- type Option
- func WithAssets(a props.Assets) Option
- func WithCollector(c props.TelemetryCollector) Option
- func WithConfig(c config.Containable) Option
- func WithErrorHandler(h errorhandling.ErrorHandler) Option
- func WithFS(fs afero.Fs) Option
- func WithLogger(l logger.Logger) Option
- func WithTool(t props.Tool) Option
- func WithVersion(v version.Version) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(*options)
Option customises a single field of the Props produced by New.
func WithAssets ¶
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 WithLogger ¶
WithLogger overrides the default noop logger.
func WithVersion ¶
WithVersion overrides the default deterministic test version.