ducky/devices
ducky/devices/devices.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.
1.1 --- a/devices.go Thu Nov 12 23:26:26 2015 -0800 1.2 +++ b/devices.go Sat Nov 14 05:56:04 2015 -0800 1.3 @@ -2,6 +2,7 @@ 1.4 1.5 import ( 1.6 "errors" 1.7 + "fmt" 1.8 "log" 1.9 "time" 1.10 1.11 @@ -81,6 +82,12 @@ 1.12 Destroy(c context.Context) error 1.13 } 1.14 1.15 +type ErrDeviceAlreadyExists uuid.ID 1.16 + 1.17 +func (e ErrDeviceAlreadyExists) Error() string { 1.18 + return fmt.Sprintf("device with ID %s already exists in datastore", uuid.ID(e).String()) 1.19 +} 1.20 + 1.21 // GetMany returns as many of the Devices specified by the passed IDs as possible. 1.22 // They are returned as a map, with the key being the string version of the ID. 1.23 // No error will be returned if a Device can't be found.