Commit a05b48f3 authored by fibonacci1729's avatar fibonacci1729

update driver Queryor interface to reflect list filtering mechanism

parent bfd6712c
......@@ -27,24 +27,34 @@ var (
ErrNotImplemented = errors.New("not implemented")
)
// Creator stores a release.
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 {
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 {
Delete(string) (*rspb.Release, error)
Delete(key string) (*rspb.Release, error)
}
// Queryor defines the behavior on accessing a release from storage.
type Queryor interface {
Get(string) (*rspb.Release, error)
All(string, ...interface{}) ([]*rspb.Release, error)
// Get returns the release named by key or returns ErrReleaseNotFound
// if the release does not exist.
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 {
Creator
Updator
......
......@@ -41,14 +41,14 @@ func (mem *Memory) Get(key string) (*rspb.Release, error) {
return nil, ErrReleaseNotFound
}
// All returns all releases whose status is not Status_DELETED.
func (mem *Memory) All(key string, opts ...interface{}) ([]*rspb.Release, error) {
// List returns all releases whose status is not Status_DELETED.
func (mem *Memory) List(filter func(*rspb.Release) bool) ([]*rspb.Release, error) {
defer unlock(mem.rlock())
var releases []*rspb.Release
for _, rls := range mem.cache {
if rls.Info.Status.Code != rspb.Status_DELETED {
releases = append(releases, rls)
for k := range mem.cache {
if filter(mem.cache[k]) {
releases = append(releases, mem.cache[k])
}
}
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.
func (mem *Memory) Create(rls *rspb.Release) error {
defer unlock(mem.wlock())
mem.cache[rls.Name] = rls
return nil
}
......
......@@ -36,10 +36,6 @@ func TestMemoryGet(t *testing.T) {
}
}
func TestMemoryAll(t *testing.T) {
t.Skip("MemoryAll")
}
func TestMemoryCreate(t *testing.T) {
key := "test-1"
rls := &rspb.Release{Name: key}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment