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.
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package simslim
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestNormalizeSimulatorName(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
want string
|
|
wantError bool
|
|
}{
|
|
{name: "ordinary", input: "QA iPhone", want: "QA iPhone"},
|
|
{name: "trims whitespace", input: " QA iPhone ", want: "QA iPhone"},
|
|
{name: "unicode", input: "Démo 📱", want: "Démo 📱"},
|
|
{name: "empty", input: " ", wantError: true},
|
|
{name: "embedded control", input: "QA\nPhone", wantError: true},
|
|
{name: "too long", input: strings.Repeat("a", 129), wantError: true},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := NormalizeSimulatorName(tt.input)
|
|
if (err != nil) != tt.wantError {
|
|
t.Fatalf("NormalizeSimulatorName() error = %v, wantError %v", err, tt.wantError)
|
|
}
|
|
if got != tt.want {
|
|
t.Errorf("NormalizeSimulatorName() = %q, want %q", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseClonedUDID(t *testing.T) {
|
|
const udid = "00000000-0000-0000-0000-000000000001"
|
|
got, err := parseClonedUDID([]byte("\n" + udid + "\n"))
|
|
if err != nil {
|
|
t.Fatalf("parseClonedUDID() error = %v", err)
|
|
}
|
|
if got != udid {
|
|
t.Errorf("parseClonedUDID() = %q, want %q", got, udid)
|
|
}
|
|
|
|
for _, invalid := range []string{"", "not-a-udid", "00000000-0000-0000-0000-00000000000Z"} {
|
|
if _, err := parseClonedUDID([]byte(invalid)); err == nil {
|
|
t.Errorf("parseClonedUDID(%q) unexpectedly succeeded", invalid)
|
|
}
|
|
}
|
|
}
|