still working
This commit is contained in:
27
internal/infra/osexec/fakerunner.go
Normal file
27
internal/infra/osexec/fakerunner.go
Normal file
@@ -0,0 +1,27 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user