forked from zach-klippenstein/goadb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
device_state_test.go
32 lines (29 loc) · 865 Bytes
/
device_state_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package adb
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseDeviceState(t *testing.T) {
for _, test := range []struct {
String string
WantState DeviceState
WantName string
WantError error // Compared by Error() message.
}{
{"", StateDisconnected, "StateDisconnected", nil},
{"offline", StateOffline, "StateOffline", nil},
{"device", StateOnline, "StateOnline", nil},
{"unauthorized", StateUnauthorized, "StateUnauthorized", nil},
{"bad", StateInvalid, "StateInvalid", errors.New(`ParseError: invalid device state: "StateInvalid"`)},
} {
state, err := parseDeviceState(test.String)
if test.WantError == nil {
assert.NoError(t, err)
} else {
assert.EqualError(t, err, test.WantError.Error())
}
assert.Equal(t, test.WantState, state)
assert.Equal(t, test.WantName, state.String())
}
}