mirror of
https://github.com/taigrr/adb.git
synced 2026-04-14 00:08:16 -07:00
- Implement filterErr to detect device-not-found, offline, unauthorized, connection-refused, and multiple-device errors from stderr output - Add ErrDeviceNotFound, ErrDeviceOffline, ErrDeviceUnauthorized, ErrConnectionRefused, ErrMoreThanOneDevice sentinel errors - Remove log.Printf in CaptureSequence (was marked TODO for removal) - Fix ConnString to use local variable instead of mutating value receiver - Update go directive to 1.26.2 - Update README: check implemented features, fix intro typo, add root/keyevent/getevent to supported functions list - Expand filterErr tests for all new error patterns
31 lines
1.0 KiB
Go
31 lines
1.0 KiB
Go
package adb
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func Test_filterErr(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
stderr string
|
|
wantErr error
|
|
}{
|
|
{name: "empty stderr", stderr: "", wantErr: nil},
|
|
{name: "random output", stderr: "some warning text", wantErr: nil},
|
|
{name: "device not found", stderr: "error: device not found", wantErr: ErrDeviceNotFound},
|
|
{name: "device offline", stderr: "error: device offline", wantErr: ErrDeviceOffline},
|
|
{name: "device unauthorized", stderr: "error: device unauthorized.\nThis adb server's $ADB_VENDOR_KEYS is not set", wantErr: ErrDeviceUnauthorized},
|
|
{name: "connection refused", stderr: "cannot connect to daemon at tcp:5037: Connection refused", wantErr: ErrConnectionRefused},
|
|
{name: "more than one device", stderr: "error: more than one device/emulator", wantErr: ErrMoreThanOneDevice},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := filterErr(tt.stderr)
|
|
if !errors.Is(err, tt.wantErr) {
|
|
t.Errorf("filterErr() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|