package app import ( "context" "strings" "testing" "github.com/Nwflower/reims-go/internal/config" "github.com/Nwflower/reims-go/internal/i18n" "github.com/Nwflower/reims-go/internal/macos/guest" "github.com/Nwflower/reims-go/internal/macos/reims" "github.com/Nwflower/reims-go/internal/plugin" "github.com/Nwflower/reims-go/internal/plugin/builtin" ) // Disabling macOS VM Support must also stop the native macOS pages from // driving reims-ctl behind the plugin's back. func TestNativeMacOSFlowsRefuseWhilePluginDisabled(t *testing.T) { dataRoot := t.TempDir() mgr, err := plugin.NewManager(plugin.ManagerOptions{DataRoot: dataRoot, HostVersion: "0.0.0"}) if err != nil { t.Fatal(err) } defer mgr.Close() cfg := config.Default() cfg.DataRoot = dataRoot cfg.Locale = i18n.ZhCN a := &App{cfg: cfg, pluginMgr: mgr, pollWake: make(chan struct{}, 1)} cb := builtin.HostCallbacks{GetConfig: func() config.Config { return *cfg }} if err := guest.Register(mgr.Registry(), cb, mgr.DesiredFor); err != nil { t.Fatal(err) } mgr.Registry().Reconcile(context.Background()) if err := a.requireMacOSEnabled(); err != nil { t.Fatalf("enabled plugin refused: %v", err) } if err := mgr.Disable(context.Background(), guest.ID); err != nil { t.Fatalf("disable: %v", err) } want := i18n.T(i18n.ZhCN, "err.macos.disabled") for name, call := range map[string]func() error{ "client": func() error { _, err := a.client(); return err }, "prep": func() error { _, err := a.prep("vm"); return err }, "createVM": func() error { return a.CreateVM(reims.CreateOpts{Name: "vm"}) }, } { if err := call(); err == nil || !strings.Contains(err.Error(), want) { t.Errorf("%s while disabled: err = %v, want %q", name, err, want) } } if err := mgr.Enable(context.Background(), guest.ID, false); err != nil { t.Fatalf("enable: %v", err) } if err := a.requireMacOSEnabled(); err != nil { t.Fatalf("re-enabled plugin refused: %v", err) } }