Files
storage-appliance/internal/infra/osexec/fakerunner.go
2025-12-13 15:31:52 +00:00

28 lines
589 B
Go

package osexec
import (
"context"
"time"
)
// FakeRunner is a test-friendly Runner that returns pre-determined values, supports delays, and can simulate timeouts.
type FakeRunner struct {
Stdout string
Stderr string
ExitCode int
Delay time.Duration
Err error
}
func (f *FakeRunner) Run(ctx context.Context, name string, args ...string) (string, string, int, error) {
if f.Delay > 0 {
select {
case <-time.After(f.Delay):
case <-ctx.Done():
// Pass through context error
return "", "", -1, ctx.Err()
}
}
return f.Stdout, f.Stderr, f.ExitCode, f.Err
}