package fixtures
import "github.com/amonks/run/internal/fixtures"
Package fixtures provides test doubles for the run package.
Index
-
type Task
- func NewTask(id, taskType string) *Task
- func (t *Task) Metadata() task.TaskMetadata
- func (t *Task) Start(ctx context.Context, onReady chan<- struct{}, stdout io.Writer) error
- func (t *Task) WithCancel(err error) *Task
- func (t *Task) WithDependencies(deps ...string) *Task
- func (t *Task) WithExit(ch <-chan error) *Task
- func (t *Task) WithImmediateFailure(err error) *Task
- func (t *Task) WithOutput(output string) *Task
- func (t *Task) WithReady(ch <-chan struct{}) *Task
- func (t *Task) WithTriggers(triggers ...string) *Task
- func (t *Task) WithWatch(watch ...string) *Task
- type Writer
Types
type Task
type Task struct { // contains filtered or unexported fields }
Task is a controllable mock implementation of task.Task for testing.
func NewTask
func NewTask(id, taskType string) *Task
NewTask creates a new mock task with the given ID and type.
func (*Task) Metadata
func (t *Task) Metadata() task.TaskMetadata
func (*Task) Start
func (t *Task) Start(ctx context.Context, onReady chan<- struct{}, stdout io.Writer) error
func (*Task) WithCancel
func (t *Task) WithCancel(err error) *Task
WithCancel configures the task to block on ctx.Done() and return err when canceled.
func (*Task) WithDependencies
func (t *Task) WithDependencies(deps ...string) *Task
func (*Task) WithExit
func (t *Task) WithExit(ch <-chan error) *Task
WithExit configures the task to block until an error is sent on ch. Send nil for a clean exit.
func (*Task) WithImmediateFailure
func (t *Task) WithImmediateFailure(err error) *Task
WithImmediateFailure configures Start to return err immediately.
func (*Task) WithOutput
func (t *Task) WithOutput(output string) *Task
func (*Task) WithReady
func (t *Task) WithReady(ch <-chan struct{}) *Task
WithReady configures the task to wait for a readiness signal. The caller should close the returned channel to signal readiness.
func (*Task) WithTriggers
func (t *Task) WithTriggers(triggers ...string) *Task
func (*Task) WithWatch
func (t *Task) WithWatch(watch ...string) *Task
type Writer
type Writer struct { // contains filtered or unexported fields }
Writer is a test MultiWriter that records per-stream and combined output. It strips ANSI escape codes so that assertions don't need to account for styling.
func NewWriter
func NewWriter() *Writer
NewWriter creates a new recording Writer.
func (*Writer) CombinedString
func (w *Writer) CombinedString() string
CombinedString returns all output interleaved with [id] prefixes, with ANSI codes stripped.
func (*Writer) String
func (w *Writer) String(id string) string
String returns the raw output for a single stream, with ANSI codes stripped.
func (*Writer) Writer
func (w *Writer) Writer(id string) io.Writer
Writer returns an io.Writer for the given stream ID. Each write is recorded both in the per-stream buffer and in the combined buffer (prefixed with "[id] ").