mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-08 00:47:36 +08:00
Merge branch 'fix/yuhongzheng/adb_device_format' into 'feature/huangbin/stability_optimization'
Fix/yuhongzheng/adb device format See merge request iesqa/httprunner!27
This commit is contained in:
@@ -41,7 +41,11 @@ var listAndroidDevicesCmd = &cobra.Command{
|
|||||||
if isDetail {
|
if isDetail {
|
||||||
fmt.Println(format(d.DeviceInfo()))
|
fmt.Println(format(d.DeviceInfo()))
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(d.Serial(), d.Usb())
|
if usb, err := d.Usb(); err != nil {
|
||||||
|
fmt.Println(d.Serial())
|
||||||
|
} else {
|
||||||
|
fmt.Println(d.Serial(), usb)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ func (c Client) DeviceList() (devices []*Device, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fields := strings.Fields(line)
|
fields := strings.Fields(line)
|
||||||
if len(fields) < 5 || len(fields[0]) == 0 {
|
if len(fields) < 4 || len(fields[0]) == 0 {
|
||||||
log.Error().Str("line", line).Msg("get unexpected line")
|
log.Error().Str("line", line).Msg("get unexpected line")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -117,6 +117,9 @@ func (c Client) DeviceList() (devices []*Device, err error) {
|
|||||||
mapAttrs := map[string]string{}
|
mapAttrs := map[string]string{}
|
||||||
for _, field := range sliceAttrs {
|
for _, field := range sliceAttrs {
|
||||||
split := strings.Split(field, ":")
|
split := strings.Split(field, ":")
|
||||||
|
if len(split) == 1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
key, val := split[0], split[1]
|
key, val := split[0], split[1]
|
||||||
mapAttrs[key] = val
|
mapAttrs[key] = val
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-10
@@ -107,20 +107,37 @@ func (d *Device) features() (features Features, err error) {
|
|||||||
return features, nil
|
return features, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) Product() string {
|
func (d Device) HasAttribute(key string) bool {
|
||||||
return d.attrs["product"]
|
_, ok := d.attrs[key]
|
||||||
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) Model() string {
|
func (d Device) Product() (string, error) {
|
||||||
return d.attrs["model"]
|
if d.HasAttribute("product") {
|
||||||
|
return d.attrs["product"], nil
|
||||||
|
}
|
||||||
|
return "", errors.New("does not have attribute: product")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) Usb() string {
|
func (d Device) Model() (string, error) {
|
||||||
return d.attrs["usb"]
|
if d.HasAttribute("model") {
|
||||||
|
return d.attrs["model"], nil
|
||||||
|
}
|
||||||
|
return "", errors.New("does not have attribute: model")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) transportId() string {
|
func (d *Device) Usb() (string, error) {
|
||||||
return d.attrs["transport_id"]
|
if d.HasAttribute("usb") {
|
||||||
|
return d.attrs["usb"], nil
|
||||||
|
}
|
||||||
|
return "", errors.New("does not have attribute: usb")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d Device) transportId() (string, error) {
|
||||||
|
if d.HasAttribute("transport_id") {
|
||||||
|
return d.attrs["transport_id"], nil
|
||||||
|
}
|
||||||
|
return "", errors.New("does not have attribute: transport_id")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) DeviceInfo() map[string]string {
|
func (d *Device) DeviceInfo() map[string]string {
|
||||||
@@ -132,8 +149,13 @@ func (d *Device) Serial() string {
|
|||||||
return d.serial
|
return d.serial
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) IsUsb() bool {
|
func (d *Device) IsUsb() (bool, error) {
|
||||||
return d.Usb() != ""
|
usb, err := d.Usb()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return usb != "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) State() (DeviceState, error) {
|
func (d *Device) State() (DeviceState, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user