ducky/subscriptions

Paddy 2015-06-11 Child:b240b6123548

0:56a2bef197cd Go to Latest

ducky/subscriptions/memstore.go

First implementation of datastore interface. Define Subscriptions, and the SubscriptionChange type that can modify Subscriptions. Define the subscriptionStore, which describes how Subscriptions are to be created, retrieved, updated, and deleted in/from the storage backend they're stored in. Create a Memstore implementation of the subscriptionStore, which stores all our data in-memory, for use in testing. Write tests to cover the subscriptionStore interface, testing the entire Memstore. We'll plug future storage backends into these tests, to make sure they all behave the same, and to exercise each storage backend without requiring a suite of tests for each. At this point, we have 100% test coverage and no complaints from golint or go vet. I expect it's all downhill from here.

History
paddy@0 1 package subscriptions
paddy@0 2
paddy@0 3 import (
paddy@0 4 "sync"
paddy@0 5 )
paddy@0 6
paddy@0 7 // Memstore is an in-memory version of our datastores, useful
paddy@0 8 // for testing. It should not be used in production.
paddy@0 9 type Memstore struct {
paddy@0 10 subscriptions map[string]Subscription
paddy@0 11 subscriptionLock sync.RWMutex
paddy@0 12 }
paddy@0 13
paddy@0 14 // NewMemstore returns a pointer to a Memstore object, ready
paddy@0 15 // to be used as a datastore.
paddy@0 16 func NewMemstore() *Memstore {
paddy@0 17 return &Memstore{
paddy@0 18 subscriptions: map[string]Subscription{},
paddy@0 19 }
paddy@0 20 }
paddy@0 21
paddy@0 22 func (m *Memstore) reset() error {
paddy@0 23 m.subscriptionLock.Lock()
paddy@0 24 defer m.subscriptionLock.Unlock()
paddy@0 25
paddy@0 26 m.subscriptions = map[string]Subscription{}
paddy@0 27 return nil
paddy@0 28 }