ducky/devices

Paddy 2015-11-14 Parent:600326d50e74

5:408abf6e48d3 Go to Latest

ducky/devices/device_type.go

Add more interface tests. Add a test to ensure that, when retrieving Devices, no error is returned if a Device cannot be found. Add a test to ensure that, when adding Devices, adding a Device that shares an ID with a Device already in the Storer returns an ErrDeviceAlreadyExists error. This involved creating the ErrDeviceAlreadyExists error, and modifying the in-memory implementation to properly return it. Fix a go vet issue in our previous test, wherein we forgot to pass the storer to a log message, resulting in a mismatch between the number of variables expected and the number of variables provided. Rename our tests to be better reflective of what they actually test.

History
1 package devices
3 const (
4 // TypeAndroidTablet is used to designate a Device as an
5 // Android tablet, usually for display purposes.
6 TypeAndroidTablet = DeviceType("android_tablet")
7 // TypeAndroidPhone is used to designate a Device as an
8 // Android phone, usually for display purposes.
9 TypeAndroidPhone = DeviceType("android_phone")
10 // TypeChromeExtension is used to designate a device as a
11 // Chrome extension, usually for display purposes.
12 TypeChromeExtension = DeviceType("chrome_extension")
13 )
15 // DeviceType is an enum specifying which type of Device it is. Usually,
16 // this is something like `android_phone` or `android_tablet`.
17 type DeviceType string
19 // IsValidDeviceType validates the DeviceType against a list of
20 // DeviceTypes that have been whitelisted as "valid".
21 func IsValidDeviceType(d DeviceType) bool {
22 switch d {
23 case TypeAndroidTablet:
24 return true
25 case TypeAndroidPhone:
26 return true
27 case TypeChromeExtension:
28 return true
29 default:
30 return false
31 }
32 }