ducky/devices

Paddy 2015-11-29 Parent:03c49b4d3d9f

14:1ae5bae472c1 Go to Latest

ducky/devices/memstore.go

Set up DeleteDevices in Memstore. Implement the DeleteDevices method for our Memstore, removing the Devices specified by the passed IDs. Also, create a simple test that verifies that when Devices are deleted, only the Devices you intend to delete are actually deleted. Further tests should be written to verify that this extends to ListDevicesByOwner (e.g., deleted devices will not be returned when listing them), CreateDevices (e.g., will not result in an ErrDeviceAlreadyExists error), and UpdateDevice (e.g., will return an ErrDeviceNotFound error after the Device is deleted). But for now, we're confident that it works in the simplest possible case.

History
     1.1 --- a/memstore.go	Sun Nov 29 19:46:20 2015 -0800
     1.2 +++ b/memstore.go	Sun Nov 29 21:31:47 2015 -0800
     1.3 @@ -69,7 +69,14 @@
     1.4  // DeleteDevices will remove any Devices from the Memstore that match
     1.5  // the IDs passed in. If an ID can't be matched to a Device in the
     1.6  // Memstore, then it is ignored.
     1.7 -func (m *Memstore) DeleteDevices(id []uuid.ID, c context.Context) error {
     1.8 +func (m *Memstore) DeleteDevices(ids []uuid.ID, c context.Context) error {
     1.9 +	m.lock.Lock()
    1.10 +	defer m.lock.Unlock()
    1.11 +
    1.12 +	for _, id := range ids {
    1.13 +		delete(m.devices, id.String())
    1.14 +	}
    1.15 +
    1.16  	return nil
    1.17  }
    1.18