28 lines
589 B
Go
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
|
|
}
|