ducky/devices

Paddy 2015-11-20 Parent:7bc6a84ac906

9:f5a9d5f8f28d Go to Latest

ducky/devices/memstore_test.go

Separate out StorerFactory into its own interface. We had previously included a Factory and Destroy method in the Storer interface, but it makes more sense to separate those out into a StorerFactory interface. This lets us avoid the impression that we're using the same instance of a Storer for every test, separates the test methods away from the methods that are actually used in prod, and hides them from Godoc. What's not to like?

History
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 }