mirror of
https://github.com/MobAI-App/simslim.git
synced 2026-09-27 17:02:00 +02:00
The repo root becomes `package simslim`, an importable library holding every piece of slimming logic; the CLI moves to `cmd/simslim`. Previously everything was `package main`, so nothing here could be imported at all. The library carries no external dependencies — urfave/cli stays on the CLI side, along with all terminal-facing code: the interactive profile wizard, writeJSON, truncate/humanBytes, fatal and usage. The library never writes to stdout; it returns values and reports progress through the Reporter callback. Renames forced by collisions with existing types: status() -> ReadStatus, statusForDevice() -> ReadStatusForDevice, diskCleanupPlan() -> PlanDiskCleanup. The shutdown/boot timeouts move to simctl.go as ShutdownTimeout/BootTimeout. `go install` gains a path element: github.com/mobai-app/simslim/cmd/simslim. The installed binary is still named simslim, and -X main.version still applies. packaging/homebrew/simslim.rb.in is updated to match, since std_go_args passes no package path. Verified live against a real simulator: list, profiles, status, doctor, size, disk-plan, measure, boot, shutdown, on, off, on --except, on --profile, clone, rename, delete and the interactive wizard all behave identically to the previous build. JSON output, human output, help text and exit codes are unchanged.
60 lines
2.0 KiB
Go
60 lines
2.0 KiB
Go
package simslim
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestSimctlArgsForSet(t *testing.T) {
|
|
t.Run("default set omits --set", func(t *testing.T) {
|
|
got := simctlArgsForSet("", "boot", "UDID")
|
|
want := []string{"simctl", "boot", "UDID"}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Errorf("simctlArgsForSet() = %v, want %v", got, want)
|
|
}
|
|
})
|
|
t.Run("named set injects --set before the subcommand", func(t *testing.T) {
|
|
got := simctlArgsForSet("testing", "boot", "UDID")
|
|
want := []string{"simctl", "--set", "testing", "boot", "UDID"}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Errorf("simctlArgsForSet() = %v, want %v", got, want)
|
|
}
|
|
})
|
|
t.Run("simctlArgs maps a set name to its --set token", func(t *testing.T) {
|
|
got := simctlArgs("testing", "list", "devices", "-j")
|
|
want := []string{"simctl", "--set", "testing", "list", "devices", "-j"}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Errorf("simctlArgs() = %v, want %v", got, want)
|
|
}
|
|
if got := simctlArgs("default", "list"); !reflect.DeepEqual(got, []string{"simctl", "list"}) {
|
|
t.Errorf("simctlArgs(default) = %v, want no --set", got)
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestDeviceSetToken(t *testing.T) {
|
|
if got := deviceSetToken("default"); got != "" {
|
|
t.Errorf("deviceSetToken(default) = %q, want empty", got)
|
|
}
|
|
if got := deviceSetToken("testing"); got != "testing" {
|
|
t.Errorf("deviceSetToken(testing) = %q, want testing", got)
|
|
}
|
|
if deviceSetToken("unknown-set") != "" {
|
|
t.Error("an unknown set name should fall back to the default token")
|
|
}
|
|
}
|
|
|
|
func TestRegisterDeviceSetRoutes(t *testing.T) {
|
|
extraDeviceSets = nil
|
|
defer func() { extraDeviceSets = nil }()
|
|
RegisterDeviceSet("/custom/set")
|
|
// A registered set becomes discoverable like any other.
|
|
if deviceSetToken("/custom/set") != "/custom/set" {
|
|
t.Errorf("registered set not resolvable by name")
|
|
}
|
|
// A custom set's simctl args carry it as --set.
|
|
if got := simctlArgsForSet("/custom/set", "boot", "U"); !reflect.DeepEqual(got, []string{"simctl", "--set", "/custom/set", "boot", "U"}) {
|
|
t.Errorf("simctlArgsForSet(custom) = %v", got)
|
|
}
|
|
}
|