Events to the frontend go through App.emit, and a test keeps their names in step with wails.ts. QEMU argument splitting, hidden console processes, the macOS release record, the running check and a few smaller helpers now exist once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
2.0 KiB
Go
56 lines
2.0 KiB
Go
package app
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/Nwflower/reims-go/internal/macos/reims"
|
|
)
|
|
|
|
func TestParseDiskSnapshotsJSON(t *testing.T) {
|
|
raw := []byte(`{
|
|
"format": "qcow2",
|
|
"snapshots": [
|
|
{"id": "1", "name": "before-ota", "vm-state-size": 0, "date-sec": 1764400000},
|
|
{"id": "2", "name": "clean-xcode", "vm-state-size": 0, "date-sec": 1764403600}
|
|
]
|
|
}`)
|
|
fmtName, snaps, err := reims.ParseDiskSnapshotsJSON(raw)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if fmtName != "qcow2" || len(snaps) != 2 || snaps[0].Name != "before-ota" || snaps[1].CreatedAt != 1764403600 {
|
|
t.Fatalf("unexpected snapshots: format=%q snaps=%+v", fmtName, snaps)
|
|
}
|
|
}
|
|
|
|
func TestSanitizeVMNoteAndStorageBreakdown(t *testing.T) {
|
|
if got := sanitizeVMNote(" Xcode 26\nBuilder "); got != "Xcode 26 Builder" {
|
|
t.Fatalf("sanitizeVMNote = %q", got)
|
|
}
|
|
root := t.TempDir()
|
|
vms := filepath.Join(root, "vms")
|
|
inst := filepath.Join(root, "installers")
|
|
rtDir := filepath.Join(root, "runtimes")
|
|
_ = os.MkdirAll(filepath.Join(vms, "mac-a"), 0o755)
|
|
_ = os.MkdirAll(filepath.Join(vms, "mac-b"), 0o755)
|
|
_ = os.MkdirAll(inst, 0o755)
|
|
_ = os.MkdirAll(rtDir, 0o755)
|
|
_ = os.MkdirAll(filepath.Join(root, "cache"), 0o755)
|
|
_ = os.WriteFile(filepath.Join(vms, "mac-a", "disk.qcow2"), make([]byte, 200), 0o644)
|
|
_ = os.WriteFile(filepath.Join(vms, "mac-b", "disk.qcow2"), make([]byte, 500), 0o644)
|
|
_ = os.WriteFile(filepath.Join(inst, "tahoe.img"), make([]byte, 1000), 0o644)
|
|
_ = os.WriteFile(filepath.Join(rtDir, "qemu.exe"), make([]byte, 300), 0o644)
|
|
_ = os.WriteFile(filepath.Join(root, "cache", "download.tmp"), make([]byte, 75), 0o644)
|
|
_ = os.WriteFile(filepath.Join(root, "reims-go.json"), make([]byte, 25), 0o644)
|
|
|
|
bd := computeStorageBreakdown(root, vms, inst, "")
|
|
if bd.VMsBytes != 700 || bd.InstallersBytes != 1000 || bd.RuntimesBytes != 400 || bd.TotalBytes != 2100 {
|
|
t.Fatalf("breakdown = %+v", bd)
|
|
}
|
|
if len(bd.VMs) != 2 || bd.VMs[0].Name != "mac-b" || bd.VMs[0].Bytes != 500 {
|
|
t.Fatalf("VMs order = %+v", bd.VMs)
|
|
}
|
|
}
|