Files
simslim-mirror/simctl_test.go

77 lines
2.1 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 TestParseBatchOK(t *testing.T) {
output := strings.Join([]string{
"Warning: Please switch to user/foreground/com.apple.siriactionsd service identifier (rdar://78126471)",
"simslim-ok com.apple.siriactionsd",
"simslim-fail com.apple.assistantd",
" simslim-ok com.apple.suggestd",
"simslim-ok ",
"unrelated noise",
"",
}, "\n")
got := parseBatchOK(output)
want := map[string]bool{
"com.apple.siriactionsd": true,
"com.apple.suggestd": true,
}
if len(got) != len(want) {
t.Fatalf("parseBatchOK() = %v, want %v", got, want)
}
for label := range want {
if !got[label] {
t.Errorf("parseBatchOK() missing %q", label)
}
}
}
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)
}
}
}