test(app): adapt disk_flow_test to lifecycle driver router

This commit is contained in:
Nwflower committed 2026-12-01 04:36:46 -07:00
1 parent b493b395e4
commit 16fe93defd
1 file changed
+26 -27
+26 -27
View File
@@ -11,25 +11,9 @@ import (
"github.com/Nwflower/reims-go/internal/config"
"github.com/Nwflower/reims-go/internal/driver"
vmlifecycle "github.com/Nwflower/reims-go/internal/lifecycle"
"github.com/Nwflower/reims-go/internal/plugin"
)
type stubStatsDriver struct {
diskPath string
}
func (d stubStatsDriver) ID() string { return driver.BuiltinReimsMacOSDriverID }
func (d stubStatsDriver) Capabilities() []string { return nil }
func (d stubStatsDriver) List(context.Context) ([]driver.VMInfo, error) { return []driver.VMInfo{{Name: "test", DriverID: d.ID(), State: "stopped", DiskPath: d.diskPath}}, nil }
func (d stubStatsDriver) Inspect(context.Context, string) (driver.VMInfo, error) {
return driver.VMInfo{Name: "test", DriverID: d.ID(), State: "stopped", DiskPath: d.diskPath}, nil
}
func (d stubStatsDriver) Start(context.Context, driver.StartRequest) (driver.StartResult, error) {
return driver.StartResult{}, nil
}
func (d stubStatsDriver) Stop(context.Context, string, bool, interface{ Write([]byte) (int, error) }, interface{ Write([]byte) (int, error) }) error {
return nil
}
func TestGetDefenderExclusionCommand(t *testing.T) {
a := &App{cfg: &config.Config{DataRoot: `D:\Rei's VMs`}}
const want = `Add-MpPreference -ExclusionPath 'D:\Rei''s VMs' -ExclusionProcess 'qemu-system-x86_64.exe'`
@@ -40,13 +24,6 @@ func TestGetDefenderExclusionCommand(t *testing.T) {
func TestVMStatsDiskHeaderMeta(t *testing.T) {
cfg := &config.Config{DataRoot: t.TempDir()}
runtimeDir := filepath.Join(cfg.RuntimesDir(), "test")
if err := os.MkdirAll(runtimeDir, 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(runtimeDir, "manifest.json"), []byte(`{"commit":"test"}`), 0o644); err != nil {
t.Fatal(err)
}
disk := filepath.Join(cfg.DataRoot, "disk.qcow2")
hdr := make([]byte, 104)
copy(hdr, "QFI\xfb")
@@ -57,12 +34,34 @@ func TestVMStatsDiskHeaderMeta(t *testing.T) {
t.Fatal(err)
}
router := driver.NewRouter()
router.Register(stubStatsDriver{diskPath: disk})
drv := &appSecondDriver{
id: driver.BuiltinReimsMacOSDriverID,
vms: []driver.VMInfo{{
Name: "test",
DriverID: driver.BuiltinReimsMacOSDriverID,
Directory: cfg.DataRoot,
State: "stopped",
DiskPath: disk,
}},
}
reg := plugin.NewRegistry(nil)
if err := reg.Register(plugin.PluginDef{
Manifest: plugin.Manifest{ID: "test.macos", Version: "1.0.0"},
Source: plugin.SourceBuiltin,
Desired: true,
Activate: func(_ context.Context, sc *plugin.Scope) error {
reg.RegisterGuestDriver(sc, drv.id, drv)
return nil
},
}); err != nil {
t.Fatal(err)
}
reg.Reconcile(context.Background())
router := driver.NewRouter(reg, nil)
a := &App{
cfg: cfg,
lastVMsAt: time.Now(),
lifecycleSvc: vmlifecycle.New(router, nil),
lifecycleSvc: vmlifecycle.New(reg, router, nil),
}
stats, err := a.GetVMStats("test")
if err != nil || !stats.DiskExtendedL2 || stats.DiskSnapshotCount != 2 {