Files
adb/util_test.go
Tai Groot 747c4abb7f fix(errors): implement filterErr with common adb stderr patterns
- 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
2026-04-08 10:38:56 +00:00

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)
}
})
}
}