Skip to content

Commit

Permalink
feat: [XCTest] add option
Browse files Browse the repository at this point in the history
  • Loading branch information
electricbubble committed May 18, 2021
1 parent 8c797a4 commit 00c0d0e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
21 changes: 19 additions & 2 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (d *device) lockdownService() (lockdown Lockdown, err error) {
}

var innerConn InnerConn
if innerConn, err = d.NewConnect(LockdownPort); err != nil {
if innerConn, err = d.NewConnect(LockdownPort, 0); err != nil {
return nil, err
}
d.lockdownClient = libimobiledevice.NewLockdownClient(innerConn)
Expand Down Expand Up @@ -481,7 +481,12 @@ func (d *device) MoveCrashReport(hostDir string, opts ...CrashReportMoverOption)
return d.crashReportMover.Move(hostDir, opts...)
}

func (d *device) XCTest(bundleID string) (out <-chan string, cancel context.CancelFunc, err error) {
func (d *device) XCTest(bundleID string, opts ...XCTestOption) (out <-chan string, cancel context.CancelFunc, err error) {
xcTestOpt := defaultXCTestOption()
for _, fn := range opts {
fn(xcTestOpt)
}

ctx, cancelFunc := context.WithCancel(context.TODO())
_out := make(chan string)

Expand Down Expand Up @@ -609,6 +614,18 @@ func (d *device) XCTest(bundleID string) (out <-chan string, cancel context.Canc
appOpt["ActivateSuspended"] = uint64(1)
}

if len(xcTestOpt.appEnv) != 0 {
for k, v := range xcTestOpt.appEnv {
appEnv[k] = v
}
}

if len(xcTestOpt.appOpt) != 0 {
for k, v := range xcTestOpt.appEnv {
appOpt[k] = v
}
}

d.instruments.registerCallback("outputReceived:fromProcess:atTime:", func(m libimobiledevice.DTXMessageResult) {
// fmt.Println("###### instruments ### -->", m.Aux[0])
_out <- fmt.Sprintf("%s", m.Aux[0])
Expand Down
1 change: 1 addition & 0 deletions device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func Test_device_XCTest(t *testing.T) {

bundleID = "com.leixipaopao.WebDriverAgentRunner.xctrunner"
out, cancel, err := dev.XCTest(bundleID)
// out, cancel, err := dev.XCTest(bundleID, WithXCTestEnv(map[string]interface{}{"USE_PORT": 8222, "MJPEG_SERVER_PORT": 8333}))
if err != nil {
t.Fatal(err)
}
Expand Down
39 changes: 38 additions & 1 deletion idevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type Device interface {
crashReportMoverService() (crashReportMover CrashReportMover, err error)
MoveCrashReport(hostDir string, opts ...CrashReportMoverOption) (err error)

XCTest(bundleID string) (out <-chan string, cancel context.CancelFunc, err error)
XCTest(bundleID string, opts ...XCTestOption) (out <-chan string, cancel context.CancelFunc, err error)
}

type DeviceProperties = libimobiledevice.DeviceProperties
Expand Down Expand Up @@ -133,6 +133,9 @@ type Instruments interface {
notifyOfPublishedCapabilities() (err error)
requestChannel(channel string) (id uint32, err error)

// sysMonSetConfig(cfg ...interface{}) (err error)
// SysMonStart(cfg ...interface{}) (_ interface{}, err error)

registerCallback(obj string, cb func(m libimobiledevice.DTXMessageResult))
}

Expand Down Expand Up @@ -364,6 +367,40 @@ func WithWhenMoveIsDone(whenDone func(filename string)) CrashReportMoverOption {
}
}

type xcTestOption struct {
appEnv map[string]interface{}
appArgs []interface{}
appOpt map[string]interface{}
}

func defaultXCTestOption() *xcTestOption {
return &xcTestOption{
appEnv: make(map[string]interface{}),
appArgs: make([]interface{}, 0, 2),
appOpt: make(map[string]interface{}),
}
}

type XCTestOption func(opt *xcTestOption)

func WithXCTestEnv(env map[string]interface{}) XCTestOption {
return func(opt *xcTestOption) {
opt.appEnv = env
}
}

// func WithXCTestArgs(args []interface{}) XCTestOption {
// return func(opt *xcTestOption) {
// opt.appArgs = args
// }
// }

func WithXCTestOpt(appOpt map[string]interface{}) XCTestOption {
return func(opt *xcTestOption) {
opt.appOpt = appOpt
}
}

func _removeDuplicate(strSlice []string) []string {
existed := make(map[string]bool, len(strSlice))
noRepeat := make([]string, 0, len(strSlice))
Expand Down

0 comments on commit 00c0d0e

Please sign in to comment.