pull/1007/head
fibonacci1729 9 years ago
parent a05b48f320
commit 967e438bfd

@ -44,7 +44,7 @@ func (mem *Memory) Get(key string) (*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 k := range mem.cache {
if filter(mem.cache[k]) {

@ -11,7 +11,7 @@ func (fn FilterFunc) Check(rls *rspb.Release) bool {
if rls == nil {
return false
}
return fn(rls)
return fn(rls)
}
// Any returns a FilterFunc that filters a list of releases
@ -48,4 +48,4 @@ func StatusFilter(status rspb.Status_Code) FilterFunc {
}
return rls.GetInfo().GetStatus().Code == status
})
}
}

@ -91,6 +91,8 @@ func (s *Storage) ListFilterAny(filters ...FilterFunc) ([]*rspb.Release, error)
}
func Init(d driver.Driver) *Storage {
if d == nil { d = driver.NewMemory() }
if d == nil {
d = driver.NewMemory()
}
return &Storage{Driver: d}
}
}

@ -47,7 +47,7 @@ func TestStorageUpdate(t *testing.T) {
assertErrNil(t.Fatal, storage.Create(rls), "StoreRelease")
// modify the release
rls.Version = 2
rls.Version = 2
rls.Manifest = "new-manifest"
assertErrNil(t.Fatal, storage.Update(rls), "UpdateRelease")
@ -81,12 +81,12 @@ func TestStorageList(t *testing.T) {
setup := func() {
// release records
rls0 := ReleaseTestData{Name: "happy-catdog", Status: rspb.Status_SUPERSEDED}.ToRelease()
rls1 := ReleaseTestData{Name: "livid-human", Status: rspb.Status_SUPERSEDED}.ToRelease()
rls2 := ReleaseTestData{Name: "relaxed-cat", Status: rspb.Status_SUPERSEDED}.ToRelease()
rls1 := ReleaseTestData{Name: "livid-human", Status: rspb.Status_SUPERSEDED}.ToRelease()
rls2 := ReleaseTestData{Name: "relaxed-cat", Status: rspb.Status_SUPERSEDED}.ToRelease()
rls3 := ReleaseTestData{Name: "hungry-hippo", Status: rspb.Status_DEPLOYED}.ToRelease()
rls4 := ReleaseTestData{Name: "angry-beaver", Status: rspb.Status_DEPLOYED}.ToRelease()
rls5 := ReleaseTestData{Name: "opulent-frog", Status: rspb.Status_DELETED}.ToRelease()
rls6 := ReleaseTestData{Name: "happy-liger", Status: rspb.Status_DELETED}.ToRelease()
rls6 := ReleaseTestData{Name: "happy-liger", Status: rspb.Status_DELETED}.ToRelease()
// create the release records in the storage
assertErrNil(t.Fatal, storage.Create(rls0), "Storing release 'rls0'")
@ -98,12 +98,12 @@ func TestStorageList(t *testing.T) {
assertErrNil(t.Fatal, storage.Create(rls6), "Storing release 'rls6'")
}
var listTests = []struct{
var listTests = []struct {
Description string
NumExpected int
ListFunc func() ([]*rspb.Release,error)
ListFunc func() ([]*rspb.Release, error)
}{
{"ListDeleted", 2, storage.ListDeleted},
{"ListDeleted", 2, storage.ListDeleted},
{"ListDeployed", 2, storage.ListDeployed},
{"ListReleases", 7, storage.ListReleases},
}
@ -124,20 +124,20 @@ func TestStorageList(t *testing.T) {
}
type ReleaseTestData struct {
Name string
Name string
Version int32
Manifest string
Namespace string
Status rspb.Status_Code
Status rspb.Status_Code
}
func (test ReleaseTestData) ToRelease() *rspb.Release {
return &rspb.Release{
Name: test.Name,
Name: test.Name,
Version: test.Version,
Manifest: test.Manifest,
Namespace: test.Namespace,
Info: &rspb.Info{Status: &rspb.Status{Code: test.Status}},
Info: &rspb.Info{Status: &rspb.Status{Code: test.Status}},
}
}
@ -147,7 +147,6 @@ func assertErrNil(eh func(args ...interface{}), err error, message string) {
}
}
/*
func releaseData() *rspb.Release {
var manifest = `apiVersion: v1
@ -174,4 +173,4 @@ func releaseData() *rspb.Release {
Namespace: "kube-system",
}
}
*/
*/

Loading…
Cancel
Save