52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"scm.bstein.dev/bstein/ananke/internal/config"
|
|
)
|
|
|
|
// TestDaemonMaybeRunPostStartAutoHeal runs one orchestration or CLI step.
|
|
// Signature: TestDaemonMaybeRunPostStartAutoHeal(t *testing.T).
|
|
// Why: covers the daemon-side interval and on-battery guards for the new
|
|
// post-start repair loop.
|
|
func TestDaemonMaybeRunPostStartAutoHeal(t *testing.T) {
|
|
calls := 0
|
|
d := &Daemon{
|
|
cfg: config.Config{
|
|
Startup: config.Startup{
|
|
PostStartAutoHealSeconds: 10,
|
|
},
|
|
},
|
|
postStartAutoHealOverride: func(context.Context) error {
|
|
calls++
|
|
return nil
|
|
},
|
|
}
|
|
|
|
var last time.Time
|
|
d.maybeRunPostStartAutoHeal(context.Background(), &last, false)
|
|
if calls != 1 {
|
|
t.Fatalf("expected first auto-heal invocation, got %d", calls)
|
|
}
|
|
|
|
d.maybeRunPostStartAutoHeal(context.Background(), &last, false)
|
|
if calls != 1 {
|
|
t.Fatalf("expected interval guard to suppress second call, got %d", calls)
|
|
}
|
|
|
|
last = time.Now().Add(-11 * time.Second)
|
|
d.maybeRunPostStartAutoHeal(context.Background(), &last, true)
|
|
if calls != 1 {
|
|
t.Fatalf("expected on-battery guard to suppress call, got %d", calls)
|
|
}
|
|
|
|
last = time.Now().Add(-11 * time.Second)
|
|
d.maybeRunPostStartAutoHeal(context.Background(), &last, false)
|
|
if calls != 2 {
|
|
t.Fatalf("expected second allowed auto-heal call, got %d", calls)
|
|
}
|
|
}
|