Files
Reims-Go/internal/cli/window_args_test.go
T
Nwflower f0b69c252c feat(update,plugin,ui): add in-app self-update, plugin locale packs, and About page
- Add shared resumable + SHA256SUMS-verified downloader (internal/fetch) and Windows executable swap/relaunch flow (internal/selfupdate, internal/app/appupdate_flow.go, --wait-pid in main.go/cli).
- Add dedicated About page and sidebar update capsule with background release checks, download progress, and restart confirmation when VMs are running.
- Implement plugin-contributed UI and backend/CLI locale packs (contributes.locales, LocalizedText extra tags, validation, runtime overlay, and PopupSelect language picker).
- Move kernel-irqchip and Windows processor scheduling controls into VM Compute > Performance settings, hide Plugins settings gear for VM-only schemas, and align locked system plugin switches.
2026-11-29 10:32:11 -07:00

80 lines
2.6 KiB
Go

package cli
import (
"context"
"errors"
"os"
"path/filepath"
"reflect"
"testing"
"time"
)
func TestParseWindowArgs(t *testing.T) {
cases := []struct {
args []string
want WindowArgs
isPlain bool // window launch, not a command
}{
{nil, WindowArgs{}, true},
{[]string{"--background"}, WindowArgs{Background: true}, true},
{[]string{"--background", "--start-vm=m0", `--start-result=D:\tmp\cli-start-1.json`},
WindowArgs{Background: true, StartVM: "m0", StartResult: `D:\tmp\cli-start-1.json`}, true},
{[]string{"vm", "start", "m0"}, WindowArgs{}, false},
{[]string{"--background", "vm", "list"}, WindowArgs{}, false},
{[]string{"--help"}, WindowArgs{}, false},
{[]string{"--start-vm", "m0"}, WindowArgs{}, false}, // value must be joined with =
{[]string{"--wait-pid=4242"}, WindowArgs{WaitPID: 4242}, true},
{[]string{"--background", "--wait-pid=7"}, WindowArgs{Background: true, WaitPID: 7}, true},
{[]string{"--wait-pid=0"}, WindowArgs{}, false},
{[]string{"--wait-pid=abc"}, WindowArgs{}, false},
}
for _, c := range cases {
got, ok := ParseWindowArgs(c.args)
if ok != c.isPlain || !reflect.DeepEqual(got, c.want) {
t.Errorf("ParseWindowArgs(%q) = %+v, %v; want %+v, %v", c.args, got, ok, c.want, c.isPlain)
}
if IsCommand(c.args) == c.isPlain {
t.Errorf("IsCommand(%q) = %v", c.args, !c.isPlain)
}
}
}
func TestWindowArgsRoundTrip(t *testing.T) {
w := WindowArgs{Background: true, StartVM: "mac os", StartResult: `D:\Data\tmp\cli-start-9.json`, WaitPID: 31337}
got, ok := ParseWindowArgs(w.Args())
if !ok || got != w {
t.Fatalf("round trip = %+v, %v", got, ok)
}
}
func TestStartResultRoundTrip(t *testing.T) {
dir := t.TempDir()
okPath := filepath.Join(dir, "cli-start-1.json")
if err := WriteStartResult(okPath, nil); err != nil {
t.Fatal(err)
}
res, err := waitStartResult(context.Background(), okPath, time.Second)
if err != nil || !res.OK {
t.Fatalf("ok result = %+v, %v", res, err)
}
if _, err := os.Stat(okPath); !os.IsNotExist(err) {
t.Fatal("result file should be removed once read")
}
failPath := filepath.Join(dir, "cli-start-2.json")
go func() {
time.Sleep(300 * time.Millisecond)
_ = WriteStartResult(failPath, errors.New("not enough memory"))
}()
res, err = waitStartResult(context.Background(), failPath, 5*time.Second)
if err != nil || res.OK || res.Error != "not enough memory" {
t.Fatalf("failed result = %+v, %v", res, err)
}
_, err = waitStartResult(context.Background(), filepath.Join(dir, "never.json"), 300*time.Millisecond)
if !errors.Is(err, context.DeadlineExceeded) {
t.Fatalf("missing result err = %v", err)
}
}