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