ducky/devices
ducky/devices/memstore.go
Implement and test updating devices, and reuse contexts. Update all our tests to use the same context.Context instance within each test case, so static analysis about how we're passing contexts around dosn't get tripped up. Also, write a test that will check to make sure that our Storer implementations all actually update the Device correctly. We create every possible permutation of a DeviceChange, just to make sure they all work.
1.1 --- a/memstore.go Fri Nov 20 01:14:58 2015 -0800 1.2 +++ b/memstore.go Fri Nov 27 10:37:27 2015 -0800 1.3 @@ -35,6 +35,17 @@ 1.4 } 1.5 1.6 func (m *Memstore) UpdateDevice(change DeviceChange, c context.Context) error { 1.7 + m.lock.Lock() 1.8 + defer m.lock.Unlock() 1.9 + 1.10 + device, ok := m.devices[change.DeviceID.String()] 1.11 + if !ok { 1.12 + return nil // TODO: return an error 1.13 + } 1.14 + 1.15 + device = ApplyChange(device, change) 1.16 + m.devices[change.DeviceID.String()] = device 1.17 + 1.18 return nil 1.19 } 1.20