ducky/devices
2015-11-27
Parent:f5a9d5f8f28d
ducky/devices/memstore_test.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 package devices
3 import (
4 "fmt"
6 "golang.org/x/net/context"
7 )
9 func init() {
10 storerFactories = append(storerFactories, MemstoreFactory{})
11 }
13 type MemstoreFactory struct {
14 }
16 func (m MemstoreFactory) NewStorer(ctx context.Context) (Storer, error) {
17 return NewMemstore(), nil
18 }
20 func (m MemstoreFactory) TeardownStorer(storer Storer, ctx context.Context) error {
21 memstorer, ok := storer.(*Memstore)
22 if !ok {
23 return fmt.Errorf("Storer was not a *Memstore, was a %T", storer)
24 }
25 memstorer.devices = nil
26 return nil
27 }