mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
test(ios): cover tunnel close via io.Closer not child process
This commit is contained in:
1 parent
46f828d0be
commit
5bb068e77c
1 file changed
+15
-10
@@ -3,6 +3,7 @@ package ioscompanion
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -38,7 +39,7 @@ func testDeviceOptions(address string, companion transport.Companion) DeviceOpti
|
|||||||
BundleID: "com.example.app",
|
BundleID: "com.example.app",
|
||||||
Output: &bytes.Buffer{},
|
Output: &bytes.Buffer{},
|
||||||
spawnRunner: func(context.Context, string) (*exec.Cmd, error) { return &exec.Cmd{}, nil },
|
spawnRunner: func(context.Context, string) (*exec.Cmd, error) { return &exec.Cmd{}, nil },
|
||||||
spawnTunnel: func(context.Context, string, string, string) (*exec.Cmd, error) { return &exec.Cmd{}, nil },
|
startTunnel: func(context.Context, string, string, string) (io.Closer, error) { return io.NopCloser(nil), nil },
|
||||||
dialRunner: func(string) (transport.Companion, error) { return companion, nil },
|
dialRunner: func(string) (transport.Companion, error) { return companion, nil },
|
||||||
pickAddress: func() (string, error) { return address, nil },
|
pickAddress: func() (string, error) { return address, nil },
|
||||||
}
|
}
|
||||||
@@ -165,29 +166,33 @@ func TestDeviceClearStateWithoutAppPathWarnsOnce(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type recordingCloser struct{ closed bool }
|
||||||
|
|
||||||
|
func (c *recordingCloser) Close() error {
|
||||||
|
c.closed = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestDeviceCloseStopsRunnerAndTunnel(t *testing.T) {
|
func TestDeviceCloseStopsRunnerAndTunnel(t *testing.T) {
|
||||||
d := &Driver{output: &bytes.Buffer{}}
|
d := &Driver{output: &bytes.Buffer{}}
|
||||||
runner := exec.Command("sleep", "30")
|
runner := exec.Command("sleep", "30")
|
||||||
tunnel := exec.Command("sleep", "30")
|
|
||||||
if err := runner.Start(); err != nil {
|
if err := runner.Start(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := tunnel.Start(); err != nil {
|
tunnel := &recordingCloser{}
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
d.runnerChild = runner
|
d.runnerChild = runner
|
||||||
d.tunnelChild = tunnel
|
d.tunnel = tunnel
|
||||||
|
|
||||||
d.Close()
|
d.Close()
|
||||||
|
|
||||||
if d.runnerChild != nil || d.tunnelChild != nil {
|
if d.runnerChild != nil || d.tunnel != nil {
|
||||||
t.Fatal("Close must clear both child fields")
|
t.Fatal("Close must clear the runner child and the tunnel")
|
||||||
}
|
}
|
||||||
if runner.ProcessState == nil {
|
if runner.ProcessState == nil {
|
||||||
t.Fatal("Close must reap the runner session child")
|
t.Fatal("Close must reap the runner session child")
|
||||||
}
|
}
|
||||||
if tunnel.ProcessState == nil {
|
if !tunnel.closed {
|
||||||
t.Fatal("Close must reap the tunnel child")
|
t.Fatal("Close must close the usbmux tunnel")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user