Commit graph

1 commit

Author SHA1 Message Date
b2756f5e7e
test: add newTestDaemon harness + options
No Daemon test in this package has a shared constructor. Every file
re-derives the same pattern — &Daemon{...}, wireServices(d), maybe
override a field — which means new lifecycle / integration tests
spend half their length standing up infrastructure instead of
exercising behaviour.

Consolidate into internal/daemon/daemon_testing_test.go:

  func newTestDaemon(t *testing.T, opts ...testDaemonOption) *Daemon

Defaults: tempdir layout (distinct StateDir/ConfigDir/SSHDir/...),
fresh store.Store with migrations auto-run, permissiveRunner,
io.Discard logger, empty vmCaps (so default workDisk/dns/nat
capabilities don't fire real side effects in tests that just want
to exercise VMService plumbing).

Options so far:
  - withRunner(system.CommandRunner)
  - withConfig(model.DaemonConfig)
  - withStore(*store.Store)
  - withLogger(*slog.Logger)
  - withLayout(paths.Layout)
  - withVMCaps(caps ...vmCapability)
  - withVsockHostDevice(string)

withVMCaps tracks a vmCapsSet flag so tests that explicitly pass no
caps (i.e. the default) still get the empty-slice behaviour — the
reset after wireServices only fires when the caller didn't opt in.
That keeps wireServices's production semantics unchanged: if you
construct a real Daemon without pre-populating vmCaps, you still
get the default three.

Two smoke tests pin:
  - zero-option call wires every service, gives an empty-vmCaps
    daemon with the default vsock device, store non-nil
  - each option actually lands on the resulting Daemon (guards
    against silent rename)

Existing tests unchanged — this is purely additive. Later slices
(Firecracker error-path tests, store migration edges, lifecycle
flow harness) will adopt the helper.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 17:45:43 -03:00