ducky/devices
ducky/devices/memstore.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/memstore.go Thu Nov 12 23:26:26 2015 -0800 1.2 +++ b/memstore.go Sat Nov 14 05:56:04 2015 -0800 1.3 @@ -47,6 +47,12 @@ 1.4 defer m.lock.Unlock() 1.5 1.6 for _, device := range devices { 1.7 + if _, ok := m.devices[device.ID.String()]; ok { 1.8 + return ErrDeviceAlreadyExists(device.ID) 1.9 + } 1.10 + } 1.11 + 1.12 + for _, device := range devices { 1.13 m.devices[device.ID.String()] = device 1.14 } 1.15 return nil