update driver Queryor interface to reflect list filtering mechanism

pull/1007/head
fibonacci1729 8 years ago
parent bfd6712c94
commit a05b48f320

@ -27,24 +27,34 @@ var (
ErrNotImplemented = errors.New("not implemented") ErrNotImplemented = errors.New("not implemented")
) )
// Creator stores a release.
type Creator interface { type Creator interface {
Create(*rspb.Release) error Create(rls *rspb.Release) error
} }
// Updator updates an existing release or returns
// ErrReleaseNotFound if the release does not exist.
type Updator interface { type Updator interface {
Update(*rspb.Release) error Update(rls *rspb.Release) error
} }
// Deletor deletes the release named by key or returns
// ErrReleaseNotFound if the release does not exist.
type Deletor interface { type Deletor interface {
Delete(string) (*rspb.Release, error) Delete(key string) (*rspb.Release, error)
} }
// Queryor defines the behavior on accessing a release from storage.
type Queryor interface { type Queryor interface {
Get(string) (*rspb.Release, error) // Get returns the release named by key or returns ErrReleaseNotFound
// if the release does not exist.
All(string, ...interface{}) ([]*rspb.Release, error) Get(key string) (*rspb.Release, error)
// List returns the set of all releases that satisfy the filter predicate.
List(filter func(*rspb.Release) bool) ([]*rspb.Release, error)
} }
// Driver defines the behavior for storing, updating, deleted, and retrieving
// tiller releases from some underlying storage mechanism, e.g. memory, configmaps.
type Driver interface { type Driver interface {
Creator Creator
Updator Updator

@ -41,14 +41,14 @@ func (mem *Memory) Get(key string) (*rspb.Release, error) {
return nil, ErrReleaseNotFound return nil, ErrReleaseNotFound
} }
// All returns all releases whose status is not Status_DELETED. // List returns all releases whose status is not Status_DELETED.
func (mem *Memory) All(key string, opts ...interface{}) ([]*rspb.Release, error) { func (mem *Memory) List(filter func(*rspb.Release) bool) ([]*rspb.Release, error) {
defer unlock(mem.rlock()) defer unlock(mem.rlock())
var releases []*rspb.Release var releases []*rspb.Release
for _, rls := range mem.cache { for k := range mem.cache {
if rls.Info.Status.Code != rspb.Status_DELETED { if filter(mem.cache[k]) {
releases = append(releases, rls) releases = append(releases, mem.cache[k])
} }
} }
return releases, nil return releases, nil
@ -57,7 +57,6 @@ func (mem *Memory) All(key string, opts ...interface{}) ([]*rspb.Release, error)
// Create creates a new release or error. // Create creates a new release or error.
func (mem *Memory) Create(rls *rspb.Release) error { func (mem *Memory) Create(rls *rspb.Release) error {
defer unlock(mem.wlock()) defer unlock(mem.wlock())
mem.cache[rls.Name] = rls mem.cache[rls.Name] = rls
return nil return nil
} }

@ -36,10 +36,6 @@ func TestMemoryGet(t *testing.T) {
} }
} }
func TestMemoryAll(t *testing.T) {
t.Skip("MemoryAll")
}
func TestMemoryCreate(t *testing.T) { func TestMemoryCreate(t *testing.T) {
key := "test-1" key := "test-1"
rls := &rspb.Release{Name: key} rls := &rspb.Release{Name: key}

Loading…
Cancel
Save