test(ios): a device clear-state without an app path ends the run

This commit is contained in:
pj committed 2026-08-16 01:03:48 +05:30
1 parent 220c7fe1d7
commit 99b9fe23f5
1 file changed
+25 -10
+25 -10
View File
@@ -222,17 +222,32 @@ func TestDevicectlReinstallProceedsWhenNothingIsInstalled(t *testing.T) {
} }
} }
func TestDeviceClearStateWithoutAppPathWarnsOnce(t *testing.T) { // TestNewDeviceRefusesClearStateWithoutAnAppPath keeps the device from starting
output := &bytes.Buffer{} // a run whose clear-state cannot happen. There is no data-container wipe on a
d := &Driver{output: output, deviceMode: true} // physical device, so without an app path to reinstall from, carrying on hands
d.resetContainer = d.deviceResetContainerUnsupported // the run every previous run's data under a flag that says otherwise.
for i := 0; i < 2; i++ { func TestNewDeviceRefusesClearStateWithoutAnAppPath(t *testing.T) {
if err := d.deviceResetContainerUnsupported(context.Background()); err != nil { address := startLoopbackListener(t)
t.Fatal(err) options := testDeviceOptions(address, newDeviceCompanion())
} options.HardwareUDID = "00008140-NO-APP-PATH"
options.ClearState = true
spawned := false
spawn := options.spawnRunner
options.spawnRunner = func(ctx context.Context, runnerAddress string) (*exec.Cmd, error) {
spawned = true
return spawn(ctx, runnerAddress)
} }
if got := bytes.Count(output.Bytes(), []byte("requires --ios-app-path")); got != 1 {
t.Fatalf("warning emitted %d times, want once", got) d, err := NewDevice(context.Background(), options)
if err == nil {
d.Close()
t.Fatal("NewDevice returned a driver whose clear-state never happened")
}
if !strings.Contains(err.Error(), "--ios-app-path") {
t.Fatalf("err = %v, want it to name the flag that makes the clear possible", err)
}
if spawned {
t.Fatal("the run started anyway; a clear-state that cannot happen must end the run, not open it")
} }
} }