Files
simslim-mirror/features_test.go
Interlap ffd3a13d34 refactor: split into an importable library and a cmd/simslim CLI (#14)
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.
2026-07-23 12:39:20 +02:00

93 lines
2.6 KiB
Go

package simslim
import (
"reflect"
"testing"
)
func TestFeatureLabelsAreSlimmable(t *testing.T) {
slimmable := SlimmableSet()
for _, f := range Features {
if len(f.Labels) == 0 {
t.Errorf("feature %q has no labels", f.ID)
}
for _, l := range f.Labels {
if !slimmable[l] {
t.Errorf("feature %q names %q, which no category disables", f.ID, l)
}
}
}
}
func TestFeatureIDsAreUniqueAndNamed(t *testing.T) {
seen := map[string]bool{}
for _, f := range Features {
if f.ID == "" {
t.Error("a feature has an empty ID")
}
if f.Name == "" {
t.Errorf("feature %q has no name", f.ID)
}
if seen[f.ID] {
t.Errorf("duplicate feature ID %q", f.ID)
}
seen[f.ID] = true
}
}
func TestResolveFeatures(t *testing.T) {
got, err := ResolveFeatures([]string{"push", "storekit"})
if err != nil {
t.Fatalf("ResolveFeatures() error = %v", err)
}
if len(got) != 2 || got[0].ID != "push" || got[1].ID != "storekit" {
t.Errorf("resolveFeatures = %v, want [push storekit]", got)
}
if _, err := ResolveFeatures([]string{"push", "nope"}); err == nil {
t.Error("ResolveFeatures(unknown) error = nil, want error")
}
}
func TestDiagnoseFeatures(t *testing.T) {
features, err := ResolveFeatures([]string{"push", "storekit", "universal-links"})
if err != nil {
t.Fatalf("ResolveFeatures() error = %v", err)
}
t.Run("all healthy on a stock device", func(t *testing.T) {
report := DiagnoseFeatures(features, map[string]bool{})
if !report.OK {
t.Errorf("OK = false, want true for %v", report.Features)
}
})
t.Run("a disabled daemon breaks its feature", func(t *testing.T) {
disabled := map[string]bool{"com.apple.storekitd": true}
report := DiagnoseFeatures(features, disabled)
if report.OK {
t.Error("OK = true, want false when storekitd is disabled")
}
byID := map[string]FeatureStatus{}
for _, f := range report.Features {
byID[f.ID] = f
}
if byID["storekit"].OK {
t.Error("storekit reported OK despite storekitd disabled")
}
if !reflect.DeepEqual(byID["storekit"].Disabled, []string{"com.apple.storekitd"}) {
t.Errorf("storekit.Disabled = %v, want [com.apple.storekitd]", byID["storekit"].Disabled)
}
if !byID["push"].OK || !byID["universal-links"].OK {
t.Error("unrelated features should stay OK")
}
})
t.Run("any disabled backing daemon breaks a multi-daemon feature", func(t *testing.T) {
spotlight, _ := ResolveFeatures([]string{"spotlight"})
report := DiagnoseFeatures(spotlight, map[string]bool{"com.apple.searchtoold": true})
if report.OK {
t.Error("spotlight reported OK with searchtoold disabled")
}
})
}